我有下一个XAML代码:
<DataGrid x:Name="some_name" AutoGenerateColumns="False">
<DataGrid.ItemsSource>
<Binding XPath="Setting/Element[@Name='...']/Field"/>
</DataGrid.ItemsSource>
<DataGrid.Columns>
<DataGridTextColumn Header="Name" Width="*" Binding="{Binding XPath=@Name}"/>
<DataGridTextColumn Header="Type" Width="80" Binding="{Binding XPath=@Type}"/>
<DataGridTextColumn Header="Count" Binding="{Binding XPath=@Count}"/>
<DataGridTextColumn Header="ID" Width="80" Binding="{Binding XPath=@ID}"/>
</DataGrid.Columns>
</DataGrid>
如何在C#代码中使用Binding
设置XPath="Setting/Element[@Name='...']/Field"
?
答案 0 :(得分:0)
您可以像这样添加绑定。
var binding = new Binding
{
Source = _viewModel,
XPath = "Setting/Element[@Name='...']/Field"
};
some_name.SetBinding(ItemsControl.ItemsSourceProperty, binding);