“ WPF command support in ComboBox ”,此页面展示了如何扩展组合框以支持命令,但它没有给出映射到组合框的 SelectedIndexChanged 事件的委托命令的圆顶。现在我面临的问题是如何处理组合框 SelectedIndexChanged 事件,就像它是一次性组合框情况一样:
<ComboBox SelectionChanged="ComboBox_SelectionChanged"></ComboBox>
private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
var combobox = sender as ComboBox;
if (combobox.SelectedIndex == 0)
{
//todo:
}
}
目前的情况如下:
<GridViewColumn.CellTemplate>
<DataTemplate>
<Ext:CommandSupportedComboBox SelectedIndex="{Binding StartMode}"
Command="{Binding ChangeStartModeCmd}">
<ComboBoxItem>Automatically</ComboBoxItem>
<ComboBoxItem>Manual</ComboBoxItem>
<ComboBoxItem>Forbidden</ComboBoxItem>
</Ext:CommandSupportedComboBox>
</DataTemplate>
</GridViewColumn.CellTemplate>
/// <summary>
/// change service start mode command
/// </summary>
public ICommand ChangeStartModeCmd { get; private set; }
和相应的委托方法:
/// <summary>
/// change service start mode
/// </summary>
public void ChangeStartMode()
{
//todo:
}
命令的绑定方法:
ChangeStartModeCmd = new DelegateCommand(ChangeStartMode);
我想定义这样的方法:
private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
var combobox = sender as ComboBox;
if (combobox.SelectedIndex == 0)
{
//todo:
}
}
但是如何将它绑定到委托命令 ChangeStartModeCmd?
ChangeStartModeCmd = new DelegateCommand(ChangeStartMode(
/*what should I pass for the method?*/));