Tutorial by Examples

DisplayName sets display name for a property, event or public void method having zero (0) arguments. public class Employee { [DisplayName(@"Employee first name")] public string FirstName { get; set; } } Simple usage example in XAML application <Window x:Class="WpfA...
EditableAttribute sets whether users should be able to change the value of the class property. public class Employee { [Editable(false)] public string FirstName { get; set; } } Simple usage example in XAML application <Window x:Class="WpfApplication.MainWindow" ...
Validation attributes are used to enforce various validation rules in a declarative fashion on classes or class members. All validation attributes derive from the ValidationAttribute base class. Example: RequiredAttribute When validated through the ValidationAttribute.Validate method, this att...
Custom validation attributes can be created by deriving from the ValidationAttribute base class, then overriding virtual methods as needed. [AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited = false)] public class NotABananaAttribute : ValidationAttribute { public ov...
Data annotations are a way of adding more contextual information to classes or members of a class. There are three main categories of annotations: Validation Attributes: add validation criteria to data Display Attributes: specify how the data should be displayed to the user Modelling Attributes...
Most of the times, validation attributes are use inside frameworks (such as ASP.NET). Those frameworks take care of executing the validation attributes. But what if you want to execute validation attributes manually? Just use the Validator class (no reflection needed). Validation Context Any valid...

Page 1 of 1