【发布时间】:2016-01-19 04:05:37
【问题描述】:
所以我有一个Listbox,其项目包含Expander。我想要做的是将IsExpanded 属性绑定到父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>
【问题讨论】:
-
我们需要一些代码
-
@nkoniishvt 我添加了一些代码。它不起作用,因为我无法绑定到 ListBoxItem 的 IsSelected 部分。我正在寻找类似的东西。如果选择了该项目,则应选择扩展器。由于它设置为
SelectionMode="Single",因此任何时候都应该选择/展开一项。
标签: wpf binding listbox expander