我想知道为什么我不能让我的 wpf 数据网格自动生成列。属性 AutogerenateColumns 设置为 true。也许这与我没有将 itemssource 绑定到类而是绑定到 XElement 的事实有关。如果可能有限制?我找不到有关此的任何信息。谢谢
这是xml:
<DataGrid
x:Name="grid"
Grid.Row="3"
Grid.Column="2"
HorizontalAlignment="Left"
ItemsSource="{Binding Path=Elements[person]}"
DataContext="{Binding Path=ResourceFileGroupMerged}"
AutoGenerateColumns="True">
</DataGrid>
在视图模型中:
public MainWindowViewModel()
{
ResourceFileGroupMerged = XElement.Load(@"c:\test.xml");
}