Search code examples
wpfuser-controlswpf-controls

UserControl VS Page in WPF


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.


Solution

  • 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 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)