【问题标题】:Expander IsExpanded binding to listbox selectedExpander IsExpanded 绑定到选定的列表框
【发布时间】:2016-01-19 04:05:37
【问题描述】:

所以我有一个Listbox,其项目包含Expander。我想要做的是将IsExpanded 属性绑定到父ListBoxItemIsSelected 属性。整个目的是,如果他们选择了不同的列表框项目,它将折叠当前选定的项目并展开新的选定项目。

更新(代码):

<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


【解决方案1】:

我正在寻找的属性/绑定是IsExpanded="{Binding Mode=TwoWay, Path=IsSelected, RelativeSource={RelativeSource AncestorType=ListBoxItem, Mode=FindAncestor}}"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-04-04
    • 1970-01-01
    • 1970-01-01
    • 2014-10-31
    • 1970-01-01
    • 2012-02-24
    • 2013-03-26
    相关资源
    最近更新 更多