所以我有一个Listbox
,其项目包含一个Expander
。我想要做的是将 IsExpanded
属性绑定(bind)到父 ListBoxItem
的 IsSelected
属性。整个目的是,如果他们选择了不同的列表框项目,它将折叠当前所选项目并展开新所选项目。
更新(代码):
<ListBox SelectionMode="Single">
<ListBox.ItemContainerStyle>
<Style TargetType="{x:Type ListBoxItem}">
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
<Setter Property="Padding" Value="0" />
</Style>
</ListBox.ItemContainerStyle>
<ListBox.ItemTemplate>
<DataTemplate>
<Boreder BorderThickness="0,0,0,1"
BorderBrush="Black">
<Expander IsExpanded={Binding RelativeSource={RelativeSource AncestorType=ListBoxItem},
Path=IsSelected} />
</Border>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
最佳答案
我正在寻找的属性/绑定(bind)是IsExpanded="{Binding Mode=TwoWay, Path=IsSelected,relativeSource={RelativeSource AncestorType=ListBoxItem, Mode=FindAncestor}}"
关于wpf - Expander IsExpanded 绑定(bind)到选定的列表框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34861001/