MMVMLight注册发送消息

有GalasoftMVVM以及Microsoft.Community.MVVM

MVVMLight

WeakReferenceMessenger.Default.Register<MessageBase>(this, (r, m) => Receive(m));

WeakReferenceMessenger.Default.Unregister<MessageBase>(this);

private void Receive(MessageBase message)
{
    if (message.Value == MessageType.Add)
    { 
        //todo 
    }
}

WeakReferenceMessenger.Default.Send(alarmMsg)



GalaSoftMVVM

Messenger.Default.Register<bool>(this, "SearchStudents", SearchStudents);//消息注册
Messenger.Default.Unregister<object>(this, "SearchStudents");

//SearchStudents(bool obj):消息触发时,需要执行的函数
private void SearchStudents(bool obj)
{
    SearchStudentsDataCmd.Execute(searchType);
}

Messenger.Default.Send<bool>(true, "SearchStudents");

你可能感兴趣的:(wpf,mvvm,wpf)