I want to substitute CommunityToolkit.MVVM for GalaSoft.MvvmLight.
I add "using CommunityToolkit.Mvvm.Messaging;"
GalaSoft.MvvmLight register message code, include a class like this:
MessengerInstance.Register<MetadataMessage>(this, annotation, (m) => HandleMessage(m));
The type of "annotation" is AnnotationViewModel, a kind of ViewModel.
MetadataMessage is a struct:
public struct MetadataMessage
{
public MetadataMessage(MetadataMessageType type, MetadataValueViewModel value)
{
Type = type;
MetadataValue = value;
}
public MetadataMessageType Type { get; set; }
public MetadataValueViewModel MetadataValue { get; set; }
}
Another GalaSoft.MvvmLight register message code, include an object is:
MessengerInstance.Register<ModelItemModifyMessage<ModelItem>>(this, messengerToken, (model) => ReceiveModelItemMsg(model));
messengerToken is a object, ModelItemModifyMessage<ModelItem> is a struct:
internal struct ModelItemModifyMessage<T> where T : class
{
internal ModelItemModifyMessage(T source, ModelItemModifyType type, object oldValue)
{
Source = source;
ModifyType = type;
OldValue = oldValue;
}
internal T Source { get; }
internal object OldValue { get; }
internal ModelItemModifyType ModifyType { get; }
}
I try to rewrite register message to CommunityToolkit.MVVM like this:
Messenger.Register<MetadataMessage, AnnotationViewModel>(this, annotation, (t, m) => HandleMessage(m));
But it still not find correct method.
I also try to rewrite another register message to CommunityToolkit.MVVM like this:
Messenger.Register<ModelItemModifyMessage<ModelItem>, object>(this, messengerToken, (t, model) => ReceiveModelItemMsg(model));
It showed:
How can I write correct register message code?
Thanks!