我做了一个 ListView 跟 DataGridView
都完成了 Grouping 的动作
但是当我动态去改变 selectd 的时候(也静态给定初始值)
group 的 expander 没办法自动地展开
部分的 xaml design 如下:
<ListView.GroupStyle>
<GroupStyle>
<GroupStyle.ContainerStyle>
<Style TargetType="{x:Type GroupItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<Expander IsExpanded="{Binding
Mode=TwoWay, Path=IsSelected, RelativeSource={RelativeSource
AncestorType=ListViewItem, Mode=FindAncestor}}">
<Expander.Header>
<StackPanel
Orientation="Horizontal">
<TextBlock Text="{Binding
Name}" FontWeight="Bold" Foreground="Gray" FontSize="16"
VerticalAlignment="Bottom"/>
<TextBlock Text="{Binding
ItemCount}" FontSize="22" Foreground="Green" FontWeight="Bold"
FontStyle="Italic" Margin="10,0,0,0" VerticalAlignment="Bottom" />
<TextBlock Text="
item(s)" FontSize="22" Foreground="Silver" FontStyle="Italic"
VerticalAlignment="Bottom" />
</StackPanel>
</Expander.Header>
<ItemsPresenter/>
</Expander>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</GroupStyle.ContainerStyle>
</GroupStyle>
</ListView.GroupStyle>
主要的应该就是
<Expander IsExpanded="{Binding Mode=TwoWay, Path=IsSelected,
RelativeSource={RelativeSource AncestorType=ListViewItem,
Mode=FindAncestor}}">
将 AncestorType 设为 ListViewItem 是否正确??
还是上面还缺了什么宣告?