WPF:使用frame做导航

index页面:

前台:

<Grid Height="380" Width="299">
        <Button Content="Page1" Height="23" HorizontalAlignment="Left" Margin="25,28,0,0" Name="button1" VerticalAlignment="Top" Width="75" Click="button1_Click" />
        <Button Content="Page2" Height="23" HorizontalAlignment="Left" Margin="125,30,0,0" Name="button2" VerticalAlignment="Top" Width="64" Click="button2_Click" />
        <Button Content="Page3" Height="23" HorizontalAlignment="Right" Margin="0,30,30,0" Name="button3" VerticalAlignment="Top" Width="75" Click="button3_Click" />
       
<Frame x:Name="frame1" Margin="0,59,0,0" Width="300" Height="300" Source="Page1.xaml" />  //定义一个Frame
    </Grid>

后台:

private void button1_Click(object sender, RoutedEventArgs e)
        {

            this.frame1.Navigate(new Uri("Page1.xaml", UriKind.Relative));  //当点击按钮的时候,Frame中的内容会变成相应的页面
        }

        private void button2_Click(object sender, RoutedEventArgs e)
        {
              this.frame1.Navigate(new Uri("Page2.xaml", UriKind.Relative));
        }

        private void button3_Click(object sender, RoutedEventArgs e)
        {
                this.frame1.Navigate(new Uri("Page3.xaml", UriKind.Relative));
        }

 

  • 14
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值