[英]IMessageMediator doesn't hit breakpoint
I've recently upgraded an old project from Catel 4.3 to Catel 5.0. 我最近将一个旧项目从Catel 4.3升级到Catel 5.0。
The project used the InterestedIn attribute which is no longer supported. 项目使用了不再支持的InterestedIn属性。 I tried replacing it with the IMediator but can't get it to work. 我尝试将其替换为IMediator,但无法正常工作。
In the ViewModel that Listens I have the following code: 在侦听的ViewModel中,我有以下代码:
private IMessageMediator _messageMediator;
public CustomerControlViewModel(IMessageMediator messageMediator)
{
Argument.IsNotNull(() => messageMediator);
_messageMediator = messageMediator;
}
[MessageRecipient(Tag = "AddCustomerWindowViewModel")]
protected void AddCustomerWindowViewModelExecuted(string value)
{
if (value == "OnAccept")
RetrieveCustomers();
}
And in the sending ViewModel I have: 在发送ViewModel中,我有:
public AddCustomerWindowViewModel(IMessageMediator messageMediator)
{
Argument.IsNotNull(() => messageMediator);
_messageMediator = messageMediator;
}
private void OnAccept()
{
_messageMediator.SendMessage("OnAccept","AddCustomerWindowViewModel");
}
But when I place a breakpoint on the listener it never hits 但是当我在听众上放置一个断点时,它永远不会击中
I'm missing something, but what? 我想念什么,但是呢?
Just checked the code and unit tests for you. 只需为您检查代码和单元测试。
https://github.com/Catel/Catel/blob/develop/src/Catel.Tests/Messaging/MessageMediatorFacts.cs#L199 https://github.com/Catel/Catel/blob/develop/src/Catel.Tests/Messaging/MessageMediatorFacts.cs#L199
From what I remember, the view models in Catel should auto-register itself as recipients, but maybe we removed it for performance reasons (opt-in model). 据我所知,Catel中的视图模型应自动将其自身注册为接收者,但也许出于性能原因我们将其删除(选择加入模型)。 Couldn't find anything in the release notes though. 不过,在发行说明中找不到任何内容。
Anyway, try registering (and don't forget to unregister!) the vm manually (I recommend in InitializeAsync and CloseAsync). 无论如何,请尝试手动注册(并且不要忘记注销!)虚拟机(我建议在InitializeAsync和CloseAsync中使用)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.