我坚持在 C# WPF 中使用 Linq 在组合框(父)和列表视图(子)控件之间创建主细节关系。
protected class Student
{
public string FirstName { get; set; }
public string LastName { get; set; }
public string Gender{ get; set; }
}
protected static List<Student> students = new List<Student>
{
new Student {FirstName = "Terry", LastName = "Adams", Gender= "M"},
new Student {FirstName = "Terry2", LastName = "Adams", Gender= "M"},
new Student {FirstName = "Karry", LastName = "Adams2", Gender= "F"},
new Student {FirstName = "Karry2", LastName = "Adams4", Gender= "F"},
}
组合框将由 Gender groubby() 生成,列表视图将根据组合框选择进行更新。像这样的东西,但不起作用,谢谢
var result = (from cat in students
select new {
FirstName = cat.FirstName ,
LastName = cat.LastName}).Distinct().ToList();