WPF中的用户控件VS页面

编程入门 行业动态 更新时间:2024-10-21 20:39:38
本文介绍了WPF中的用户控件VS页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在编写一个简单的应用程序,它有一个菜单,当用户选择每个 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.

我有两个选择.

  • 我可以在我的窗口中添加一个 <Frame></Frame> 并写一些页面.
  • 我可以写一些 UserControls 并将它们放在 ContentControl
  • i can add a <Frame></Frame> to my window and write some pages.
  • i can write some UserControls and put them in a ContentControl
  • 当用户触发 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页面

    本文发布于:2023-11-08 07:10:58,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1568692.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:控件   页面   用户   WPF

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!