.net 如何绑定DataGrid标头
无法获取要绑定的.net 如何绑定DataGrid标头,.net,wpf,datagrid,.net,Wpf,Datagrid,无法获取要绑定的DataGridTextColumn.Header中的ComboBox。 第一个独立的组合框绑定良好。 字段只是公共列表 私有列表字段=新列表{“aa”、“bb”、“cc”}; 公共列表字段{get{return Fields;}} 即使尝试将字段设置为MyRow的属性,如果使用DataGrid上的DataContext,它也应该可以工作,因为DataGrid是从窗口继承的 <ComboBox Width="60" ItemsSource="{Bi
DataGridTextColumn.Header
中的ComboBox
。第一个独立的组合框
绑定良好。
字段只是公共列表
私有列表字段=新列表{“aa”、“bb”、“cc”};
公共列表字段{get{return Fields;}}
即使尝试将字段设置为MyRow的属性,如果使用DataGrid上的DataContext,它也应该可以工作,因为DataGrid是从窗口继承的
<ComboBox Width="60"
ItemsSource="{Binding Path=DataContext.Fields,
RelativeSource={RelativeSource AncestorType=DataGrid}}" />
我错了,显然DataContext没有按预期继承。彼得·汉森的变通方法是最好的选择。我曾经很接近。ItemsSource中没有RealtiveSource。谢谢
private List<string> fields = new List<string> { "aa", "bb", "cc" };
public List<string> Fields { get { return fields; } }
<ComboBox Width="60"
ItemsSource="{Binding Path=DataContext.Fields,
RelativeSource={RelativeSource AncestorType=DataGrid}}" />