WPF DataGrid GroupStyle

我在WPF中有两个组的以下DataGrid
第一组是bool标志,表示一个人是否处于活动/非活动状态。
第二组(或子组)是每个人的ID。 每个人都可以拥有多个城市,因此可以对ID进行分组,因为每个人在DataGrid都会显示多个。 表人 - 城市

这是XAML:

                                                       

一切正常 ! 但是,我不喜欢每个子组的蓝色行。 我想要实现的是下图中的分组样式:

表人 - 城市

对于每个子组,我希望编辑按钮和ID每人只出现一次。 我该怎么办? 是否可以仅在XAML中使用,还是应该删除代码隐藏中的reduntant内容?

编辑
这里有一些测试数据:

 public class Person { public Person(bool active, int id, string name, string city) { Active = active; ID = id; Name = name; City = city; } public bool Active { get; set; } public int ID { get; set; } public string Name { get; set; } public string City { get; set; } } public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); DataContext = this; var data = new ObservableCollection { new Person(true, 233, "Max", "New York"), new Person(true, 233, "Max", "Los Angeles"), new Person(true, 314, "John", "Paris"), new Person(true, 578, "Mary", "Vienna"), new Person(true, 782, "Susan", "Rome"), new Person(true, 782, "Susan", "Prague"), new Person(true, 782, "Susan", "San Francisco"), new Person(false, 151, "Henry", "Chicago") }; DataSource = new ListCollectionView(data); } private ListCollectionView _dataSource; public ListCollectionView DataSource { get { return _dataSource; } set { _dataSource = value; _dataSource.GroupDescriptions.Add(new PropertyGroupDescription("Active")); _dataSource.GroupDescriptions.Add(new PropertyGroupDescription("ID")); } } 

强烈建议将数据结构更改为:

 public class Person { public bool Active { get; set; } public int ID { get; set; } public string Name { get; set; } public Collection Cities { get; set; } } 

否则,您可以更改此GroupStyle

          

      

更改模板以满足您的需求