Required field Validation in WPF
-
Dear All, I am in need of Validation of my textboxes when i click save button in WPF. I have tried this code : app.xaml ------------- <Style.Triggers> <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=Text}" Value=""> <!--Set the TextBox Border--> <Setter Property="TextBox.BorderBrush" Value="{StaticResource MySolidBrush}" /> <!--Set the Inner TextBox BG--> <Setter Property="TextBox.Background" Value="{StaticResource MyInnerBrush}"/> <!--Set the RFV Tooltip--> <Setter Property="TextBox.ToolTip" Value="This Field is Mandatory"/> </DataTrigger> </Style.Triggers> test.xaml -------------- sumbit</Button> The code is showing the message as tool tip when i move the cursor to textbox. Since I am new to WPF, i need a code for Requiredfield validator as same as ASP.Net. I have refered the Binding Rules (Validation Rules) concept also , but not know how to do. All my need is when I click my button , It should show the error message to type something. Please help me on this,Its urgent. :sigh: Regards, SelvaKathir.C
-
Dear All, I am in need of Validation of my textboxes when i click save button in WPF. I have tried this code : app.xaml ------------- <Style.Triggers> <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=Text}" Value=""> <!--Set the TextBox Border--> <Setter Property="TextBox.BorderBrush" Value="{StaticResource MySolidBrush}" /> <!--Set the Inner TextBox BG--> <Setter Property="TextBox.Background" Value="{StaticResource MyInnerBrush}"/> <!--Set the RFV Tooltip--> <Setter Property="TextBox.ToolTip" Value="This Field is Mandatory"/> </DataTrigger> </Style.Triggers> test.xaml -------------- sumbit</Button> The code is showing the message as tool tip when i move the cursor to textbox. Since I am new to WPF, i need a code for Requiredfield validator as same as ASP.Net. I have refered the Binding Rules (Validation Rules) concept also , but not know how to do. All my need is when I click my button , It should show the error message to type something. Please help me on this,Its urgent. :sigh: Regards, SelvaKathir.C
Hi SelvaKathir, I assume you have implemented the following things for triggering the Error. 1. Viewmodel implements IDataErrorInfo interface. 2. Set ValidationAttribute on each property which has to be validated or Use SelfValidation attribute on the class and override DoValidate. 3. Controls in Xaml are using bindings and ValidatesOnDataErrors=true,NotifyOnValidationError=true 4. Use a textblock to display the error by binding the error content of the target field. "