Class NotifyDataErrorInfoAttribute
- Namespace
- CommunityToolkit.Mvvm.ComponentModel
- Assembly
- CommunityToolkit.Mvvm.dll
An attribute that can be used to support ObservablePropertyAttribute in generated properties, when applied to fields contained in a type that is inheriting from ObservableValidator and using any validation attributes. When this attribute is used, the generated property setter will also call ValidateProperty(object?, string). This allows generated properties to opt-in into validation behavior without having to fallback into a full explicit observable property.
This attribute can be used as follows:
partial class MyViewModel : ObservableValidator
{
[ObservableProperty]
[NotifyDataErrorInfo]
[Required]
[MinLength(2)]
private string username;
}
And with this, code analogous to this will be generated:
partial class MyViewModel
{
[Required]
[MinLength(2)]
public string Username
{
get => username;
set => SetProperty(ref username, value, validate: true);
}
}
[AttributeUsage(AttributeTargets.Class|AttributeTargets.Field, AllowMultiple = false, Inherited = false)]
public sealed class NotifyDataErrorInfoAttribute : Attribute
- Inheritance
-
NotifyDataErrorInfoAttribute
- Inherited Members
Constructors
NotifyDataErrorInfoAttribute()
public NotifyDataErrorInfoAttribute()