d).注册好别名之后,我们就可以在程序中如下使用:
以下是代码片段: NavigationService.Navigate(new Uri("SecondPage",UriKind.Relative)); |
或者在HyperLinkButton 中如下使用:
以下是代码片段: <HyperlinkButton Content="点转" NavigateUri="SecondPage" Height="30" HorizontalAlignment="Left" Margin="101,68,0,0" Name="hyperlinkButton1" VerticalAlignment="Top" Width="200" /> |
好了,说完如何通过URI导航到指定Page 页面,下面来尝试一下如何通过URI导航传递数据吧。
做过Asp.Net 的童鞋相信对地址栏传值不陌生,比如我现在在博客园写文章的路径如下:
后面的“?”跟着的就是相关的参数或者要表达的某些请求,这种写法很好,又直接。做过WEB的又好理解,不过庆幸的是微软把这个非常棒的功能加入到Windows phone 7的页面传递中来,这真是一大另人兴奋的事,怎么样呢?就这样用:
以下是代码片段: NavigationService.Navigate(new Uri("/Layout/SecondPage.xaml?opt=1", UriKind.Relative)); |
或者
以下是代码片段: <HyperlinkButton Content="点转" NavigateUri="/Layout/SecondPage.xaml?opt=1" Height="30" HorizontalAlignment="Left" Margin="101,68,0,0" Name="hyperlinkButton1" VerticalAlignment="Top" Width="200" /> |
简单明了,不带一丝拖拉看来WEB开发人员进入Windows Phone 7开发也可以哟。。。呵呵~!!
我们刚才的缩写也是同样直接这种URI带参数的写法的,同样还是来到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:UriMapper> </Application.Resources> |