Live Chat Icon For mobile
Live Chat Icon
Popular Categories.NET  (145).NET Core  (23)Angular  (40)ASP.NET  (47)ASP.NET Core  (54)ASP.NET MVC  (84)Azure  (28)Blazor  (57)DocIO  (18)Essential JS 2  (65)Essential Studio  (160)Flutter  (61)JavaScript  (135)Microsoft  (97)PDF  (50)React  (30)Succinctly series  (119)Syncfusion  (428)TypeScript  (30)Uno Platform  (2)UWP  (4)Vue  (26)Webinar  (14)Windows Forms  (52)WPF  (98)Xamarin  (107)XlsIO  (20)Other CategoriesBarcode  (4)BI  (29)Bold BI  (3)Build conference  (6)Business intelligence  (53)Button  (4)C#  (100)Chart  (40)Cloud  (9)Company  (445)Dashboard  (5)Data Science  (3)Data Validation  (3)DataGrid  (31)Development  (238)Doc  (7)eBook  (90)Enterprise  (22)Entity Framework  (5)Essential Tools  (14)Excel  (14)Extensions  (8)File Manager  (3)Gantt  (7)Gauge  (4)Git  (3)Grid  (25)HTML  (8)Installer  (1)Knockout  (2)LINQPad  (1)Linux  (1)M-Commerce  (1)Metro Studio  (11)Mobile  (151)Mobile MVC  (9)OLAP server  (1)Orubase  (12)Partners  (20)PDF viewer  (18)Performance  (2)PHP  (1)PivotGrid  (4)Predictive Analytics  (6)Report Server  (3)Reporting  (10)Reporting / Back Office  (11)Rich Text Editor  (5)Road Map  (9)Scheduler  (15)SfDataGrid  (7)Silverlight  (21)Sneak Peek  (12)Solution Services  (2)Spreadsheet  (2)SQL  (4)Stock Chart  (1)Surface  (4)Tablets  (5)Theme  (9)Tips and Tricks  (27)UI  (79)Uncategorized  (68)Unix  (2)User interface  (57)Visual State Manager  (1)Visual Studio  (14)Visual Studio Code  (8)Web  (120)What's new  (78)Windows 8  (19)Windows App  (1)Windows Phone  (15)Windows Phone 7  (9)WinRT  (26)
Share on twitter
Share on facebook
Share on linkedin

Silverlight like Data Validation in WinRT

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 the IDataErrorInfo 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

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

Tags:

Share this post:

Share on twitter
Share on facebook
Share on linkedin

Leave a comment

Popular Now

Be the first to get updates

Subscribe RSS feed
Scroll To Top