2016-04-12 30 views
1

Wpf dosyasında nesne özelliği ile gruplama olanağı var mı? xmaple için :WPF, C# - nesne grubuna göre gruplandırma

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

My datagrid en ItemsSource ben çalışmak görünmüyor Mitarbeiter.FullName

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

Bu göre gruplandırmak istediğiniz bir List<Ausgabe> içerir. Bu tür gruplaşmayı başarmanın bir yolu var mı?

cevap

1

Sen

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

ardından grup gibi ana sınıfa FullName taşıyabilirsiniz

PropertyGroupDescription pgd = new PropertyGroupDescription("FullName");