Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>A <strong>Window</strong> object is just what it sounds like: its a new <code>Window</code> for your application. You should use it when you want to pop up an entirely new window. I don't often use more than one <code>Window</code> in WPF because I prefer to put dynamic content in my main Window that changes based on user action.</p> <p>A <strong>Page</strong> is a page inside your Window. It is mostly used for web-based systems like an XBAP, where you have a single browser window and different pages can be hosted in that window. It can also be used in <a href="http://windowsclient.net/learn/video.aspx?v=4190" rel="noreferrer">Navigation Applications</a> like <a href="https://stackoverflow.com/a/12206173/302677">sellmeadog said</a>.</p> <p>A <strong>UserControl</strong> is a reusable user-created control that you can add to your UI the same way you would add any other control. Usually I create a <code>UserControl</code> when I want to build in some custom functionality (for example, a <code>CalendarControl</code>), or when I have a large amount of related XAML code, such as a <code>View</code> when using the MVVM design pattern.</p> <p>When navigating between windows, you could simply create a new <code>Window</code> object and show it</p> <pre class="lang-cs prettyprint-override"><code>var NewWindow = new MyWindow(); newWindow.Show(); </code></pre> <p>but like I said at the beginning of this answer, I prefer not to manage multiple windows if possible. </p> <p>My preferred method of navigation is to create some dynamic content area using a <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.contentcontrol.aspx" rel="noreferrer"><code>ContentControl</code></a>, and populate that with a <code>UserControl</code> containing whatever the current view is.</p> <pre class="lang-xml prettyprint-override"><code>&lt;Window x:Class="MyNamespace.MainWindow" ...&gt; &lt;DockPanel&gt; &lt;ContentControl x:Name="ContentArea" /&gt; &lt;/DockPanel&gt; &lt;/Window&gt; </code></pre> <p>and in your navigate event you can simply set it using </p> <pre class="lang-cs prettyprint-override"><code>ContentArea.Content = new MyUserControl(); </code></pre> <p>But if you're working with WPF, I'd highly recommend the MVVM design pattern. I have a very <a href="http://rachel53461.wordpress.com/2011/12/18/navigation-with-mvvm-2/" rel="noreferrer">basic example on my blog</a> that illustrates how you'd navigate using MVVM, using this pattern:</p> <pre class="lang-xml prettyprint-override"><code>&lt;Window x:Class="SimpleMVVMExample.ApplicationView" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:SimpleMVVMExample" Title="Simple MVVM Example" Height="350" Width="525"&gt; &lt;Window.Resources&gt; &lt;DataTemplate DataType="{x:Type local:HomeViewModel}"&gt; &lt;local:HomeView /&gt; &lt;!-- This is a UserControl --&gt; &lt;/DataTemplate&gt; &lt;DataTemplate DataType="{x:Type local:ProductsViewModel}"&gt; &lt;local:ProductsView /&gt; &lt;!-- This is a UserControl --&gt; &lt;/DataTemplate&gt; &lt;/Window.Resources&gt; &lt;DockPanel&gt; &lt;!-- Navigation Buttons --&gt; &lt;Border DockPanel.Dock="Left" BorderBrush="Black" BorderThickness="0,0,1,0"&gt; &lt;ItemsControl ItemsSource="{Binding PageViewModels}"&gt; &lt;ItemsControl.ItemTemplate&gt; &lt;DataTemplate&gt; &lt;Button Content="{Binding Name}" Command="{Binding DataContext.ChangePageCommand, RelativeSource={RelativeSource AncestorType={x:Type Window}}}" CommandParameter="{Binding }" Margin="2,5"/&gt; &lt;/DataTemplate&gt; &lt;/ItemsControl.ItemTemplate&gt; &lt;/ItemsControl&gt; &lt;/Border&gt; &lt;!-- Content Area --&gt; &lt;ContentControl Content="{Binding CurrentPageViewModel}" /&gt; &lt;/DockPanel&gt; &lt;/Window&gt; </code></pre> <p><img src="https://i.stack.imgur.com/tX7DM.jpg" alt="Screenshot1"> <img src="https://i.stack.imgur.com/AaN5Y.jpg" alt="Screenshot2"></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload