Skip to content

How do i use the PropertyChangedMessage of a property annotated with [AlsoBroadcastChange]? #231

Discussion options

You must be logged in to vote

For future reference and if someone has the same question, i found two ways to accomplish the desired outcome:

Using the IRecipient interface:

[ObservableObject]
[ObservableRecipient]
public partial class InputBViewModel : IRecipient<PropertyChangedMessage<string>>
{
	[ObservableProperty]
	[AlsoBroadcastChange]
	private string inputB = string.Empty;

	public void Receive(PropertyChangedMessage<string> msg)
	{
		if (msg.Sender.GetType() == typeof(InputAViewModel))
		{
			if (msg.PropertyName == nameof(InputAViewModel.InputA))
				InputB = msg.NewValue;
		}
	}
}

Obs: Multiple IRecipient interfaces can be used, one for each message type to receive and each requiring a Receive method overload…

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@echoix
Comment options

Answer selected by cleissonalves
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants