I created a keypad that has increment and decrement buttons for a touch screen interface. I also overrode TextBox to create a control that will increase or decrease the current integer by 1 when the keypad buttons are pressed. My constructor is registering for the DecrementClickedEvent like this:
EventManager.RegisterClassHandler(
typeof(UIElement), SoftKeyPad.DecrementClickedEvent,
(RoutedEventHandler)OnDecrement);
and here is my handler:
private void OnDecrement(object sender, RoutedEventArgs e)
{
try
{
if (this.IsFocused)
{
var currentNumber = Convert.ToInt32(Text) - 1;
Text = currentNumber.ToString();
}
}
catch (Exception)
{
//If we can't convert, we can't decrement.
if (Text.IsNullOrEmpty())
{
Text = "0";
}
}
}
This however leads to memory leaks I've discovered because the handlers need to be static. If I make the handlers static though, I can't get the text in order to change it. Am I going about this the wrong way? If I make OnDecrement static, how can I edit the text?