代码所在位置:WPFSamples/Intro/QuickStart5
这个例子没有.cs文件,只有三个XAML文件,实现了在两个页面之间的跳转
MyApp.xaml
<Application
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="Page1.xaml">
</Application>
程序运行直接显示Page1
Page1.xaml
<Page
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<StackPanel Background="LightBlue">
<TextBlock Margin="10,10,10,10">Start Page</TextBlock>
<TextBlock HorizontalAlignment="Left"
Margin="10,10,10,10">
<Hyperlink NavigateUri="Page2.xaml">Go To Page 2</Hyperlink>
</TextBlock>
</StackPanel>
</Page>
Page1,如下图所示
下面这行代码,定义了一个超链接,点击就可以连接到Page2
<Hyperlink NavigateUri="Page2.xaml">Go To Page 2</Hyperlink>
Page2.xaml
<Page
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<StackPanel Background="LightGreen">
<TextBlock DockPanel.Dock="Top"
Margin="10,10,10,10">Page 2</TextBlock>
<TextBlock HorizontalAlignment="Left"
Margin="10,10,10,10">
<Hyperlink NavigateUri="Page1.xaml">Go To The Start Page</Hyperlink>
</TextBlock>
</StackPanel>
</Page>
链接到Page2的图片如下图所示: