我有一个我试图在xaml中显示的简单类的列表。这个类与此类似:
public class MyClass
{
public MyClass()
{
Things= new List<string>();
}
public string FirstName{get; set;}
public string MiddleName{get; set;}
public string LastName{get; set;}
public List<string> Things{get; set;}
}
然后我有一个上面的类列表
List<MyClass> myCollection;
显示myCollection的最佳方法是什么?我尝试绑定到DataGrid,但是我在列表中显示列表时遇到问题
答案 0 :(得分:1)
我不确定你是否要排除事情,所以我会做两件事。
没有东西:
<DataGrid ItemsSource="{Binding myCollection}" AutoGenerateColumns="False">
<DataGrid.Columns>
<DataGridTextColumn Header="First Name" Binding="{Binding FirstName}" />
<DataGridTextColumn Header="Middle Name" Binding="{Binding MiddleName}" />
<DataGridTextColumn Header="Last Name" Binding="{Binding LastName}" />
</DataGrid.Columns>
</DataGrid>
与事物:
<DataGrid ItemsSource="{Binding myCollection}" AutoGenerateColumns="False">
<DataGrid.Columns>
<DataGridTextColumn Header="First Name" Binding="{Binding FirstName}" />
<DataGridTextColumn Header="Middle Name" Binding="{Binding MiddleName}" />
<DataGridTextColumn Header="Last Name" Binding="{Binding LastName}" />
<DataGridTemplateColumn>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ListBox ItemsSource="{Binding Things}" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>