WPF、MVVM、Shell 和用户控件

发布于 2024-11-25 23:45:13 字数 637 浏览 0 评论 0原文

我正在构建一个基于 MVVM 模式(使用 MVVM Light)的 WPF 应用程序。它有一个外部“外壳”,为应用程序提供了主要外观(状态栏等),然后所有内容都包含在我用 Telerik RadTransitionControl 替换的各种用户控件中。我与此相关的两个问题如下:

  1. 我正在使用 ViewModelLocator 部分构建我的 ViewModel,以实现可混合性。这涉及到一个基本的静态类,它返回一个新的 ViewModel 实例进行绑定,并且只要应用程序正在运行,实例就本质上是共享的。问题是我是否应该使用诸如“ViewLocator”之类的概念,因为它是一个静态类,为我的所有视图都有一个静态属性(应用程序有大约 10 个,所以它不是很大),当我需要时转换到我刚刚从静态集中提取的新视图。这样做的优点是易于使用,但是有缺点吗?有更好的方法来实现这一点吗?

  2. 转换视图的最佳方式是什么?目前,我正在将枚举传递到我的 shell 视图(通过消息传递)以指示我需要哪个视图,但这看起来确实很老套,并且不支持传递某些视图参数。我尝试过一个自定义类,但我几乎需要为每个视图提供一个不同的类,这似乎有点矫枉过正。 WPF 开发人员为此过程执行的标准做法是什么?

预先感谢您的帮助。我对 WPF 相当陌生,因此我想确保了解行业标准并尽可能避免黑客攻击。

I am building a WPF app that is based on the MVVM pattern (using MVVM Light). It has an outer "shell" to it that gives the main look to the app (status bar, etc.) and then all the content is contained in various user controls that I swap out with the Telerik RadTransitionControl. My two questions related to this are as follows:

  1. I am building my ViewModels using the ViewModelLocator part for Blendability purposes. This involves a basic static class that returns a new instance of a ViewModel for binding and instances are essentially shared as long as the app is running. The question for this is whether I should use a concept such as a "ViewLocator" in that it is a static class that has a static property for all of my views (the app has ~10 so it's not huge) and when I need to transition to a new view I just pull from the static set. The pros of this are ease of use, but are there cons? Is there a better way to pursue this?

  2. What is the best way to transition views? Currently I am passing an enum to my shell view (via messaging) to indicate which view I need, but this seems really hacky and doesn't support passing certain views arguments. I toyed with a custom class, but I would almost need a different one for every view and it seemed like it might be overkill. What is the standard practice executed by WPF devs for this process?

Thanks in advance for the help. I'm fairly new to WPF so I want to make sure I learn the industry standards and avoid hacks wherever possible.

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

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

发布评论

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

评论(1

装迷糊 2024-12-02 23:45:13

我正在开发一个使用相同模式的应用程序。我们有一个静态定位器,并且每次切换到应用程序的不同部分(详细信息视图、列表视图、地图视图等)时都会引用相同的 ViewModel。我们使用 ViewModelLocator 模式取得了很多成功 - 这非常简单去理解。我们尚未对运行应用程序多个小时进行重要测试。

我们使用删除了选项卡样式的 TabControl 在应用程序的主屏幕之间进行转换。这为我们提供了一个入口点(我们绑定在“裸”Tabcontrol 上的选定索引属性)来更改应用程序的主屏幕。目前,我们不使用动画。

I work on an application that uses the same pattern. We have a static locator and reference the same ViewModel every time we switch to a different part of the application (details view, list view, map view, etc.) We have had a lot of success with the ViewModelLocator pattern - it is pretty easy to understand. We have not done significant testing with running the application for multiple hours.

We use a TabControl with the tab styling removed to transition between the main screens of the application. This gives us one point of entry (the selected index property that we bind on the "naked" Tabcontrol) to change the major screens of the application. For now, we do not use animations.

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