We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on : Nov 16th 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to change the validation error template color?

The SfDataGrid provides a convenient way to validate data and indicate the errors along with its information. By default, validation error templates are displayed in red. However, the SfDataGrid allows you to customize the Validation error template or its icon by writing style for GridCell and GridRowHeaderCell. You can change the validation error template color of the cell by editing the ControlTemplate of the GridCell and also setting the error path fill color. For example, yellow. You can change the validation error template color of the RowHeader by editing the ControlTemplate of the GridRowHeaderCell and setting the path fill color as any. For example, yellow.

GridRowHeaderCell

The control template of the GridRowHeaderCell contains two VisualStateGroups; BorderStates that specifies the BorderThickness of the GridRowHeaderCell and IndicationStates that contains the visual states, CurrentRowError, Error, CurrentRow, Editing row and AddNewRow. The validation error template color of the GridRowHeaderCell is changed by editing the visual state Error. It contains two classes, ObjectAnimationUsingKeyFrames where the error template is drawn and ColorAnimationUsingKeyFrames where the color of the error template is mentioned. The validation error template color is changed by changing the value property of the EasingColorKeyFrame.

XAML

GridCell

The control template of the GridCell contains only one VisualStateGroup that contains the visual states HasError and NoError. The HasError state specifies the width of the error template of the cell and NoError state depicts the state of the cell when it has no errors. Apart from the VisualStateGroup, the control template of the GridCell has three borders. A ContentPresenter is loaded in the first border where the contents of the cell are displayed. The Second border is the CurrentCellBorder and the third border displays the error template. You can change the validation error template color of the GridCell by changing the Fill property of the path codes in the third border.

XAML

 

The following screenshot displays the output for the above code in the SfDataGrid.

D:\Syncfusion\Issues\2014 Volume 2\KB Issues\KB Images\ValidationErrorTemplate.png

Note: The above code examples are for WPF. For WinRT and Silverlight platforms, refer to the following samples.

Sample Links

WPF: DataValidationDemo_WPF

WRT: DataValidationDemo_WRT.zip

SilverLight: DataValidationDemo_SL.zip

Article ID: Published Date: Last Revised Date: Platform: Control: .NET Framework:
2574 09/02/2014 03/28/2017 WPF SfDataGrid 4.5
Did you find this information helpful?
Add Comment
You must log in to leave a comment

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon