MVVM Light 消息类型:何时使用每种类型?

发布于 2024-11-14 16:00:34 字数 1256 浏览 4 评论 0原文

我刚刚开始使用 MVVM Light 框架 学习 Silverlight。最近,我开始研究 MVVM Light 中的 Messenger 功能。

到目前为止,我已经下载并深入研究了 Laurent 发布的 Clean Shutdown 示例 对 Messenger 类的工作原理有基本的了解,但我仍然有点不确定何时使用哪种消息类型。

在该网站上,以下是消息类型:

  • MessageBase:一个简单的消息类,携带可选信息 关于消息的发件人。
  • GenericMessage:内容属性为的简单消息 输入T。
  • NotificationMessage:用于将通知(作为字符串)发送到 接受者。例如,保存您的 通知作为常量 通知类,然后发送 通知。保存到收件人。
  • NotificationMessage:与上面相同,但具有通用内容 财产。可以用来传递一个 参数一起传递给接收者 并附有通知。
  • NotificationMessageAction:向收件人发送通知 并允许接收者致电 发件人回复。
  • NotificationMessageAction:向收件人发送通知 并允许接收者致电 发送者返回一个通用参数。
  • DialogMessage:用于请求接收者(通常是视图) 显示一个对话框,并传递 结果返回给调用者(使用 打回来)。收件人可以选择 如何显示对话框,或者使用 一个标准的 MessageBox,带有自定义的 弹出窗口等...
  • PropertyChangedMessage:用于广播属性已更改 在发件人中。满足同样的要求 目的比 PropertyChanged 事件,但以不太严格的方式。

我的问题是这样的:任何人都可以向我解释一下我通常何时使用这些消息类型,或者向我指出一篇详细介绍了使用每种消息类型的优缺点的文章吗?

I've just started learning Silverlight with the MVVM Light framework. Most recently I've started getting into the Messenger features in MVVM Light.

So far I've downloaded and dug into the Clean Shutdown example posted by Laurent and have a basic understanding of how the Messenger class works but I'm still a little unsure when to use which Message type.

From the site, here are the Message types:

  • MessageBase: A simple message class, carrying optional information
    about the message's sender.
  • GenericMessage: A simple message with a Content property of
    type T.
  • NotificationMessage: Used to send a notification (as a string) to a
    recipient. For example, save your
    notifications as constant in a
    Notifications class, and then send
    Notifications.Save to a recipient.
  • NotificationMessage: Same as above, but with a generic Content
    property. Can be used to pass a
    parameter to the recipient together
    with the notification.
  • NotificationMessageAction: Sends a notification to a recipient
    and allows the recipient to call the
    sender back.
  • NotificationMessageAction: Sends a notification to a recipient
    and allows the recipient to call the
    sender back with a generic parameter.
  • DialogMessage: Used to request that a recipient (typically a View)
    displays a dialog, and passes the
    result back to the caller (using a
    callback). The recipient can choose
    how to display the dialog, either with
    a standard MessageBox, with a custom
    popup, etc…
  • PropertyChangedMessage: Used to broadcast that a property changed
    in the sender. Fulfills the same
    purpose than the PropertyChanged
    event, but in a less tight way.

My question is this: Can anyone explain to me when I would typically use each of these Message types or point me to an article that breaks down the pros and cons of using each message type?

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

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

发布评论

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

评论(1

自找没趣 2024-11-21 16:00:34

如果您不尝试将编码与消息相匹配而是让消息按照您的意愿行事,那么您将为自己省去很多麻烦和烦恼。不要害怕对消息进行子类化,让它们做你真正想要的事情。这是我使用 mvvm-light 时犯的第一个错误。

我的大多数消息都使用 GenericMessage,而 Generic 是我想要传输的内容...

例如,我有一个 ExceptionMessage 类,

Public ExceptionMessage:GenericMessage<System.Exception>

然后我用正确的值重写 3 个构造函数。

我发现这样做比用鞋拔子把东西固定到位要容易得多。

我有一个深入的例子这里

它来自另一个关于消息传递的问题,我可以在其中访问我的代码......

You will save your self a lot of headaches and annoyance if you dont try to fit your coding to the messages but make the messages do what you want. Dont be afraid to subclass the messages to make them do what you really want from them. That was one of my first mistakes when using mvvm-light.

Most of my messages use the GenericMessage with the Generic being what I am trying to transfer...

for instance i have an ExceptionMessage class that

Public ExceptionMessage:GenericMessage<System.Exception>

then i override the 3 constructors with the proper values.

I found that its MUCH easier to do it this way than shoehorn things into place.

I have an indepth example here

Its from another question about messaging where I had access to my code...

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