I wrote the Style
:
<Style x:Key="ProductItemContainerStyle"
TargetType="{x:Type ListBoxItem}"
BasedOn="{StaticResource ProductItemContainerBaseStyle}">
<Setter Property="IsSelected"
Value="{Binding Path=IsExpanded, RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type Expander}}, Mode=OneWayToSource}" />
</Style>
It is relevant only when applying grouping for the ListBox
that holds this ListBoxItem
. However, most of the time it is not in grouping and this causes for dozens, hundreds and thousands of binding exception (depends on how many items are in the list). Binding Exception are known reason for performance problems. This binding should expand the Expander
when code behind selects a ListBoxItem
and IsSelected
is changed to true. As you can see the binding is Mode=OneWayToSource
.
Is there a way to prevent these binding exceptions?
VisualTreeHelper
to get the expanders in the collection? You can attach a handler to clicked event onListViewItem
orListBoxItem
find nearest expander and expand it. No need to go through thousands of records. – XAMlMAX