views:

76

answers:

1

Hi,

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

+5  A: 

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.

Chris Koenig
Thank you Chris. That helped me a lot :)
Fantastic! If you wouldn't mind marking this answer as accepted, that would really help my reputation.
Chris Koenig