我是WPF和XAML的新手。如果这看起来很简单,很抱歉,但我有一组类:
Public class Master()
{
public int Id {get;set;}
public List<Student> Students { get; set; }
}
Public class Student()
{
public int Id {get;set;}
public string Name { get; set; }
}我希望在数据网格中显示它们,因此我在页面上创建并配置了一个数据网格控件。
然后,我使用以下命令绑定了上面的类:
dataGrid.ItemsSource = result.Master.ToList();这为我提供了列表,但我尝试做的也是在每个主行上显示学生集合。目前,我得到的只是(集合)填充在datagrid的学生记录中。
发布于 2016-09-15 18:19:12
要从注释转到答案,请执行以下操作:
我假设您知道如何创建另一个datagrid,因为您已经有了一个具有正确绑定的datagrid。只需复制粘贴另一个,并将其移到一边。
对于另一个数据网格,我们称它为dataGrid2。
在第一个datagrid上:将这个添加到您的xaml:
SelectionChanged="DataGrid_SelectionChanged"
在后面的代码中:
private void DataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
var selected = dataGrid.SelectedItem as Master;
dataGrid2.ItemsSource = selected.Students.ToList();
}我还没有包括所有的东西,比如错误检查和空选择处理等,所以你需要实现它。
https://stackoverflow.com/questions/39507645
复制相似问题