我正在编写一个简单的应用程序,它有一个菜单,当用户选择每个 MenuItem 时,我想更改窗口的内容以显示所选内容.
I'm on writing a simple application, it has a menu and when user choices each MenuItem, i want to change my window's content to display the selected content.
我有两个选择.
当用户触发 MenuItem 点击事件时.
as user fires MenuItem click event.
所以我很困惑为此目的选择正确的选择.
so I'm confused to select the right choice for this purpose.
推荐答案使用Frame/Pages或ContentControl/Views可以成功实现导航.这是一个选择问题.
Navigation can be succefully implemented by using Frame/Pages or ContentControl/Views. It is a matter of choice.
但是,框架/页面有一些陷阱,例如page.DataContext 不是从父框架继承的?
However, Frame/Page have some gotchas, e.g. page.DataContext not inherited from parent Frame?
如果您不需要专门隔离,请坚持使用 ContentControl.prism 框架中的导航是使用位于的区域构建的在不同类型的控件(例如 ContentControl、TabControl)中,而不是 Frame(查看文档)
If you don't need isolation specifically, then stick to ContentControl. Navigation in prism framework is built with regions which are located in different type of controls (e.g. ContentControl, TabControl), not Frame (see docs)
简单导航的另一种方法是基于 ViewModel.
one more approach for simple navigation is ViewModel based.
例子:
WPF MVVM 导航视图
Rachel Lim 的 MVVM 导航(外部)
更多推荐
WPF中的用户控件VS页面
发布评论