"WPF command support in ComboBox", this page shows how to extend a combobox to support a command, but it didn't give a dome of the delegate command that maps to the combobox's SelectedIndexChanged event. Now the problem I face is how can I handle the combobox SelectedIndexChanged event like where it is a one-off combobox situation :
<ComboBox SelectionChanged="ComboBox_SelectionChanged"></ComboBox>
private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
var combobox = sender as ComboBox;
if (combobox.SelectedIndex == 0)
{
//todo:
}
}
current situation is as below:
<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; }
and the corresponding delegate method :
/// <summary>
/// change service start mode
/// </summary>
public void ChangeStartMode()
{
//todo:
}
binding method to command:
ChangeStartModeCmd = new DelegateCommand(ChangeStartMode);
I want to define the method like this:
private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
var combobox = sender as ComboBox;
if (combobox.SelectedIndex == 0)
{
//todo:
}
}
but how do I bind it to the delegate command ChangeStartModeCmd?
ChangeStartModeCmd = new DelegateCommand(ChangeStartMode(
/*what should I pass for the method?*/));
You probably wont need a CommandSupportedCombobox as you can attach SelectedItem property of you ComboBox and inside the setter in your ViewModel Call the funciton you want...
<ComboBox SelectedItem="{Binding MyItem,Mode=TwoWay}" />
public MyItem
{
get {return myItem;}
set
{
myItem=value;
OnPropertyChanged("MyItem"); implement INotifyPropertyChanged
MyFavFunction(); // Function to be called
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With