UriMapping Class
[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]
Defines the pattern for converting a requested uniform resource identifier (URI) into a new URI.
Inheritance Hierarchy
System..::.Object
System.Windows.Navigation..::.UriMapping
Namespace: System.Windows.Navigation
Assembly: Microsoft.Phone (in Microsoft.Phone.dll)
XMLNS for XAML: Not mapped to an xmlns.
Syntax
Public NotInheritable Class UriMapping
public sealed class UriMapping
<sdk:UriMapping .../>
The UriMapping type exposes the following members.
Constructors
Name | Description | |
---|---|---|
UriMapping | Initializes a new instance of the UriMapping class. |
Top
Properties
Name | Description | |
---|---|---|
MappedUri | Gets or sets the uniform resource identifier (URI) that is navigated to instead of the originally requested URI. | |
Uri | Gets or sets the pattern to match when determining if the requested uniform resource identifier (URI) is converted to a mapped URI. |
Top
Methods
Name | Description | |
---|---|---|
Equals(Object) | Determines whether the specified Object is equal to the current Object. (Inherited from Object.) | |
Finalize | Allows an object to try to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection. (Inherited from Object.) | |
GetHashCode | Serves as a hash function for a particular type. (Inherited from Object.) | |
GetType | Gets the Type of the current instance. (Inherited from Object.) | |
MapUri | Converts the specified uniform resource identifier (URI) to a new URI, if the specified URI matches the defined template for converting. | |
MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) | |
ToString | Returns a string that represents the current object. (Inherited from Object.) |
Top
Remarks
The UriMapping class enables you to specify that a particular URI is converted into another URI. You map one URI to another URI when you want to provide a user-friendly URI that does not map to the physical location of a file. You map a matching URI for only the portion of the URI that pertains to navigation within the frame that contains the mappings. For a browser-integrated application, this portion is found after the fragment delimiter (#). For example, if your browser-integrated Windows Phone application is hosted at https://www.contoso.com/Default.aspx, you specify a matching URI for https://www.contoso.com/Default.aspx\#Home by creating an instance of UriMapping that matches Home. Therefore, you can move your Windows Phone application to a different Web and the URIs you have mapped will still work correctly.
You specify the pattern of a URI to match in the Uri property. You specify in the MappedUri property the URI to navigate to when the pattern is matched.
The UriMapper class has a UriMappings property which contains a collection of UriMapping objects. You add UriMapping objects to this collection to define the how URIs are converted in your application. You define the UriMapper object for a frame by assigning the UriMapper object to the UriMapper property of the frame.
The pattern you specify in the Uri property does not have to be the exact URI to match against the requested URI. The pattern can include placeholder segments in the URI that will match any value in that segment. You specify a placeholder segment by enclosing the name of the segment with the curly braces ( { and } ). These placeholder segments act as variables when mapping to the URI. For example, in the App.xaml file you can specify the following UriMapping instance:
<sdk:UriMapping Uri="Products/{type}"
MappedUri="/Views/ProductDetail.xaml?producttype={type}">
</sdk:UriMapping>
The pattern Products/{type} will match any request that includes Products followed by a segment. The matching URIs could include Products/bikes, Products/kitchen or any other similar request. The value specified in the second segment is included in the query string of the mapped URI where the matching {type} value is defined.
The query string of the requested URI is not evaluated when determining if the requested URI matches the pattern. For example, a value of Home in the Uri property will match a request with #Home or #Home? and any number of query string values.
Version Information
Windows Phone OS
Supported in: 8.1, 8.0, 7.1, 7.0
Platforms
Windows Phone
Thread Safety
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
See Also
Reference
System.Windows.Navigation Namespace