开发者

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

开发者 https://www.devze.com 2023-01-05 13:47 出处:网络
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 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 bro开发者_JS百科adcast)

Thanks in advance.

Regards Raki


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号