下面是生成按钮列表的标记。
<ItemsControl x:Name="Items" Grid.Row="5" Grid.ColumnSpan="2">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Orientation="Vertical"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<ToggleButton Content="{Binding Name}"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
使用过滤条件对按钮应用了过滤
collectionView = (CollectionView)CollectionViewSource.GetDefaultView(Items.ItemsSource);
collectionView .Filter = FilterList;
问题是我想在切换过滤器状态时保留选中的按钮状态。我已尝试订阅 StatusChanged 事件
Items.ItemContainerGenerator.StatusChanged += new System.EventHandler(ItemContainerGenerator_StatusChanged);
但是在状态为 ContainersGenerated 时似乎没有生成控件
void ItemContainerGenerator_StatusChanged(object sender, System.EventArgs e)
{
if (Items.ItemContainerGenerator.Status == GeneratorStatus.ContainersGenerated)
{
RefreshButtons();
}
}