Edit

Share via


NotifyPropertyChangedRecipientsAttribute Class

Definition

An attribute that can be used to support ObservablePropertyAttribute in generated properties, when applied to fields and properties contained in a type that is either inheriting from ObservableRecipient, or annotated with ObservableRecipientAttribute. When this attribute is used, the generated property setter will also call Broadcast<T>(T, T, String). This allows generated properties to opt-in into broadcasting behavior without having to fallback into a full explicit observable property.

This attribute can be used as follows:

partial class MyViewModel : ObservableRecipient
{
    [ObservableProperty]
    [NotifyPropertyChangedRecipients]
    public partial string Username;
}

And with this, code analogous to this will be generated:

partial class MyViewModel
{
    public partial string Username
    {
        get => field;
        set => SetProperty(ref field, value, broadcast: true);
    }
}

This attribute can also be added to a class, and if so it will affect all generated properties in that type and inherited types.

[System.AttributeUsage(System.AttributeTargets.Class | System.AttributeTargets.Field | System.AttributeTargets.Property, AllowMultiple=false, Inherited=false)]
public sealed class NotifyPropertyChangedRecipientsAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.Class | System.AttributeTargets.Field | System.AttributeTargets.Property, AllowMultiple=false, Inherited=false)>]
type NotifyPropertyChangedRecipientsAttribute = class
    inherit Attribute
Public NotInheritable Class NotifyPropertyChangedRecipientsAttribute
Inherits Attribute
Inheritance
NotifyPropertyChangedRecipientsAttribute
Attributes

Remarks

Just like ObservablePropertyAttribute, this attribute can also be used on fields as well.

Applies to