1

At work, a question arose in regards to the performance impact of having a MultiTrigger in the ListBoxItem ControlTemplate.

The situation goes a bit like this: we have a custom styling for the ListBox control that defines an animation and color for the selected ListBoxItem. The issue arose because when the ListBox is disabled, we do not want the selected ListBoxItem to show the selected "background" highlight. This led us to add a set of triggers in the ControlTemplate of ListBoxItems to disable this custom highlighting when the ListBoxItem is disabled and selected. This is where the worry for a negative performance impact originated:

If every ListBoxItem needs to check for triggers and activate for triggers, would this generate a noticeable performance impact if there were a lot of items. This could be an issue because this code runs on older computers.

4

1 回答 1

3

第一个 WPF 不支持“旧计算机”。

第二,如果您ListBox是虚拟化的(这是默认行为,除非您通过不使用 aVirtualizingStackPanel或放入ListBox无限容器(例如 another StackPanel)来破坏它,ListBoxItems直到它们被用户滚动到视图中才会创建,在这种情况下无论 ListBox 中有 1000000000 个项目,实际上只创建适合屏幕的项目并消耗内存 + CPU。

于 2013-07-08T15:56:37.870 回答