折叠ItemsControl WPF中的扩展器
本文关键字:扩展器 WPF ItemsControl 折叠 | 更新日期: 2023-09-27 18:23:44
我在ItemsControl中显示了一个扩展项列表,并将一个项列表绑定到它。我下面的xaml结构是
<ItemsControl ItemsSource="{Binding}" >
<ItemsControl.ItemTemplate>
<DataTemplate>
<Expander ExpandDirection="Down" Style="{StaticResource ResourceKey=ExpanderItemStyle}" >
<Expander.Header>
<BulletDecorator>
//Expander header by default its collapsed
<Label Style="{StaticResource ResourceKey=ChapterHeadStyle}" Content="{Binding name}"></Label>
</BulletDecorator>
</Expander.Header>
<StackPanel> // Expander body want to collapse it when some some other items of ItemsControl is expanded
</StackPanel>
</Expander>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
当ItemsControl中的一些其他项目被选中时,我可以自动清空扩展器内容吗?
您可以将ItemsControl
替换为ListBox
,并将Expander
的IsExpanded
属性绑定到ListBoxItem
的IsSelected
属性。(参见http://social.msdn.microsoft.com/Forums/vstudio/en-US/a2988ae8-e7b8-4a62-a34f-b851aaf13886/windows-presentation-foundation-faq?forum=wpf#expander_list)
您还可以将IsExpanded
绑定到某个视图模型属性并从中获取它。通过wpf行为也可以获得相同的结果。
回答你的问题:不,没有"自动"的方法来折叠其他扩展器。