ObservableRecipient
A view-model base that participates in IMessenger messaging. While IsActive is true the instance is registered for every IRecipient it implements; property changes can be broadcast as PropertyChangedMessage. The shape mirrors CommunityToolkit.Mvvm.ComponentModel.ObservableRecipient.
Herda de: NotifiableObject
Construtores
protected ObservableRecipient()
observableRecipient = ObservableRecipient()
Initializes a new instance using Default.
protected ObservableRecipient(IMessenger messenger)
observableRecipient = ObservableRecipient(messenger)
Initializes a new instance with the specified messenger.
- messenger
- The messenger to use.
Propriedades
public bool IsActive { get; set; }
value = observableRecipient.IsActive
observableRecipient.IsActive = value
Gets or sets whether this recipient is active. Activating registers its IRecipient handlers; deactivating unregisters them.
protected IMessenger Messenger { get; }
value = observableRecipient.Messenger
The messenger this recipient uses.
Métodos
protected void Broadcast<T>(T oldValue, T newValue, string propertyName)
observableRecipient.Broadcast(oldValue, newValue, propertyName)
Broadcasts a PropertyChangedMessage for a property change.
- oldValue
- The previous value.
- newValue
- The new value.
- propertyName
- The property name.
protected virtual void OnActivated()
observableRecipient.OnActivated()
Called when IsActive becomes true. Registers all implemented IRecipient handlers by default.
protected virtual void OnDeactivated()
observableRecipient.OnDeactivated()
Called when IsActive becomes false. Unregisters this recipient by default.
protected bool SetProperty<T>(T field, T newValue, bool broadcast, string propertyName)
result = observableRecipient.SetProperty(field, newValue, broadcast, propertyName)
Sets a field, raising change notification and optionally broadcasting the change.
- field
- The backing field.
- newValue
- The new value.
- broadcast
- Whether to broadcast a PropertyChangedMessage.
- propertyName
- The property name (auto-filled).
Retorna: true if the value changed.