DataGrid:如何以编程方式选择ComboBox项?

时间:2013-11-29 03:53:10

标签: c# wpf datagrid combobox

有问题的ComboBoxs位于DataGrid的列中,并已定义如下:

<DataGridTemplateColumn Header=" Right Column ">
    <DataGridTemplateColumn.CellTemplate>
        <DataTemplate>
            <ComboBox ItemsSource="{Binding Caliber, RelativeSource={RelativeSource AncestorType=Window}}" DisplayMemberPath="Thicknesss" SelectedItem="{Binding Thickness, UpdateSourceTrigger=PropertyChanged" SelectionChanged="ComboBox_SelectionChanged">
            </ComboBox>
        </DataTemplate>
    </DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>

TIA

2 个答案:

答案 0 :(得分:1)

您可能正在寻找可以在ComboBox的样式上设置的DataTriggers,具体取决于可以启用或禁用ComboBox的条件。

答案 1 :(得分:1)

有问题的ComboBoxs位于DataGrid的列中,并已定义如下:

<DataGridTemplateColumn Header=" Right Column ">
    <DataGridTemplateColumn.CellTemplate>
        <DataTemplate>
            <ComboBox ItemsSource="{Binding Caliber, RelativeSource={RelativeSource AncestorType=Window}, Mode=TwoWay}" DisplayMemberPath="Thickness" SelectedItem="{Binding Thickness, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" >
            </ComboBox>
        </DataTemplate>
    </DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>

链接

http://social.technet.microsoft.com/wiki/contents/articles/19493.wpf-best-combobox-tutorial-ever.aspx#DataGridTemplateColumn_CellTemplate