-1

如何SelectionChanged向此 XAML 代码添加事件?

<DataGridComboBoxColumn x:Name="stcombo" 
                        CellStyle="{DynamicResource ComboBoxStyle}" 
                        Header="Статус" 
                        SelectedItemBinding="{Binding name_ru}" >
    ???                        
</DataGridComboBoxColumn>
4

3 回答 3

5

我认为您不能添加数据网格组合框的 SelectedChanged 事件。替代解决方案是 -

您可以将属性绑定到组合框的 SelectedItem 并使用此属性的 setter 来处理 selectedchanged 事件逻辑。

每当用户从组合框中选择任何值时,setter 都会被执行。

XAML -

<DataGridComboBoxColumn CellStyle="{DynamicResource ComboBoxStyle}" x:Name="stcombo"  Header="Статус" SelectedItemBinding ="{Binding SelectedCustomer,UpdateSourceTrigger=PropertyChanged}">

/Viwe 模型背后的代码

private Customer _selectedCustomer;
public Customer SelectedCustomer
{
    get
    {
       return _selectedCustomer;
    }
    set
    {
       _selectedCustomer = value;
       //Do your custom logic
    }
}
于 2012-07-11T09:21:28.210 回答
1

有了这条线

<DataGridComboBoxColumn x:Name="stcombo" 
                        CellStyle="{DynamicResource ComboBoxStyle}" 
                        Header="Статус" 
                        SelectedItemBinding="{Binding name_ru}">

    <DataGridComboBoxColumn.EditingElementStyle>
      <Style TargetType="{x:Type ComboBox}">
           <EventSetter Event="SelectionChanged" Handler="yourCBSelectionChanged" />
      </Style>
    </DataGridComboBoxColumn.EditingElementStyle>   


</DataGridComboBoxColumn>

在代码中:

private void yourCBSelectionChanged(object sender, SelectionChangedEventArgs e)
{
     //Your code
}
于 2016-12-29T15:36:26.733 回答
0

试试这个:

 <DataGridTemplateColumn>
    <DataGridTemplateColumn.CellTemplate>
        <DataTemplate>
            <ComboBox DisplayMemberPath=" "
                      SelectedValuePath=" "
                      SelectedValue="{Binding  }"
                      SelectionChanged="" />
        </DataTemplate>
    </DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
于 2012-07-11T09:25:39.783 回答