IT tutorials
 
Mobile
 

Windows Phone 8 : Page Navigation - URI Mapping

3/28/2014 3:58:00 AM
- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019

Relying on URIs that include the full path to each page in your app can make your app brittle and difficult to change the physical location of individual pages. If a page is moved, all references to that file must be updated. This can lead to maintainability issues as the size of the project grows.

The URI mapping system of Windows Phone apps allows requests for a URI to be routed to a different URI, and uses a single configuration point for the management of page URIs. Mapped URIs can be made shorter and are, thus, less subject to typographical errors. They also allow the exclusion of technology specific information, such as the .xaml page file extension, making it easier to retarget business logic for different platforms.

To use URI mapping, you must assign a System.Windows.Navigation.UriMapper instance to the UriMapper property of an app’s PhoneApplicationFrame. This can be done in XAML, as shown in the following excerpt from the App.xaml file in the downloadable sample code:

<Application
    x:Class="DanielVaughan.WPUnleashed.Examples.App"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

        <Application.RootVisual>
            <phone:PhoneApplicationFrame x:Name="RootFrame">
                <phone:PhoneApplicationFrame.UriMapper>
                    <navigation:UriMapper>
                        <navigation:UriMapper.UriMappings>
                            <navigation:UriMapping
                              Uri="/ProductDetails/{productId}"
         MappedUri="/Navigation/ProductDetailsView.xaml?productId={productId}" />
                            <navigation:UriMapping Uri="/WebBrowser/{url}"
                        MappedUri="/WebBrowser/WebBrowserView.xaml?url={url}" />
                        </navigation:UriMapper.UriMappings>
                    </navigation:UriMapper>
                </phone:PhoneApplicationFrame.UriMapper>
            </phone:PhoneApplicationFrame>
        </Application.RootVisual>

        <!-- Content omitted. -->
</Application>

The UriMapping class contains a Uri property and a MappedUri property. When navigation is requested from the Uri value, it is rerouted to the MappedUri property.

By using the curly brace syntax, as shown in the previous excerpt, a substring of the requested URI can be transplanted into the rerouted MappedUri value. This is especially useful when you want to target the same page using different URIs, and where the query string can be used to convey the action to be undertaken by the page.

In the previous excerpt you see a UriMapping for the ProductDetailsView page. The ProductDetailsView displays detailed information for a particular product, identified by a query string parameter. When navigating to the ProductDetails page, if the requested URL is /ProductDetails/2, this is rerouted to /Navigation/ProductDetailsView.xaml?productId=2.

If you were to request the ProductDetailsView page using the NavigationService, as shown in the following example, the request would be rerouted accordingly:

NavigationService.Source = new Uri("/ProductDetails/2", UriKind.Relative);

The product to be displayed can then be determined in the ProductsDetailsView by reading the productId query string parameter, as demonstrated in the following excerpt:

protected override void OnNavigatedTo(NavigationEventArgs e)
{
    base.OnNavigatedTo(e);
    string productIdString = NavigationContext.QueryString["productId"];
    int productId = int.Parse(productIdString);
    ViewModel.LoadProduct(productId);
}

 
Others
 
- Windows Phone 8 : Page Navigation - Passing Page Arguments Using Query Strings
- Windows Phone 8 : Page Navigation - Navigation Using Unmapped URIs
- Windows Phone 8 : Understanding the Application Execution Model - Running Under the Lock Screen - Lock Screen Management
- Windows Phone 8 : Understanding the Application Execution Model - Implementing Fast App Resume - Optimizing the Resume Experience
- Windows Phone 8 : Exploring the Execution Model (part 4) - Restoring Transient State, Saving Persistent State
- Windows Phone 8 : Exploring the Execution Model (part 3) - Programmatically Exiting an App , Saving Transient State
- Windows Phone 8 : Exploring the Execution Model (part 2) - Life Cycle Events
- Windows Phone 8 : Exploring the Execution Model (part 1) - Application State
- Windows Phone 7 to Windows Phone 8 : App publication (part 7) - Selective targeting - Device memory
- Windows Phone 7 to Windows Phone 8 : App publication (part 6) - Selective targeting - Device capabilities
 
 
Top 10
 
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
Technology FAQ
- Is possible to just to use a wireless router to extend wireless access to wireless access points?
- Ruby - Insert Struct to MySql
- how to find my Symantec pcAnywhere serial number
- About direct X / Open GL issue
- How to determine eclipse version?
- What SAN cert Exchange 2010 for UM, OA?
- How do I populate a SQL Express table from Excel file?
- code for express check out with Paypal.
- Problem with Templated User Control
- ShellExecute SW_HIDE
programming4us programming4us