页面上有三个单选按钮,然后工程中对应有三个页面:
选择后,点击按钮将会通过下标动态跳转到不同的页面,代码编写看下方。
首先,App.xaml的资源添加:
| 以下是代码片段: <Application.Resources> <nav:UriMapper x:Key="UriMapper"> <nav:UriMapping Uri="SecondPage" MappedUri="/Layout/SecondPage.xaml"/> <nav:UriMapping Uri="SecondPage/{content}" MappedUri="/Layout/SecondPage.xaml?name={content}"/> <nav:UriMapping Uri="page/{number}" MappedUri="/Layout/Page{number}.xaml"/> </nav:UriMapper> </Application.Resources> |
然后,在主页上声明一个全局索引,接着编写如下代码,即可完成:
| 以下是代码片段: private void firstRb_Checked(object sender, RoutedEventArgs e) { index = 1; } private void secondRb_Checked(object sender, RoutedEventArgs e) { index = 2; } private void threeRb_Checked(object sender, RoutedEventArgs e) { index = 3; } private void chooseButton_Click(object sender, RoutedEventArgs e) { NavigationService.Navigate(new Uri("page/"+index,UriKind.Relative)); } |