简体   繁体   English

IMessageMediator没有达到断点

[英]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. 只需为您检查代码和单元测试。

  1. I recommend that you use constants for your tags (to prevent any typos) 我建议您为标签使用常量(以防止输入错误)
  2. You should register the recipient as you can see here: 您应该注册收件人,因为您可以在此处看到:

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.

相关问题 第一次单击“登录”和“注册”链接后,没有出现断点 - Breakpoint doesn't hit after first click on Login and Register links 为什么调试器不能始终达到此断点? 我是否忽略了文件句柄? - Why doesn't the debugger hit this breakpoint consistently? Am I neglecting a file handle? Web API 返回结果但即使正确加载符号也不会命中断点 - Web API returns results but doesn't hit breakpoint even when symbols are correctly loaded Xamarin.Forms ImageButton 不起作用,单击不起作用,调试断点根本不会在 iOS 上受到影响 - Xamarin.Forms ImageButton doesn't work, clicking does not work and debug breakpoint doesn't get hit at all on iOS only IEqualityComparer中令人费解的行为 <T> ,未命中Equals()方法中的断点 - Puzzling behaviour in IEqualityComparer<T>, breakpoint in the Equals() method is not hit 无法在 program.main Blazor Client wasm 中命中断点 - Can't hit breakpoint in program.main Blazor Client wasm 断点无法命中 - Breakpoint cannot be hit 断点当前不会被命中,cshtml - The breakpoint will not currently be hit, cshtml 调试器没有命中断点 - Debugger does not hit breakpoint 断点未命中且代码未执行? - Breakpoint not hit and code not executed?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM