Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
I have 3 TextBoxes (Id,Name and Salary)Id and salary should be integers and Name is only charecters.I need validations for my TextBox as i enter wrong charecters or integers it should show error and also can i do it this in only xaml without codebehind ? I'm new to Wpf and validation please help me with the required code

This is Xaml code

<TextBox Name="tb1" HorizontalAlignment="Left" Height="20" Margin="60,10,0,0" TextWrapping="NoWrap" Text="{Binding SelectedItem.Id,ElementName=dgsample}" VerticalAlignment="Top" Width="100" />

    <TextBox Name="tb2" HorizontalAlignment="Left" Height="20" Margin="60,60,0,0" TextWrapping="NoWrap" Text="{Binding SelectedItem.Name, ElementName=dgsample}" VerticalAlignment="Top" Width="100"/>
    <TextBox Name="tb3" HorizontalAlignment="Left" Height="20" Margin="60,110,0,0" TextWrapping="NoWrap" Text="{Binding SelectedItem.Salary, ElementName=dgsample}" VerticalAlignment="Top" Width="100"/>
Posted
Comments
Pheonyx 23-Oct-13 7:28am    
You have several options, ranging from code behind to xaml for this, and if you Google WPF Validation then you will get plenty of examples. What you can also do is use the xceed extended WPF Toolkit click here which has controls that fix the type of value that can be entered.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900