1

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; } }

even tried making Fields a Property of MyRow

4

1 回答 1

2

如果您在 DataGrid 上使用从 Window 继承的 DataContext,它应该可以工作。

<ComboBox Width="60"
          ItemsSource="{Binding Path=DataContext.Fields, 
          RelativeSource={RelativeSource AncestorType=DataGrid}}" />
于 2012-09-23T20:46:59.490 回答