gpt4 book ai didi

silverlight - MVVM Light消息类型: When to use each type?

转载 作者:行者123 更新时间:2023-12-04 04:19:10 26 4
gpt4 key购买 nike

我刚刚开始使用MVVM Light framework学习Silverlight。最近,我开始接触MVVM Light中的Messenger功能。

到目前为止,我已经下载并挖掘了Laurent发表的Clean Shutdown example,并且对Messenger类的工作原理有基本的了解,但是我仍然不确定何时使用哪种Message类型。

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

  • 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.


我的问题是这样的:任何人都可以向我解释一下什么时候我通常会使用每种消息类型,或者将我指向一篇介绍每种消息类型的利弊的文章?

最佳答案

如果您不尝试使编码适合消息,而是使消息做您想要的事情,那么您将为自己省去很多麻烦和烦恼。不要害怕对消息进行子类化,以使它们执行您真正想要的消息。那是我在使用mvvm-light时遇到的第一个错误。

我的大多数邮件都使用GenericMessage,而Generic是我要传输的内容...

例如我有一个ExceptionMessage类,

Public ExceptionMessage:GenericMessage<System.Exception>

然后我用适当的值覆盖3个构造函数。

我发现,用这种方法比用鞋拔子做起来要容易得多。

我有一个深入的示例 here

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

关于silverlight - MVVM Light消息类型: When to use each type?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6282873/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com