IntegerUpDown triggering parent control SelectionChanged event

148 Views Asked by At

I have a ListBox control with IntegerUpDown in each ListBoxItem. Everything works fine, but when the IntegerUpDown reaches the min or the max I set, If I click on the disabled arrows it'll trigger a selectionchanged event for the listbox. Disabled arrow

private void lbItem_SelectionChanged(Object sender, SelectionChangedEventArgs e)
{    
     if (//e.source != integerupdowncontrol)
         //update other view, etc.  
}
1

There are 1 best solutions below

3
DotNetRussell On

Have you tried hooking into the selectionchanged event, checking for your disabled condition, and if disabled set the SelectionChangedEventArgs.Handled to true?

SelectionChangedEventArgs MSDN

private void OnSelectionChanged(Object sender, SelectionChangedEventArgs args){
      if(/*My min or max has been reached*/){
            args.Handled = true;
            return;
      }
}

Here is another example with keypressed