不能获得组合框
在 DataGridTextColumn.Header
绑定。
第一个独立组合框
结合的罚款。
场仅仅是公开名单<字符串>
Cannot get the ComboBox
in the DataGridTextColumn.Header
to bind.
The first stand alone ComboBox
binds fine.
Fields is just Public List<String>
.
<StackPanel Orientation="Vertical">
<ComboBox ItemsSource="{Binding Path=Fields}"/>
<DataGrid ItemsSource="{Binding Path=MyRows}" AutoGenerateColumns="False" >
<DataGrid.Columns>
<DataGridTextColumn Width="80" Binding="{Binding Col1}">
<DataGridTextColumn.Header>
<StackPanel>
<TextBlock Text="Header1" />
<ComboBox Width="60" ItemsSource="{Binding Path=Fields}" />
</StackPanel>
</DataGridTextColumn.Header>
</DataGridTextColumn>
</DataGrid.Columns>
</DataGrid>
</StackPanel>
private List<string> fields = new List<string> { "aa", "bb", "cc" };
public List<string> Fields { get { return fields; } }
甚至试图使场MyRow的房产
even tried making Fields a Property of MyRow
它应该工作,如果你使用的DataContext上的DataGrid中,这已继承的窗口。
It should work if you use the DataContext on the DataGrid, which has been inherited from the Window.
<ComboBox Width="60"
ItemsSource="{Binding Path=DataContext.Fields,
RelativeSource={RelativeSource AncestorType=DataGrid}}" />