Possible Duplicate:
Validation in textbox in WPF
I am currently using this code to create a numeric only textbox
Xaml
<TextBox Height="22" HorizontalAlignment="Left" Margin="192,118,0,0" Name="Unit_ID" VerticalAlignment="Top" Width="173" PreviewTextInput="UnitID_PreviewTextInput" TextInput="Unit_ID_TextInput" TextChanged="Unit_ID_TextChanged" />
and the C# codebehind
private void UnitID_PreviewTextInput(object sender, TextCompositionEventArgs e)
{
foreach (char c in e.Text)
if (!Char.IsDigit(c))
{
e.Handled = true;
break;
}
is is possible to do this by using XAML EXCLUSIVELY?i am trying to minimize my .cs file