首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

WPF:施用frame做导航

2012-07-31 
WPF:使用frame做导航index页面:前台:Grid Height380 Width299Button ContentPage1 Height23

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));
        }

 

热点排行