我刚刚开始学习WPF,我试图在ItemsControl中使用GridViewRowPresenter来实质上复制HTML中的简单表的功能.ListView不合适,因为它是交互式的(我不想要).我绑定到未知数量的对象的通用列表.
我有一个自定义对象的列表,它有两个字符串属性:FirstName和LastName.以下代码有效:
<ItemsControl Name="myItemsControl">
<ItemsControl.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=FirstName}"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
Run Code Online (Sandbox Code Playgroud)
虽然这没有任何结果:
<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>
Run Code Online (Sandbox Code Playgroud)
我不知道从哪里开始,我非常感谢任何帮助!谢谢!