WPF Prism Master 详细信息表单

发布于 2024-09-11 02:40:43 字数 254 浏览 3 评论 0原文

我正在使用 WPF 创建一个应用程序,该应用程序使用 Prism 框架。 我已经创建了 Shell 表单,并在其中为工具栏、菜单栏和工作区定义了区域。 在工作区中,我能够加载模块,但我有一个要求,即我必须加载“员工主表”表单,以在网格中显示所有员工列表。双击网格中的该员工行,它应该导航到“员工详细信息”表单。在这里我不应该使用 Tab 控件。双击员工网格时,员工主表单应关闭或卸载,员工详细信息屏幕应加载。

Prism 专家对此有何建议。

谢谢和问候, 哈利

I am creating an application using WPF which is using Prism framework.
I have created Shell form and defined regions in that for Toolbar, Menubar and Workspace.
In the workspace area, i am able to load the modules, but I got one requirement where I have to load Employee Master form showing all the employee list in grid. On double click of that employee row in grid it should navigate to the Employee details form. Here I am not supposed to use the Tab control. On double click of the employee grid the Employee Master form should get closed or unloaded and Employee details screen should get loaded.

Any suggestions from Prism Experts on this.

Thanks and Regards,
Harry

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

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

发布评论

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

评论(2

(り薆情海 2024-09-18 02:40:43

我发现在这些场景中,人们正在寻找“棱镜化”他们的解决方案的地方。 我关于何时在 Prism 中使用 EventAggregator 的经验法则:

  1. 无论事件订阅者是否存在,应用程序仍然有用
  2. 我无法使用常规 .NET 事件或其他机制,因为订阅者是在另一个模块中定义的

以下是 我唯一一次使用 EventAggregator 来解决问题。否则,我只使用 WPF 中内置的机制。特别是在主/从场景中,这两个视图可能只有在一起才有用,使它们在逻辑上是相同的视图,而不是单独的视图。

在这种情况下,我通常会这样做(我在这种情况下省略了适当的 DataTemplates,但希望这足以说明您不需要任何花哨的东西来解决这个问题)。

<ListBox ItemsSource="{Binding Turtles}" IsSynchronizedWithCurrentItem="True" />
<ContentControl Source="{Binding Turtles/}" />

这使用了一个简单的 WPF 机制,该机制显示集合中的项目列表,当用户选择一个项目时,“Turtles/”的值将更改为所选项目。简单的。没必要把事情搞得太复杂。

如果您确实觉得您的场景需要 EventAggregator(符合上面的规则 #1 和 #2),那么请尽可能简单地执行...侦听由视图模型引发的事件并从视图模型中使用它(你正在使用 MVVM,对吧?)。再多一点就头疼了。

I find that in these scenarios, people are looking for places to "Prism-ify" their solution. Here's my rule-of-thumb for when to use EventAggregator in Prism:

  1. The application is still useful whether or not a subscriber to the event exists
  2. I cannot use a regular .NET event or other mechanism because the subscriber is defined in another module

Those are the only times I would use EventAggregator to solve a problem. Otherwise, I just use the mechanisms built into WPF. Specifically in a master/detail scenario, the two views are likely useful only together, making them logically the same view, rather than seperate views.

This being the case, I typically do something like this (I've omitted the appopritate DataTemplates in this scenario, but hopefully this is enough to illustrate you don't need anything fancy to solve this problem).

<ListBox ItemsSource="{Binding Turtles}" IsSynchronizedWithCurrentItem="True" />
<ContentControl Source="{Binding Turtles/}" />

This uses a simple WPF mechanism that displays a list of items in a collection and when the user selects an item, the value of "Turtles/" is changed to the item selected. Simple. No need to over-complicate things.

If you really feel like your scenario warrants an EventAggregator (fits with rules #1 and #2 above), then do so as simply as possible... listen to an event both raised by a view model and consume it from a view model (you are using MVVM, right?). Anything more is a headache.

乜一 2024-09-18 02:40:43

我会为此使用事件聚合器或可能使用新的 VisualStateManager。

我在 PRISM 中陷入的陷阱之一是对设计的过度思考。我最终停止使用它并将其从我的项目中删除,事情变得好多了。虽然我仍然使用并喜欢事件聚合器...但是整个区域和视图状态的事情有一个很大的学习曲线...

I would use an eventaggregator for this or possibly the new VisualStateManager.

One of the traps I fell into with PRISM is overthinking the designs. I eventually stopped using it and ripped it out of my project and things have been going much nicer. Though I still use and love eventaggregator...but theres a big learning curve on the whole regions and viewstate thing...

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