I have a generic class populated using common functions like the one below to parse a text field:
public static void DoubleParse_KeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Decimal)
{
var textBox = sender as TextBox;
if (textBox != null)
textBox.Text += Convert.ToChar(CultureInfo.CurrentCulture.NumberFormat.CurrencyDecimalSeparator);
}
else
{
e.Handled = (e.Key >= Key.D0 && e.Key <= Key.D9) ||
(e.Key >= Key.NumPad0 && e.Key <= Key.NumPad9) ||
e.Key == Key.Back || e.Key == Key.Delete ||
e.Key == Key.Left || e.Key == Key.Right || e.Key == Key.Unknown;
}
}
I thought I could use this everywhere on my pages as the only source for keydown events for a TextBox. New to implementing MVVM in WP8, curious, is there any way to achieve this?
In the spirit of MVVM (although I'm not a purist), I understand that this does not have to be in the viewmodel, but I still like its centralization.
Quick note:
- The class is not static, I understand that I can not use it directly in xaml.
- I was thinking of making a class like StaticResource and referring to functions in xaml. But that does not work.
- .