0

我使用 XAML 在 Datagrid 中实现了 DataGridComboBoxColumn。我可以以编程方式访问 comboboxColumn1,但是如何在值更改时获取所选项目?

 <DataGrid x:Name="dgData" AutoGenerateColumns="False" Margin="131,93,13,101" Grid.Column="1" SelectionChanged="dgData_SelectionChanged">
       <DataGrid.Columns>

            <DataGridComboBoxColumn Header="Subject" x:Name="comboboxColumn1"/>

       </DataGrid.Columns>
 </DataGrid>
4

1 回答 1

0

试试这个方法

<DataGridComboBoxColumn Header="Life Area" SelectedItemBinding="{Binding YourSelectedItem}">
    <DataGridComboBoxColumn.ElementStyle>
        <Style TargetType="ComboBox">
            <Setter Property="ItemsSource" Value="{Binding YourItemSource}"/>
            <Setter Property="IsReadOnly" Value="True"/>
        </Style>
    </DataGridComboBoxColumn.ElementStyle>
    <DataGridComboBoxColumn.EditingElementStyle>
        <Style TargetType="ComboBox">
            <Setter Property="ItemsSource" Value="{Binding YourItemSource}"/>
        </Style>
    </DataGridComboBoxColumn.EditingElementStyle>
</DataGridComboBoxColumn>
于 2012-11-01T04:46:56.070 回答