C# 项目内部折叠扩展器控制WPF
我在ItemsControl中显示一个扩展项列表,并将一个项列表绑定到它。 我遵循的xaml结构是C# 项目内部折叠扩展器控制WPF,c#,wpf,xaml,C#,Wpf,Xaml,我在ItemsControl中显示一个扩展项列表,并将一个项列表绑定到它。 我遵循的xaml结构是 <ItemsControl ItemsSource="{Binding}" > <ItemsControl.ItemTemplate> <DataTemplate> <Expander ExpandDirection="Down" Style="{StaticResource
<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中的某些其他项时,是否可以使expander内容自动变为colpased您可以将ItemsControl替换为ListBox,并将expander的IsExpanded属性绑定到ListBoxItem的IsSelected属性。看
您还可以将IsExpanded绑定到某个viewmodel属性并从中获取它。同样的结果也可以通过wpf行为实现
回答您的问题:不,没有自动折叠其他扩展器的方法。IsExpanded={Binding Mode=TwoWay,Path=IsSelected,RelativeSource={RelativeSource AncestorType=ListBoxItem,Mode=FindAncestor}}这种方法对我有效,谢谢您的帮助: