PIRATED 20130914 1638

PIRATED 20130914 1638

NOTE: This content appears to have been plagiarized. Please leave a comment or email tnwiki at Microsoft (with a link to this article) if we are mistaken. The content was pulled from the following source:
The community rules state:
  • "Someone else has relevant content and you want to help them share it with the world. It's a nice thought, but do not copy other people's content to the Wiki, even if the owner said it was OK."



Page and Navigation

 

This is one of the amazing features in WPF; this is the major component, which helps in reducing memory, increasing application speed, reduces network bandwidth and be a critical component to success of any application while in production.

There are lot of cool features in web page development like Stateless, low memory consumption as only one page is loaded in the application at a time, the content will be static content in HTML format with JS scripts, this are the features which makes the web technologies like ASP.NET  as the obvious choice for internet or intranet based application.

Microsoft has provided the same features in WPF and user will have the option to do the same with Page, Navigation and other components and achieve all those benefits and make the ideal choice for both web and windows development.

Windows Presentation Foundation (WPF) supports browser-style navigation that can be used in two types of applications: standalone applications and XAML browser applications (XBAPs). To package content for navigation, WPF provides the Page class. You can navigate from one Page to another declaratively, by using a Hyperlink, or programmatically, by using the NavigationService. WPF uses the journal to remember pages that have been navigated from and to navigate back to them.

Page, Hyperlink, NavigationService, and the journal form the core of the navigation support offered by WPF. This overview explores these features in detail before covering advanced navigation support that includes navigation to lose Extensible Application Mark-up Language (XAML) files, HTML files, and objects.

In WPF, you can navigate to several content types that include .NET Framework objects, custom objects, enumeration values, user controls, XAML files, and HTML files. However, you'll find that the most common and convenient way to package content is by using Page. Furthermore, Page implements navigation-specific features to enhance their appearance and simplify development.

Using Page, you can declaratively implement a navigable page of XAML content by using mark-up like the following.

XAML

 

<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" />

 

 

A Page that is implemented in XAML markup has Page as its root element and requires the WPF XML namespace declaration. The Page element contains the content that you want to navigate to and display. You add content by setting the Page.Content property element, as shown in the following markup.

XAML

 

<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">

  <Page.Content>

    <!-- Page Content -->

    Hello, Page!

  </Page.Content>

</Page>

 

 

Page.Content can only contain one child element; in the preceding example, the content is a single string, "Hello, Page!" In practice, you will usually use a layout control as the child element (see Layout System) to contain and compose your content.

The child elements of a Page element are considered to be the content of a Page and, consequently, you don't need to use the explicit Page.Content declaration. The following markup is the declarative equivalent to the preceding sample.

Programmatic Navigation to a Page Object

The following example shows how to use the NavigationService to programmatically navigate to a Page. Programmatic navigation is required because the Page that is being navigated to can only be instantiated using a single, non-default constructor. The Page with the non-default constructor is shown in the following markup and code.

XAML

 

<Page

    x:Class="SDKSample.PageWithNonDefaultConstructor"

    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

    Title="PageWithNonDefaultConstructor">

 

  <!-- Content goes here -->

 

</Page>

 

 

C#

 

using System.Windows.Controls; // Page

 

namespace SDKSample

{

    public partial class PageWithNonDefaultConstructor : Page

    {

        public PageWithNonDefaultConstructor(string message)

        {

            InitializeComponent();

 

            this.Content = message;

        }

    }

}

The Page that navigates to the Page with the non-default constructor is shown in the following markup and code.

XAML

 

<Page

    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

    x:Class="SDKSample.NSNavigationPage">

 

  <Hyperlink Click="hyperlink_Click">

    Navigate to Page with Non-Default Constructor

  </Hyperlink>

 

</Page>

 

 

C#

using System.Windows; // RoutedEventArgs

using System.Windows.Controls; // Page

using System.Windows.Navigation; // NavigationService

 

namespace SDKSample

{

    public partial class NSNavigationPage : Page

    {

        public NSNavigationPage()

        {

            InitializeComponent();

        }

 

        void hyperlink_Click(object sender, RoutedEventArgs e)

        {

            // Instantiate the page to navigate to

            PageWithNonDefaultConstructor page = new PageWithNonDefaultConstructor("Hello!");

 

            // Navigate to the page, using the NavigationService

            this.NavigationService.Navigate(page);

        }

    }

}

When the Hyperlink on this Page is clicked, navigation is initiated by instantiating the Page to navigate to using the non-default constructor and calling the NavigationService.Navigate method. Navigate accepts a reference to the object that the NavigationService will navigate to, rather than a pack URI.

Programmatic Navigation with a Pack URI

If you need to construct a pack URI programmatically (when you can only determine the pack URI at run time, for example), you can use the NavigationService.Navigate method. This is shown in the following example.

XAML

 

<Page

    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

    x:Class="SDKSample.NSUriNavigationPage">

  <Hyperlink Click="hyperlink_Click">Navigate to Page by Pack URI</Hyperlink>

</Page>

 

 

C#

 

using System; // Uri, UriKind

using System.Windows; // RoutedEventArgs

using System.Windows.Controls; // Page

using System.Windows.Navigation; // NavigationService

 

namespace SDKSample

{

    public partial class NSUriNavigationPage : Page

    {

        public NSUriNavigationPage()

        {

            InitializeComponent();

        }

 

        void hyperlink_Click(object sender, RoutedEventArgs e)

        {

            // Create a pack URI

            Uri uri = new Uri("AnotherPage.xaml", UriKind.Relative);

 

            // Get the navigation service that was used to

            // navigate to this page, and navigate to

            // AnotherPage.xaml

            this.NavigationService.Navigate(uri);

        }

    }

}

Refreshing the Current Page

 

A Page is not downloaded if it has the same pack URI as the pack URI that is stored in the NavigationService.Source property. To force WPF to download the current page again, you can call the NavigationService.Refresh method, as shown in the following example.

XAML

 

<Page

    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

    x:Class="SDKSample.NSRefreshNavigationPage">

 <Hyperlink Click="hyperlink_Click">Refresh this page</Hyperlink>

</Page>

 

 

C#

VB

 

using System.Windows; // RoutedEventArgs

using System.Windows.Controls; // Page

using System.Windows.Navigation; // NavigationService

 

namespace SDKSample

{

    public partial class NSRefreshNavigationPage : Page

    {

 

 

...

 

 

        void hyperlink_Click(object sender, RoutedEventArgs e)

        {

            // Force WPF to download this page again

            this.NavigationService.Refresh();

        }

    }

}

 

 

Navigation Lifetime

 

There are many ways to initiate navigation, as you've seen. When navigation is initiated, and while navigation is in progress, you can track and influence the navigation using the following events that are implemented by NavigationService:

  • Navigating . Occurs when a new navigation is requested. Can be used to cancel the navigation.
  • NavigationProgress . Occurs periodically during a download to provide navigation progress information.
  • Navigated . Occurs when the page has been located and downloaded.
  • NavigationStopped . Occurs when the navigation is stopped (by calling StopLoading), or when a new navigation is requested while a current navigation is in progress.
  • NavigationFailed . Occurs when an error is raised while navigating to the requested content.
  • LoadCompleted . Occurs when content that was navigated to is loaded and parsed, and has begun rendering.
  • FragmentNavigation . Occurs when navigation to a content fragment begins, which happens:

Immediately, if the desired fragment is in the current content.

After the source content has been loaded, if the desired fragment is in different content.

The navigation events are raised in the order that is illustrated by the following figure.

In general, a Page isn't concerned about these events. It is more likely that an application is concerned with them and, for that reason, these events are also raised by the Application class:

  • Application.Navigating
  • Application.NavigationProgress
  • Application.Navigated
  • Application.NavigationFailed
  • Application.NavigationStopped
  • Application.LoadCompleted
  • Application.FragmentNavigation

Every time NavigationService raises an event, the Application class raises the corresponding event. Frame and NavigationWindow offer the same events to detect navigation within their respective scopes.

Source

This topic was mostly copied from this MSDN Navigation Overview.
 

Leave a Comment
  • Please add 4 and 3 and type the answer here:
  • Post
Wiki - Revision Comment List(Revision Comment)
Sort by: Published Date | Most Recent | Most Useful
Comments
  • Carsten Siemens edited Revision 2. Comment: Pirated Content - see my comment

  • XAML guy edited Revision 1. Comment: added link to original

  • Fernando Lugão Veltem edited Original. Comment: added toc

Page 1 of 1 (3 items)
Wikis - Comment List
Sort by: Published Date | Most Recent | Most Useful
Posting comments is temporarily disabled until 10:00am PST on Saturday, December 14th. Thank you for your patience.
Comments
  • Fernando Lugão Veltem edited Original. Comment: added toc

  • XAML guy edited Revision 1. Comment: added link to original

  • Carsten Siemens edited Revision 2. Comment: Pirated Content - see my comment

  • NOTE: This article was reported as Pirated/Plagiarized Content (content you didn't write) and will be removed. Please do not steal content from others. If you feel we are mistaken, please leave a comment or email tnwiki at Microsoft with a link to this article and with clear and detailed reasons why you own the content or have explicit permission from the author.

    Content was taken from: "Navigation Overview"

    Published by MSDN

    msdn.microsoft.com/.../ms750478(v=vs.90).aspx

Page 1 of 1 (4 items)