if have a text box in xaml. i want only numeric values can be write in textbox to validate on button. how can i do it ?
<TextBox x:Name="txtLevel" Grid.Column="1" HorizontalAlignment="Stretch"></TextBox>
if have a text box in xaml. i want only numeric values can be write in textbox to validate on button. how can i do it ?
<TextBox x:Name="txtLevel" Grid.Column="1" HorizontalAlignment="Stretch"></TextBox>
I would create a class to host all of the additions to textbox that you want to make like below, the bit that stops you putting numbers is in the event handler for PreviewTextInput, if it's not numeric I just say the event is handled and the textbox never gets the value.
To use the helper class with attached property in XAML you need to point a namespace to it then use it like this.
You can use
numericUppDown
instead oftextbox
so as to have only numeric input. That is the way to do it.Use wpf behavior control. Example http://wpfbehaviorlibrary.codeplex.com/