WPF Caliburn.Micro / MVVM导航 [英] WPF Caliburn.Micro/mvvm Navigation

查看:402
本文介绍了WPF Caliburn.Micro / MVVM导航的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我建立一个项目,我已经遇到到现在为止最大的一个问题就是导航。结果
我一直在寻找了一段时间现在caliburn.micro / MVVM的例子(!初学者在这里)导航,但他们都似乎是很长的,我无法真正了解多少呢

I'm building a project, and one of the biggest problems I've come across until now is navigation.
I've been looking for some time now for examples of caliburn.micro/mvvm navigation, but they all seem to be really long and I couldn't really understand much of it (beginner here!).

我的项目的一些信息:结果
我希望这是一个外窗/壳,具有菜单链接/标签,按按钮打开的页面点击外壳的内侧部分里面,可以打开从一内换页。

Some info about my project:
I want there to be an outer window/shell, with menu links/tabs that open pages according to the button clicked inside an inner part of the shell, and be able to open change the page from within a one.

我目前有:ShellViewModel.cs,MainViewModel.cs,我的模型,我的看法。
现在,我需要知道的是如何让MainViewModel内负荷在启动时shellviewmodel(使用ContentControl中/帧......),以及如何从一个页面移动到另一个。

I currently have: ShellViewModel.cs, MainViewModel.cs, my models, and my views. For now, all I need to know is how to make MainViewModel load inside shellviewmodel on startup(using contentcontrol/frames...), and how to move from one page to another.

您也可以只是把它写在点,并链接我一些有用的例子,我相信我可以从那里继续。这将会是最好拿到的东西,一个彻底的解释的如果可能的话

You could also just write it in points, and link me to some useful examples, and I believe I could continue from there. It'd be best to get a thorough explanation of stuff if possible.

推荐答案

有一个读了解导体和屏幕上的官方文档的。

作为一个简单的例子,你的 ShellViewModel 可以是一个指挥一个活动的画面(即只有一个屏幕变为有效/无效一次):

As a simple example, your ShellViewModel could be a Conductor of one active screen (i.e. only one screen becomes active/inactive at a time):

public class ShellViewModel : Conductor<IScreen>.Collection.OneActive

然后,您可以设置 ActiveItem 的<$的C $ C>指挥来,你希望成为当前活动视图模型的实例:

You can then set the ActiveItem of the Conductor to the view model instance that you wish to be currently active:

this.ActivateItem(myMainViewModel);

一个集合指挥键入还提供了一个项目集合正如你实例化新的窗口,您可以填充。在这个产品的ViewModels 收集可能是那些正在关闭但尚未关闭,您可以通过使用 ActivateItem 如上。这也使得它非常容易使用的ItemsControl X要打造开放式窗口的菜单:名称=项目 ShellView

A collection Conductor type also provides an Items collection which you can populate as you instantiate new windows. Viewmodels in this Items collection may be those that are currently deactivated but not yet closed, and you can activate them by using ActivateItem as above. It also makes it very easy to create a menu of open windows by using an ItemsControl with x:Name="Items" in your ShellView.

然后,要创建 ShellView ,您可以使用 ContentControl中并设置它的名称是一样的 ActiveItem 属性,卡利。科技将完成剩下的:

Then, to create the ShellView, you can use a ContentControl and set its name to be the same as the ActiveItem property, and Caliburn.Micro will do the rest:

<ContentControl x:Name="ActiveItem" />

您就可以在激活/停用回应你的 MainViewModel 通过在类中重写 OnActivate / OnDeactivate

You can then respond to activation/deactivation in your MainViewModel by overriding OnActivate/OnDeactivate in that class.

这篇关于WPF Caliburn.Micro / MVVM导航的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆