具有子窗口和共享数据的 Silverlight MVVM 模式

发布于 2024-11-08 06:24:04 字数 246 浏览 1 评论 0原文

我有一个用于显示两个网格的“父”控件的 ViewModel。第一个网格包含父级信息,第二个网格显示所选父级的相关子级。

这工作得很好,没有任何问题。然而问题是我必须提供一个更新按钮。单击它后,用户将看到所选父级的子级并选择是否删除它们。这是通过子窗口完成的,子窗口包含显示相关子项的相同网格,但网格处于“启用”模式。

所以问题是 MVVM 使用什么模式来: 1)获取子窗口的数据? 2)子窗口内成功更新后,是否更新父窗口?

谢谢,

I have a ViewModel for a "parent" control which displays two grids. The first grid has parent information and the second grid displays the related children for the selected parent.

This works fine without a hitch. However the issue is that I have to provide an update button. Upon clicking it, the user will see the children of the selected parent and opt to delete them or not. THis is done via a child window, containing the same grid that displays the related children, however the grid is in "Enabled" mode.

So the question is what pattern to use with MVVM to:
1) get the child window's data?
2) upon successful update within the child window, update the parent?

Thanks,

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

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

发布评论

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

评论(1

忆沫 2024-11-15 06:24:06

您应该考虑利用中介模式来启用控件的视图模型和子窗口的视图模型之间的通信。

请参阅此回答以获得中介者模式的基本概述。使用此模式,您可以采取的一种方法是在单击“更新”按钮时发布一条消息,该消息由显示子窗口的侦听器处理(该消息将携带子窗口数据,并在更新之前传递到数据上下文)正在显示)。更新成功后,子窗口将发布父窗口监听的消息,该消息将携带更新父窗口的信息。

您可能还想查看

You should consider utilizing the mediator pattern to enable communication between the view model of your control and the view model of your child window.

See this answer to get a basic overview of the mediator pattern. Using this pattern, one approach you can take is to publish a message when the Update button is clicked that is handled by a listener that shows the child window (the message will carry the child windows data, and be passed to the data context prior to being shown). Upon sucessful update the child window would publish a message that the parent listens for, and this message would carry the information to update the parent.

You might also want to take a look at the User Interaction Patterns section in the PRISM 4 guidance. Even if you are not using PRISM, the general principles and approaches taken are well thought through.

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