我刚刚开始学习 WPF,我正在尝试在 ItemsControl 中使用 GridViewRowPresenter 来基本上复制 HTML 中简单表格的功能。ListView 不合适,因为它是交互式的(我不想要)。我绑定到未知数量的对象的通用列表。
我有一个自定义对象的列表,该对象具有两个字符串属性:名字和姓氏。以下代码有效:
<ItemsControl Name="myItemsControl">
<ItemsControl.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=FirstName}"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
虽然这没有任何效果:
<ItemsControl Name="myItemsControl">
<ItemsControl.ItemTemplate>
<DataTemplate>
<GridViewRowPresenter>
<GridViewRowPresenter.Columns>
<GridViewColumnCollection>
<GridViewColumn DisplayMemberBinding="{Binding Path=FirstName}"></GridViewColumn>
<GridViewColumn DisplayMemberBinding="{Binding Path=LastName}"></GridViewColumn>
</GridViewColumnCollection>
</GridViewRowPresenter.Columns>
</GridViewRowPresenter>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
我不知道从这里去哪里,我将不胜感激任何帮助!谢谢!