首页 / 软件开发 / .NET编程技术 / WPF学习笔记 - 3. Navigation
WPF学习笔记 - 3. Navigation2010-10-11 rainsts.net Q.yuhen互联网的兴起,造就和培养了一种新的用户交互界面 —— Page & Navigation。无论是前进、后退还是页面,都完全是一个全新的门类,不同于以往的 SDI/MDI。WPF 或者是它的简化版 Silverlight 都不可避免地遵从了这种改良的 B/S 模式,使用 URI 来串接 UI 流程。NavigationService、Page、Hyperlink、Journal(日志/历史记录) 是 WPF 整个导航体系的核心。NavigationService 提供了类似 IE Host 的控制环境,Journal 可以记录和恢复相关 Page 的状态,我们通常会选用的宿主方式包括:Browser(XBAP) 和 NavigationWindow。1. NavigationWindowNavigationWindow 继承自 Window,不知什么原因,我并没有在 VS2008 "New Item..." 中找到相关的条目,只好自己动手将一个 Window 改成 NavigationWindow。Window1.xaml<NavigationWindow x:Class="Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300" WindowStartupLocation="CenterScreen"
Source="Page1.xaml">
</NavigationWindow>
Source 属性指定了该窗口的默认页面,当然,我们还要修改一下 Window1.xaml.cs 里的基类。public partial class Window1 : NavigationWindow{
public Window1()
{
InitializeComponent();
}
}
创建一个 Page1.xaml,我们就可以像普通 Window 那样添加相关的控件和操作。2. Hyperlink超链接应该是我们最熟悉的一种导航方式。Page1.xaml<Page x:Class="Learn.WPF.Page1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Page1">
<Grid>
<TextBlock>
<Hyperlink NavigateUri="Page2.xaml">Page2</Hyperlink>
</TextBlock>
</Grid>
</Page>