读书人

WPF:施用frame做导航

发布时间: 2012-07-31 12:33:46 作者: rapoo

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

读书人网 >编程

热点推荐