问题
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.
- i can add a
<Frame></Frame>
to my window and write some pages. - i can write some
UserControls
and put them in aContentControl
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