Hi,
I'm trying to handle SelectionChanged event in XamMultiColumnComboEditor.
comboEditor.SelectionChanged += HandleSelectionChanged;
private void HandleSelectionChanged(object sender, EventArgs eventArgs)
{
... do something when the selection changed by the user.
}
I want to handle the event only when the event is triggered by a user.
How can I achieve this?
Thank you in advance.
Dennis
HI,
You could use a boolean flag in your view model that you can set to determine if selection change is by a user or via codebehind/
I am attaching a sample application.
Sincerely,
Matt
Devleoper Suopport Engineer
private void xmcombo1_SelectionChanged(object sender, EventArgs e) { if (vm.ChangeByUser) { MessageBox.Show("change by user"); } else vm.ChangeByUser = true; }
private void btn_Click(object sender, RoutedEventArgs e) { vm.ChangeByUser = false; if (xmcombo1.SelectedIndex == xmcombo1.SelectedItems.Count - 1) { xmcombo1.SelectedIndex = 0; } else xmcombo1.SelectedIndex++; }
There is a problem with this approach.
Let's say the button change the selection when the comboeditor's selected item is not null, then I don't get the expected behavior.
Just try to replace above code with the following:
private void btn_Click(object sender, RoutedEventArgs e) { vm.ChangeByUser = false; if (xmcombo1.SelectedItem != null) { xmcombo1.SelectedIndex++; } }
Run the app, and click the button first. and then change the dropdown selection.
Thank you,