[windows phone开发]导航

windows phone开发——简单导航

      首先建立一个windows phone的项目命名Navigation

      在MainPage页面做一下布局,建立三个新的Page(Page2.xaml,Page3.xaml,Page4.xaml):

 定义一个HyperLinkButtn,两个Button按钮

<strong>  <HyperlinkButton x:Name="button1" HorizontalAlignment="Center" Margin="0,10,0,10" Content="The second page" FontSize="30" NavigateUri="/Page2.xaml"/>
            <Button x:Name="button3" Grid.Row="1" HorizontalAlignment="Center" Margin="0,0,0,10" Content="The third page" FontSize="30" Click="button3_Click"/>
            <Button x:Name="button4" Grid.Row="2"  HorizontalAlignment="Center" Margin="0,0,0,10" Content=" The fourth page" FontSize="30" Click="button4_Click"/></strong>
1、XAML利用HypeLlinkButton按钮,进行导航

      XAML直接使用HyperLinkButton按钮,定义他的NavigateUri属性,即可实现页面导航

      NavigateUri="/Page2.xaml"

2、使用后台代码实现页面导航

    为button3添加Click,双击button3或者Click="button3_Click

   在MainPage.xaml.cs 中添加代码

<strong> private void button3_Click(object sender, RoutedEventArgs e)
        {
            NavigationService.Navigate(new Uri("/Page3.xaml", UriKind.Relative));
        }
</strong>

  3、使用别名地址导航

    首先在APP.xaml增加命名空间的支持

<strong>  xmlns:navgation="clr-namespace:System.Windows.Navigation;assembly=Microsoft.Phone"</strong>

在资源块中添加uri的映射关系

<strong><Application.Resources>
        <local:LocalizedStrings xmlns:local="clr-namespace:Navigation" x:Key="LocalizedStrings"/>
        <navgation:UriMapper x:Key="nav">
            <navgation:UriMapping Uri="The fourth page" MappedUri="/Page4.xaml">
            </navgation:UriMapping>
        </navgation:UriMapper>
    </Application.Resources>
</strong>


在APP.xaml.cs中将映射关系放入程序框架中:在APP的构造函数public APP中添加

 

<strong> RootFrame.UriMapper = Resources["nav"] as UriMapper;</strong>


接下来无论使用HyperLinkButton 还是使用Button都可以使用别名进行导航,本实例使用button4,添加后台代码

<strong>  private void button4_Click(object sender, RoutedEventArgs e)
        {
            NavigationService.Navigate(new Uri("The fourth page", UriKind.Relative));
        }</strong>

今天尝试了这三种方法,与大家分享。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值