【问题标题】:WPF, C# - group by object propertyWPF,C# - 按对象属性分组
【发布时间】:2016-04-12 05:36:35
【问题描述】:

是否可以在 wpf 中按对象属性进行分组? 例如:

public class Ausgabe
{
    public int Id { get; set; }
    public Mitarbeiter Mitarbeiter { get; set; }
    public Ausgabestatus Status { get; set; }
    public Bestellung Bestellung { get; set; }
}

public class Mitarbeiter
{
    public int Id { get; set; }
    public String Vorname { get; set; }
    public String Nachname { get; set; }
    public String FullName
    {
        get { return Nachname + " " + Vorname; }
    }
}

我的数据网格的ItemsSource 包含一个List<Ausgabe>,我想按Mitarbeiter.FullName 分组

CollectionView cv = (CollectionView)CollectionViewSource.GetDefaultView(dgErfasst.ItemsSource);
cv.GroupDescriptions.Clear();
PropertyGroupDescription pgd = new PropertyGroupDescription("Mitarbeiter.Vorname");
cv.GroupDescriptions.Add(pgd);

这似乎不起作用。有没有办法实现这种分组?

【问题讨论】:

    标签: c# wpf properties grouping


    【解决方案1】:

    您可以将 FullName 移动到父类,例如

    public class Ausgabe
    {
        public int Id { get; set; }
        public Mitarbeiter Mitarbeiter { get; set; }
        public Ausgabestatus Status { get; set; }
        public Bestellung Bestellung { get; set; }
        public String FullName
        {
            get { return Mitarbeiter.Nachname + " " + Mitarbeiter.Vorname; }
        }
    }
    

    然后分组

    PropertyGroupDescription pgd = new PropertyGroupDescription("FullName");
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-22
      • 2019-04-15
      • 1970-01-01
      • 1970-01-01
      • 2017-07-17
      • 2021-12-21
      相关资源
      最近更新 更多