[英]C# XAML grid Expander
一种新的WPF项目,而xaml确实令人困惑。
我有一个显示分组的ListCollectionView的数据网格,我想要一个单击按钮,以便分组的视图可以折叠。 这似乎是一个容易实现的功能,但在过去的一天中到处搜索,没有一个例子可以解决(也许太简单了吗?)
这是我的XAML的代码
<Window.Resources>
<Style x:Key="GroupHeaderStyle" TargetType = "{x:Type GroupItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type GroupItem}">
<Expander x:Name="myExpander" IsExpanded="True"
Background="LightBlue"
Foreground="Black">
<ItemsPresenter />
</Expander>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
并在mainwindow.xaml.cs中
ListCollectionView collection = new ListCollectionView(dt.DefaultView);
collection.GroupDescriptions.Add(new PropertyGroupDescription("Grouping"));
dataGrid1.ItemsSource = collection;
请帮忙。 非常感谢大家。
您要覆盖/设置GroupStyle
。 但是您的示例代码看起来还不错-所以也许我只是不明白您的问题是什么。
<ItemsControl>
<ItemsControl.GroupStyle>
<GroupStyle>
<GroupStyle.ContainerStyle>
<Style TargetType="{x:Type GroupItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type GroupItem}">
<Expander IsExpanded="true" Header="Yolo">
<ItemsPresenter />
</Expander>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</GroupStyle.ContainerStyle>
</GroupStyle>
</ItemsControl.GroupStyle>
</ItemsControl>
请添加附加信息,如果它不是您要执行的操作!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.