Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net 如何绑定DataGrid标头_.net_Wpf_Datagrid - Fatal编程技术网

.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}}" />