UserControl VS Page in WPF

心不动则不痛 提交于 2020-06-08 14:50:46

问题


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.

i have two option to that.

  1. i can add a <Frame></Frame> to my window and write some pages.
  2. i can write some UserControls and put them in a ContentControl

as user fires MenuItem click event.

so I'm confused to select the right choice for this purpose.


回答1:


Navigation can be succefully implemented by using Frame/Pages or ContentControl/Views. It is a matter of choice.

However, Frame/Page have some gotchas, e.g. page.DataContext not inherited from parent 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)


one more approach for simple navigation is ViewModel based.

Examples:

WPF MVVM navigate views

Navigation with MVVM by Rachel Lim (external)



来源:https://stackoverflow.com/questions/50408072/usercontrol-vs-page-in-wpf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!