xaml - Change SelectedIndex without triggering SelectedIndexChanged? -
i'm having problem. want set default value (kind of 'header text') combobox. purely aesthetics purposes , describe user initial purpose of combobox.
i have selectedindexchanged combobox opens view.
my problem is, change .selectedindex '0' value 'header' selected. when change index, seems cause infinite loop, until .selectedvalue of combobox becomes null , .selectedindex becomes '-1' throws exception.
my code below:
public myview() { this.initializecomponent(); load += myloadevent(); } private void myloadevent(object sender, routedeventargs e) { mycombobox.selectedindex = 0; } private void mycomboboxselectionchanged(object sender, selectionchangedeventargs e) { // use combobox value , go other view }
thank you!
you can skip first event adding flag variable. skip first 1 or next event after setting processevent
false
:
public myview() { this.initializecomponent(); load += myloadevent(); processevent = false; } ... private void mycomboboxselectionchanged(object sender, selectionchangedeventargs e) { if ( processevent ) { // use combobox value , go other view // event processing ... } processevent = true; }
Comments
Post a Comment