【发布时间】:2013-09-25 13:18:54
【问题描述】:
当同时指定ContainerStyle 时,似乎优先使用HeaderTemplate,如下所示;
<controls:DataGrid.GroupStyle>
<GroupStyle>
<GroupStyle.HeaderTemplate>
<DataTemplate>
<StackPanel>
<TextBlock Text="{Binding Path=Name}" Background="Yellow" />
</StackPanel>
</DataTemplate>
</GroupStyle.HeaderTemplate>
<GroupStyle.ContainerStyle>
<Style TargetType="{x:Type GroupItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type GroupItem}">
<Expander IsExpanded="true" Background="Violet">
<Expander.Header>
<DockPanel TextBlock.FontWeight="Bold">
<TextBlock Text="{Binding Path=Name}" />
<TextBlock Text="{Binding Path=ItemCount}"/>
</DockPanel>
</Expander.Header>
<ItemsPresenter />
</Expander>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</GroupStyle.ContainerStyle>
</GroupStyle>
</controls:DataGrid.GroupStyle>
唯一的区别是HeaderTemplate 无法访问ItemsPresenter,还是与分层数据结构有关?
谢谢!
编辑链接到http://wpftutorial.net/DataGrid.html#grouping。我实际上并没有直接从那里拿这个例子,但这是一个很棒的网站,所以他们无论如何都可以有一个链接。
【问题讨论】:
标签: wpf xaml datagrid .net-3.5 groupstyle