Differentiate Window vs Page vs UserControl in WPF?

Shivam Srivastava picture Shivam Srivastava · Nov 29, 2013 · Viewed 8.8k times · Source

I wondered if someone could help me. I'm new to WPF and am currently writing a desktop application, but I cannot seem to get my head around what to use when redirecting someone to a new section of the application.

My options appear to be

Window
Page
UserControl

but I don't understand what the difference between them is, and when I should use each one.

Could someone explain the differences for me, and give an example of what situations/applications you may use each one for?

Answer

Mike Perrenoud picture Mike Perrenoud · Nov 29, 2013

I'm not sure there is a right answer here, but let me try and guide you. The Window class was created to allow you to have a true window. So, if you need to open a dialog, put it in a Window. Generally you will have at least one Window to house the main form.

A Page was built to be used with the NavigationWindow class. This allows you to build Page classes that are marked up like everything else, but just navigate to them under the covers. This is good if you have a single-paged application where the users just go back and forth between pages (i.e. a wizard).

A UserControl is a way to house reusable markup. These can be housed inside of any ContentControl. These can be swapped out of a "content pane" for example on the main window, like Outlook.

Using that, I hope it helps guide you in the right direction on when to use which. They each have their own uses and are not necessarily exclusive.