在App.xaml里提供了这种方式来使用它的Uri映射机制。
- 1: <Application xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
- 2: xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
- 3: x:Class="NavigationSample.App"
- 4: xmlns:navcore="clr-namespace:System.Windows.Navigation;assembly=System.Windows.Controls.Navigation" >
- 5: <Application.Resources>
- 6: <navcore:UriMapper x:Key="uriMapper">
- 7: <navcore:UriMapping Uri="About-Us" MappedUri="/Views/AboutPage.xaml" />
- 8: </navcore:UriMapper>
- 9: </Application.Resources>
- 10: </Application>
- 1: <navcore:UriMapper x:Key="uriMapper">
- 2: <navcore:UriMapping Uri="{}{page}" MappedUri="/Views/{page}.xaml" />
- 3: </navcore:UriMapper>
你还可以按照一些命名规则,比如你确定你仅需要在页面或者其他什么上限制路由,你可以给你的视图页面命名为"某某Page.xaml",那么你可以编写路由就像这样:
- 1: <navcore:UriMapper x:Key="uriMapper">
- 2: <navcore:UriMapping Uri="{}{page}" MappedUri="/Views/{page}Page.xaml" />
- 3: </navcore:UriMapper>
- 1: <navcore:UriMapper x:Key="uriMapper">
- 2: <navcore:UriMapping Uri="About-Us" MappedUri="/Views/AboutPage.xaml" />
- 3: <navcore:UriMapping Uri="History" MappedUri="/Views/AboutPage.xaml" />
- 4: <navcore:UriMapping Uri="{}{page}" MappedUri="/Views/{page}.xaml" />
- 5: </navcore:UriMapper>