MVVM Light 消息传递问题

发布于 2024-10-03 14:56:48 字数 683 浏览 0 评论 0原文

我在使用 MVVMLight 时面临一系列问题。 其中之一是跨应用程序传递非字符串消息。 这是我传递的消息类型 -

 public class NameValue
    {
        public NameValue()
        {
        }
        public string Name { get; set; }
        public string Value { get; set; }
    }

View1 中

 Messenger.Default.Send<NameValue>(nv, "Message1");

​​ 在ViewModel2 中的

Messenger.Default.Register<NameValue>(this, "Message1", OnMessageSent);

 private void OnMessageSent(NameValue nv)
        {
         }

当我使用 Messender.Default 将消息从一个视图传递到另一个 ViewModel 时,它在消息类型为字符串时有效,但在消息类型为“NameValue”时无效。

如果其他人也面临同样的问题或实施过程中出现问题,请告诉我。

I am facing with series of issues while using MVVMLight.
One of them is passing non-string messages across the application.
This is the message type I am passing -

 public class NameValue
    {
        public NameValue()
        {
        }
        public string Name { get; set; }
        public string Value { get; set; }
    }

in the View1

 Messenger.Default.Send<NameValue>(nv, "Message1");

in the ViewModel2

Messenger.Default.Register<NameValue>(this, "Message1", OnMessageSent);

 private void OnMessageSent(NameValue nv)
        {
         }

When I pass a message using Messender.Default from a View to another ViewModel it works when the message type is string but not when message type is 'NameValue'.

Please let me know if someone else is facing the same problem or there is some thing wrong in the implementation.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

此刻的回忆 2024-10-10 14:56:48

我通过调试周五上传的 SL4 源代码解决了这个问题。

问题出在注册消息以侦听具有相同名称的不同“类型”消息的代码中。

I was able to resolve this issue by debugging the SL4 source code uploaded on Friday.

The issue was in the code where the message was being registered for listening different 'type' of messages with same name.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文