使用 Messenger 将 IOrder 从 ViewModel1 发送到 ViewModel2,如何区分 ADD/DEL?

发布于 2024-09-28 03:24:30 字数 504 浏览 7 评论 0原文

我有一个 CustomerListViewModel 和一个 OrderListViewModel。在后者中,我选择一个订单将其删除或创建一个新订单。在这两种情况下,我的 CustomerListViewModel 和 Messenger 必须注册到 IOrder 类型:

Messenger.Default.Register<IOrder>(this, AddOrder);
Messenger.Default.Register<IOrder>(this, DeleteOrder);

In the OrderListViewModel I do send the customer to be deleted/added:

Messenger.Default.Send<IOrder>(MyOrderObject);

Now both Actions AddOrder and DeleteOrder gets surely executed, how can I differentiate ?

I have a CustomerListViewModel and a OrderListViewModel. In the latter I select an order to delete it or I create a new one. In both situations my CustomerListViewModel and the Messenger must register to the type IOrder:

Messenger.Default.Register<IOrder>(this, AddOrder);
Messenger.Default.Register<IOrder>(this, DeleteOrder);

In the OrderListViewModel I do send the customer to be deleted/added:

Messenger.Default.Send<IOrder>(MyOrderObject);

Now both Actions AddOrder and DeleteOrder gets surely executed, how can I differentiate ?

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

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

发布评论

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

评论(1

GRAY°灰色天空 2024-10-05 03:24:30

如果是插入或删除,所有者不会发送任何提示。因此,接收者只能自己猜测或发现。
我的建议是引入额外的消息类型(IAddOrder、IDeleteOrder),让发送者有一个接口来告知更改的类型。
如果不可能,您需要将一些信息添加到 IOrder 中,但这只是一个令人讨厌的解决方法,因为交换消息后不再需要数据。

The owner does not send any hint, if it is insert or delete. Hence, the receiver can only guess or find out by himself.
My suggestion is to introduce additional message-types (IAddOrder, IDeleteOrder), s.t. the sender has an interface to tell about the type of change.
If this is not possibe, you would need to add some information into the IOrder, but that would be just a smelly workaround, because the data is no longer needed after exchanging the message.

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