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)
The UriMapping type exposes the following members.
| 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.) |
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}"
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.
The following example shows an instance of UriMapper that is defined within a frame named ContentFrame. The element contains a collection of UriMapping objects.
<sdk:Frame x:Name="ContentFrame" Style="{StaticResource ContentFrameStyle}" Source="/Home" Navigated="ContentFrame_Navigated" NavigationFailed="ContentFrame_NavigationFailed"> <sdk:Frame.UriMapper> <sdk:UriMapper> <sdk:UriMapping Uri="/ProductDetail/{productid}" MappedUri="/Views/ProductDetail.xaml?ProductId={productid}"/> <sdk:UriMapping Uri="/Reports/{type}/{selection}" MappedUri="/Views/ReportsPage.xaml?type={type}&selection={selection}"/> <sdk:UriMapping Uri="/{pageName}" MappedUri="/Views/{pageName}.xaml"/> </sdk:UriMapper> </sdk:Frame.UriMapper> </sdk:Frame>
For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.


