当我通过触发器设置ItemsPanel时,主题更改时,列表框中的可见项看不到更改。如果我将列表框向下滚动几页然后向上滚动,则初始可见项目会更新。
如果我直接设置ItemsPanel(请参阅下面的xaml注释,并删除样式),列表框中的可见项确实反映了主题的更改 立即
有人可以建议如何更改ItemsPanelTemplate并让它响应主题的变化吗?
<ListBox
SelectionMode="Extended"
VirtualizingStackPanel.IsVirtualizing="True"
ItemTemplateSelector="{StaticResource LayerItemTemplateSelector}"
IsSynchronizedWithCurrentItem="True"
ItemsSource="{Binding MyItemsView}"
SelectedItem="{Binding Path=SelectedMyItem, Mode=TwoWay}">
<ListBox.Resources>
<ItemsPanelTemplate x:Key="StackItemsPanelTemplate">
<VirtualizingStackPanel
Orientation="Vertical"
VirtualizationMode="Recycling"
IsContainerVirtualizable="True"
IsVirtualizing="True"
/>
</ItemsPanelTemplate>
<ItemsPanelTemplate x:Key="WrapItemsPanelTemplate">
<telerik:VirtualizingWrapPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
</ListBox.Resources>
<!-- THIS WORKS
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel
Orientation="Vertical"
VirtualizationMode="Recycling"
IsContainerVirtualizable="True"
IsVirtualizing="True"
/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>-->
<ListBox.Style>
<Style TargetType="ListBox" BasedOn="{StaticResource ListBoxStyle}">
<Setter Property="ItemsPanel" Value="{DynamicResource StackItemsPanelTemplate}"/>
<Style.Triggers>
<DataTrigger Binding="{Binding Path=IsLoadingUnitShowLayerActive, Mode=OneWay}" Value="True">
<Setter Property="ItemsPanel" Value="{DynamicResource StackItemsPanelTemplate}"/>
</DataTrigger>
<DataTrigger Binding="{Binding Path=IsLoadingUnitHideLayerActive, Mode=OneWay}" Value="True">
<Setter Property="ItemsPanel" Value="{DynamicResource WrapItemsPanelTemplate}"/>
</DataTrigger>
</Style.Triggers>
</Style>
</ListBox.Style>
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem" BasedOn="{StaticResource ListBoxItemStyle}">
<Setter Property="HorizontalContentAlignment" Value="Stretch"></Setter>
</Style>
</ListBox.ItemContainerStyle>
</ListBox>