2016-04-12 5 views
1

Есть ли возможность группировать свойство объекта в wpf? Для exmaple:WPF, C# - по свойству объекта

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; } 
    } 
} 

Моя DataGrid-х 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

Вы можете перемещать 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");