WPF,C# - 按对象属性分组

时间:2016-04-12 05:36:35

标签: c# wpf properties grouping

是否可以通过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);

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

1 个答案:

答案 0 :(得分: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");
相关问题