I’m using in my programa several times this code for my TextBox:
private void ResultTextBox_PreviewTextInput(object sender, TextCompositionEventArgs e)
{
e.Handled = !IsTextAllowed(e.Text);
}
private static bool IsTextAllowed(string text)
{
System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex("[^0-9.-]+"); //regex that matches disallowed text
return !regex.IsMatch(text);
}
I’d like to create a custom textbox where I don’t have to write that code anymore in each user control. I have no idea to create custom controls in WPF.
1 Answer