Table of Contents

Class NotifyPropertyChangedRecipientsAttribute

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 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]
    private string username;
}

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

partial class MyViewModel
{
    public string Username
    {
        get => username;
        set => SetProperty(ref username, 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.

[AttributeUsage(AttributeTargets.Class|AttributeTargets.Field, AllowMultiple = false, Inherited = false)]
public sealed class NotifyPropertyChangedRecipientsAttribute : Attribute
Inheritance
NotifyPropertyChangedRecipientsAttribute
Inherited Members

Constructors

NotifyPropertyChangedRecipientsAttribute()

public NotifyPropertyChangedRecipientsAttribute()