Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RaisePropertyChanged<T>(string propertyName, T oldValue, T newValue, bool broadcast)

I was trying to get the RaisePropertyChanged<T>(string propertyName, T oldValue, T newValue, bool broadcast) working but could not get it to work.

I am not implementing it in any real world scenario but just for learning it. If I raise broadcast the usual way only then it works Messenger.Default.Send<PropertyUpdateeMessage>(new PropertyUpdateeMessage("test"));

So i am wondering what am i missing to use RaisePropertyChanged<T>(string propertyName, T oldValue, T newValue, bool broadcast)

Thanks in advance.

Regards Raki

like image 444
user383663 Avatar asked Dec 07 '22 02:12

user383663


1 Answers

This took me a bit to figure out too. Basically you have to coordinate the message you're registering with the message you're sending, but there isn't a lot of documentation about it.

I have a full working sample here, but here's the info in a nutshell:

First, register for the PropertyChangedMessage specifying the type that's going on the bus

Messenger.Default.Register<PropertyChangedMessage<ObjectICareAbout>>(
    this,
    (action) => DispatcherHelper.CheckBeginInvokeOnUI(
                 () => DoWorkOnObject(action.NewValue) 
                )
);

Then send the message out when the main VM's property changes

RaisePropertyChanged(SelectedItemPropertyName, oldValue, value, true);

There are some disambiguation options you can use when sending out the message and registering to hear it, but this is how the basics work.

like image 175
Chris Koenig Avatar answered Dec 09 '22 15:12

Chris Koenig