Create Event That is Fired When RepeatButtons are Released
Environment
Product | RadNumericUpDown for WPF |
Description
How to receive only one notification, when the user releases the RepeatButton in a RadNumericUpDown.
Solution
Inherit the RadNumericUpDown control and add a handler for the MouseLeftButtonUp event of the RepeatButtons within the control. In that event handler, raise a custom RoutedEvent.
public class MyNumericUpDown : RadNumericUpDown
{
public MyNumericUpDown()
{
this.AddHandler(RepeatButton.MouseLeftButtonUpEvent, new MouseButtonEventHandler(IncreaseDecreaseButton_MouseLeftButtonUp), true);
}
private void IncreaseDecreaseButton_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
this.RaiseFinalValueChangedEvent();
}
public static readonly RoutedEvent FinalValueChangedEvent = EventManager.RegisterRoutedEvent(
"FinalValueChanged", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(MyNumericUpDown));
public event RoutedEventHandler FinalValueChanged
{
add { AddHandler(FinalValueChangedEvent, value); }
remove { RemoveHandler(FinalValueChangedEvent, value); }
}
void RaiseFinalValueChangedEvent()
{
RoutedEventArgs newEventArgs = new RoutedEventArgs(MyNumericUpDown.FinalValueChangedEvent);
RaiseEvent(newEventArgs);
}
}
<Style TargetType="local:MyNumericUpDown" BasedOn="{StaticResource RadNumericUpDownStyle}" />