使用弹出对话框和 Prism4 掌握详细信息
已经提出了这个问题的多个版本,但我不认为它是重复的。我正在 C#/Prism4 中构建一个 LOB 应用程序,并且我试图从第一天起就获得正确的架构。该应用程序(最终)将有相当多的主/详细信息屏幕以及带有可编辑的嵌入式网格的编辑屏幕。例如:显示能够通过弹出屏幕添加或编辑的用户列表。
目前,我认为一个简单的解决方案是将对话框作为隐藏面板数据绑定到同一视图模型,其可见性由数据绑定控制。要编辑用户(使用上面的示例),请复制要编辑的数据,然后将 IsInEditMode 标志设置为 true 以显示对话框。然后,正常命令可以捕获“保存”/“取消”按钮来更新模型(或不更新)。
虽然这听起来很容易实现,但感觉有点不对。存在关注点分离,只是感觉视图模型正在被复用。
我遇到过 Prism InteractionRequest 指南,但这似乎更适合简单的弹出窗口(“您确定要取消吗?”)。
我需要一个可以跨数十个屏幕扩展的解决方案。它必须简单且易于维护。
提前致谢。
Versions of this question have been asked, but I don't think it's a duplicate as such. I am building an LOB application in C#/Prism4 and I'm trying to get the architecture right from day one. The app will (eventually) have quite a few master/details screens plus edit screens with embedded grids that can be edited. For example: display a list of users with the ability to add or edit via a popup screen.
At the moment, I'm thinking a simple solution would be to have the dialog as a hidden panel databound to the same viewmodel with its visibility controlled by databinding. To edit a user (using above example), make a copy of the data to edit then set a IsInEditMode flag to true to show the dialog. Normal commanding can then capture the 'save'/'cancel' buttons to update the model (or not).
Whereas this sounds simple to implement, it feels a bit wrong. There is a separation of concerns, it just feels like the viewmodel is being multiplexed.
I have come across the Prism InteractionRequest guidance, but that seems more geared towards simple popups ('Are you sure you want to cancel?').
I need a solution that scales across tens of screens. It has to be simple and easy to maintain.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
一般方法是拥有一个所谓的对话框服务,其界面如下所示:
每当您需要显示对话框时,您都可以调用 ShowDialog 方法,传递对话框的视图模型。剩下的就是服务了。它可以显示隐藏面板、真实对话框窗口或弹出窗口 - 这取决于实现,调用方对此一无所知。
The general approach is to have a so called dialog service with the interface something like this:
And whenever you need to show a dialog you call the ShowDialog method passing a view model for the dialog. And the service takes of the rest. It can show a hidden panel, real dialog window or popup - it depends on the implementation and the calling side doesn't know anything about it.
在我看来,主要细节值得拥有自己的视图(如果细节是多个模型对象,则 VM 部分可能是必要的)。
也就是说,我肯定会使用 PopupRegionBehavior,它是 Prism 2.2 RI 的一部分。这对于这种情况特别有用,因为它允许您在特定区域注册主详细信息视图(如果您决定将详细信息拉入 Shell,这仍然有效)。
codeplex 的 Prism 论坛中有许多帖子讨论了这一点。
In my opinion, the master details deserves a view of its own (the VM part might be necessary if the details are of multiple model objects).
That said, I would definitely use the PopupRegionBehavior, that was part of the RI for Prism 2.2. This is particularly useful for this scenario, as it allows you to register the master details View in a specific region (and if you ever decide to pull the details into the Shell, this will still work).
There are many threads in the Prism forum at codeplex that talk about this.
我不同意你的对话框总是应该有它自己的VM,调用方可以只传递它自己的DataContext,这就是你不必关心同步maser/child ViewModel的方式,它与分离无关的担忧。例如,您有一个用户配置文件表单(maser)并且有模式对话框地址 - 如果您在对话框关闭后传递配置文件的虚拟机,则与地址相关的属性和视图字段将自动更新(享受绑定)。
I would not agree that your dialog box always should have it's own VM, the calling side can just pass it's own DataContext, this is how you do not have to take care of syncing maser/child ViewModel and it has nothing to do with the separation of concerns. For example you have an user profile form (maser) and there is modal dialog address - if you pass profile's vm after your dialog is closed your address-related properties and view fields are updated automatically (enjoy the binding).