WPF application strufture RRS feed

  • Question

  • Hi, another newbie question:

    I'm building a silverlight (obviously) application that will not run in a browser.

    I'm trying to grasp the logic behind the app structure.

    the app will have several windows or pages - question 1- which to use ? or maybe use user controls in one window?

    and how do i navigate between them?

    which is "best practice" for building an app like this?

    Wednesday, September 22, 2010 1:34 PM

All replies

  • Your title says WPF, your post says "silverlight (obviously).

    The 2 are different platforms. Silverlight applications run in the browser, WPF applications run on the windows desktop.

    If you are in fact using silverlight, you could create Pages and use the navigation frame as the host container. To navigate between them, you can use hyperlinks, or events attached to elements, or you could write a behavior to do so. I have a WPF version posted at http://chuckhays.net/, but it would need to be modified for Silverlight.

    Wednesday, September 22, 2010 3:57 PM
  • as i said - newbie

    ok so i got my terms wronng?

    i use blend to create the application, and i thought it creates a silverlight windows application?

    so basically it creates a windows app that just looks like a silverlight app?

    so lets start over, i create a WPF app, what's the logical structure for it?

    and how do i navigate pages? windows? user controls?

    Wednesday, September 22, 2010 4:39 PM
  • OK, just to be sure we are clear on the terms:

    Silverlight = browser plugin, runs cross platform, Mac and Windows (and linux with the moonlight project), produces a .xap and .html file.

    WPF = Windows only, produces an .exe.

    So, if you create a WPF app, the main object is based on the Window class, and will be called MainWindow.xaml/MainWindow.xaml.cs. This is the top level object that is the basis of your application.

    WPF has the built in feature that you can simply load Page objects into a default host, so if you add a new item, of type Page, you can right click it and set it as the startup item. To navigate to other Page objects, you can use Hyperlink items, like this:

     Navigate To pack Fragment

    Or programatically in your Page like this:

    private void GoToPage2(object sender, System.Windows.RoutedEventArgs e)
           this.NavigationService.Navigate(new Uri("Page2.xaml", UriKind.Relative));

    This is described here:



    I have no idea why they still talk about XBAP there, which was a concept of WPF in the browser. I would suggest you ignore that, and use Silverlight if you want to run in a browser.


    Wednesday, September 22, 2010 4:56 PM
  • ok, finally i understand,

    so another question,

    i fi create the fist window, where the pages reside (if i understand it correctly)  i tried to do it and selected the first page as startup' but it wasn't sitting in the MainWindow.

    do i need to do something to tell the page to load inside the MainWindow?

    Wednesday, September 22, 2010 5:42 PM
  • If you would rather have the "Frame" inside the main window, you need to do something more, otherwise it will just never use the mainwindow document.


    If you want the changing content inside the MainWindow, you can use the Frame control, which works the same way in code and xaml as above. You set the starting page with the Source property I believe. This is also covered in that webpage above if you are looking for the docs/more info.


    Wednesday, September 22, 2010 5:50 PM
  • ok, so the question is, do i need the ManWindow if i use pages, or can i skip using it?
    Wednesday, September 22, 2010 6:03 PM
  • You can skip using it if you want to just use pages, and navigate between them.
    Wednesday, September 22, 2010 6:13 PM
  • thanks, you've be a great help
    Wednesday, September 22, 2010 6:39 PM