---
title: "Silverlight like Data Validation in WinRT"
published_at: "2013-03-25T14:09:00+00:00"
modified_at: "2019-11-27T11:18:45+00:00"
url: "https://www.syncfusion.com/blogs/post/silverlight-like-data-validation-in-winrt"
excerpt: "Written by Jawahar, Syncfusion Inc. According to a recent MSDN.com forum discussion, Silverlight-like data validation is not available in WinRT. Syncfusion’s editor controls, however, do have built-in options to achieve such data validation. In Silverlight, data is validated by using..."
taxonomy_category:
  - "Development"
  - "User interface"
  - "Windows 8"
  - "WinRT"
taxonomy_post_tag:
  - "data validation"
  - "editors"
  - "error"
  - "Windows 8"
---

# Silverlight like Data Validation in WinRT

[winrt](https://www.syncfusion.com/blogs/author/winrt)

![Image](https://www.syncfusion.com/blogs/wp-content/uploads/2018/08/data_validation_158597b5.png)

**Written by**** Jawahar, Syncfusion Inc.**

According to a [recent MSDN.com forum discussion](http://social.msdn.microsoft.com/Forums/en-US/winappswithcsharp/thread/1749b3e4-87f2-4617-af30-c7be91455b52)
, Silverlight-like data validation is not available in WinRT. Syncfusion’s editor controls, however, do have built-in options to achieve such data validation. In Silverlight, data is validated by using the [IDataErrorInfo](http://msdn.microsoft.com/en-us/library/system.componentmodel.idataerrorinfo(v=vs.100).aspx)
 interface. With Syncfusion WinRT editors, we use the **Syncfusion.UI.Xaml.Controls.Data.IDataValidation** interface for data validation.

Consider a simple model class containing the **Age** property. Let’s say we want to allow values only within the range of 18-80. The following code snippet shows how to implement the **IDataValidation** interface.

```
 public class Person : INotifyPropertyChanged, IDataValidation
 {
     private const string error = "Age should be in the range of 18 to 80.";
     private int _age = 25;
     public int Age
     {
         get { return _age; }
         set { _age = value; RaiseNotification("Age");
     }
 }

 #region IDataValidation implementation
 public string Error
 {
     get { return null; }
 }
 public string this[string columnname]
 {
     get
     {
         if (columnname == "Age")
         {
             if (Age < 18 || Age > 80)
            {
                      return error;
            }
     }
    return null;
  }
} 
 #endregion

 #region INotifyPropertyChanged implementation
 public void RaiseNotification(string propertyname)
 {
    if (PropertyChanged != null)
    {
      PropertyChanged(this, new PropertyChangedEventArgs(propertyname));
    }
}
     public event PropertyChangedEventHandler PropertyChanged; 
  #endregion
 }
```

In the following snippet, the **NotifyOnDataErrors** property enables data validation in the editors. The ** PropertyPath**property tells the editor what property needs to be validated.

```
    
    
    
```

When a value is entered and the tab is clicked, the text box border turns red, indicating an incorrect value. The option for **UpdateSourceTrigger** when a property changes is not available in WinRT binding, so the value will be updated only when focus is lost.

You can also display a message using the **ErrorMessage** property.

![image](https://blog.syncfusion.com/wp-content/uploads/2018/08/image-28.png "image")

This will also work for all our other editor controls, like the NumericTextBox control and the DatePicker control.
