c# - XAML 中的 ListView 和 GroupStyle
问题描述
我有一个 WPF 应用程序并创建一个静态网格表。第一列中有一个下拉单元格,单击时会显示行和列。有没有一种方法可以用 XAML 或任何其他方式进行编码?我会上传一个样本。
何时显示下拉详细信息。
*** 这是我的 C# 代码 ***
public partial class ProcessData : UserControl
{
public ProcessData()
{
InitializeComponent();
List<User> items = new List<User>();
items.Add(new User() { Name = "John Doe", Age = 42, Type = Group.One });
items.Add(new User() { Name = "Jane Doe", Age = 39, Type = Group.Two });
items.Add(new User() { Name = "Sammy Doe", Age = 13, Type = Group.One });
items.Add(new User() { Name = "testing", Age = 13, Type = Group.Three });
lvUsers.ItemsSource = items;
CollectionView view = (CollectionView)CollectionViewSource.GetDefaultView(lvUsers.ItemsSource);
PropertyGroupDescription groupDescription = new PropertyGroupDescription("Type");
view.GroupDescriptions.Add(groupDescription);
}
public enum Group { One, Two, Three };
public class User
{
public string Name { get; set; }
public int Age { get; set; }
public string Mail { get; set; }
public Group Type { get; set; }
}
}
*** 这是我现在的 XAML 代码 ***
<ListView Name="lvUsers">
<ListView.View>
<GridView>
<GridViewColumn Header="Name" Width="120" DisplayMemberBinding="{Binding Name}" />
<GridViewColumn Header="Age" Width="50" DisplayMemberBinding="{Binding Age}" />
</GridView>
</ListView.View>
<ListView.GroupStyle>
<GroupStyle>
<GroupStyle.ContainerStyle>
<Style TargetType="{x:Type GroupItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<Expander IsExpanded="True">
<Expander.Header>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Name}" FontWeight="Bold" Foreground="Gray" FontSize="11" VerticalAlignment="Bottom" />
<TextBlock Text="{Binding ItemCount}" FontSize="11" Foreground="Green" FontWeight="Bold" FontStyle="Italic" Margin="10,0,0,0" VerticalAlignment="Bottom" />
<TextBlock Text=" item(s)" FontSize="11" Foreground="Silver" FontStyle="Italic" VerticalAlignment="Bottom" />
</StackPanel>
</Expander.Header>
<ItemsPresenter />
</Expander>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</GroupStyle.ContainerStyle>
</GroupStyle>
</ListView.GroupStyle>
</ListView>
在我的代码中,所有项目都分组。我想要的是如果某些数据不在类型中,它将在组之外并且不属于任何组。
解决方案
推荐阅读
- wso2is - 如何使用辅助用户存储配置 WSO2IS,以便用户在登录时不必输入域名?
- typescript - 在抽象类构造函数中调用的抽象方法看不到派生类属性
- c# - 温莎城堡:注册似乎没问题时控制器解析失败
- debian - Debian Stretch - 存储库“http://192.168.196.1/sw/repo/deb9 stretch Release”没有发布文件
- python - SIP邀请消息python
- python -
0x00等是什么意思? - android - 手机启动时服务不启动
- css - 如何使用 CSS-in-JS 方法设置 body 标签的样式?
- laravel - 通过 Laravel 在 Mysql 中插入数据的最佳方法
- java - (De)用 Gson 序列化抽象类