如何将SelectionChanged
事件添加到此XAML代码中?
<DataGridComboBoxColumn x:Name="stcombo"
CellStyle="{DynamicResource ComboBoxStyle}"
Header="Статус"
SelectedItemBinding="{Binding name_ru}" >
???
</DataGridComboBoxColumn>
答案 0 :(得分:4)
我认为你不能添加datagrid组合框的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
}
}
答案 1 :(得分:0)
试试这个:
<DataGridTemplateColumn>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ComboBox DisplayMemberPath=" "
SelectedValuePath=" "
SelectedValue="{Binding }"
SelectionChanged="" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
答案 2 :(得分:0)
这一行
<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
}