UriMapping Class


Defines the pattern for converting a requested uniform resource identifier (URI) into a new URI.


Namespace:  System.Windows.Navigation
Assembly:  System.Windows.Controls.Navigation (in System.Windows.Controls.Navigation.dll)

public sealed class UriMapping
<sdk:UriMapping .../> 

The UriMapping type exposes the following members.

Public methodUriMappingInitializes a new instance of the UriMapping class.

Public propertyMappedUriGets or sets the uniform resource identifier (URI) that is navigated to instead of the originally requested URI.
Public propertyUriGets or sets the pattern to match when determining if the requested uniform resource identifier (URI) is converted to a mapped URI.

Public methodEquals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetHashCodeServes as a hash function for a particular type. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodMapUriConverts the specified uniform resource identifier (URI) to a new URI, if the specified URI matches the defined template for converting.
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)

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 Silverlight application is hosted at http://www.contoso.com/Default.aspx, you specify a matching URI for http://www.contoso.com/Default.aspx#Home by creating an instance of UriMapping that matches Home. Therefore, you can move your Silverlight application to a different Web page or run it as an out-of-browser application 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}" 

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.

The following example shows an instance of UriMapper that is defined within a frame named ContentFrame. The element contains a collection of UriMapping objects.

       Style="{StaticResource ContentFrameStyle}" 


Supported in: 5, 4, 3

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Community Additions