原文:
WPF笔记(1.2 Navigation导航)——Hello,WPF!
Example
1
-
16
. A sample navigation page
<!--
Page1.xaml
-->
<
Page
x:Class
=
"
MyNavApp.Page1
"
xmlns
=
"
http://schemas.microsoft.com/winfx/avalon/2005
"
xmlns:x
=
"
http://schemas.microsoft.com/winfx/xaml/2005
"
Text
=
"
Page 1
"
>
<
TextBlock FontSize
=
"
72
"
TextWrap
=
"
Wrap
"
>
Check
out
<
Hyperlink NavigateUri
=
"
page2.xaml
"
>
page
2
</
Hyperlink
>
,
too.
</
TextBlock
>
</
Page
>
关键是这句话:
<Hyperlink NavigateUri="page2.xaml">page 2</Hyperlink>
等价于以下后台代码:
NavigationService.GetNavigationService(this).Navigate(new Uri("page2.xaml", UriKind.Relative));
其中,NavigationService是一个提供静态导航方法的类,还有两个方法负责后退和前进:
NavigationService.GetNavigationService(this).GoForward();
NavigationService.GetNavigationService(this).GoBack();
可以放在按钮事件中完成导航。
配套源码的例子是可以用的(WpfPreReleaseBookSamples\ch01\beta2\MyNavApp)。
这一节是讲导航的。看了一遍,发现多不能实现,因为版本更新了,所以很多旧的语法不支持了,比如说,不再有NavigationApplication,仍然是Application,TextBlock容器的TextWrap属性改为TextingWrap,StartupUri指向"Page1.xaml"。只要WPFApplication(不是Browser)内展示Page的页面,都会自动产生导航条。
下面我们来看Page1.xaml
![img_a6339ee3e57d1d52bc7d02b338e15a60.gif](https://yqfile.alicdn.com/img_a6339ee3e57d1d52bc7d02b338e15a60.gif?x-oss-process=image/resize,w_1400/format,webp)
![img_a6339ee3e57d1d52bc7d02b338e15a60.gif](https://yqfile.alicdn.com/img_a6339ee3e57d1d52bc7d02b338e15a60.gif?x-oss-process=image/resize,w_1400/format,webp)
![img_a6339ee3e57d1d52bc7d02b338e15a60.gif](https://yqfile.alicdn.com/img_a6339ee3e57d1d52bc7d02b338e15a60.gif?x-oss-process=image/resize,w_1400/format,webp)
![img_a6339ee3e57d1d52bc7d02b338e15a60.gif](https://yqfile.alicdn.com/img_a6339ee3e57d1d52bc7d02b338e15a60.gif?x-oss-process=image/resize,w_1400/format,webp)
![img_a6339ee3e57d1d52bc7d02b338e15a60.gif](https://yqfile.alicdn.com/img_a6339ee3e57d1d52bc7d02b338e15a60.gif?x-oss-process=image/resize,w_1400/format,webp)
![img_a6339ee3e57d1d52bc7d02b338e15a60.gif](https://yqfile.alicdn.com/img_a6339ee3e57d1d52bc7d02b338e15a60.gif?x-oss-process=image/resize,w_1400/format,webp)
![img_a6339ee3e57d1d52bc7d02b338e15a60.gif](https://yqfile.alicdn.com/img_a6339ee3e57d1d52bc7d02b338e15a60.gif?x-oss-process=image/resize,w_1400/format,webp)
![img_a6339ee3e57d1d52bc7d02b338e15a60.gif](https://yqfile.alicdn.com/img_a6339ee3e57d1d52bc7d02b338e15a60.gif?x-oss-process=image/resize,w_1400/format,webp)
![img_a6339ee3e57d1d52bc7d02b338e15a60.gif](https://yqfile.alicdn.com/img_a6339ee3e57d1d52bc7d02b338e15a60.gif?x-oss-process=image/resize,w_1400/format,webp)
![img_a6339ee3e57d1d52bc7d02b338e15a60.gif](https://yqfile.alicdn.com/img_a6339ee3e57d1d52bc7d02b338e15a60.gif?x-oss-process=image/resize,w_1400/format,webp)
![img_a6339ee3e57d1d52bc7d02b338e15a60.gif](https://yqfile.alicdn.com/img_a6339ee3e57d1d52bc7d02b338e15a60.gif?x-oss-process=image/resize,w_1400/format,webp)
![img_a6339ee3e57d1d52bc7d02b338e15a60.gif](https://yqfile.alicdn.com/img_a6339ee3e57d1d52bc7d02b338e15a60.gif?x-oss-process=image/resize,w_1400/format,webp)
![img_a6339ee3e57d1d52bc7d02b338e15a60.gif](https://yqfile.alicdn.com/img_a6339ee3e57d1d52bc7d02b338e15a60.gif?x-oss-process=image/resize,w_1400/format,webp)
![img_a6339ee3e57d1d52bc7d02b338e15a60.gif](https://yqfile.alicdn.com/img_a6339ee3e57d1d52bc7d02b338e15a60.gif?x-oss-process=image/resize,w_1400/format,webp)
![img_a6339ee3e57d1d52bc7d02b338e15a60.gif](https://yqfile.alicdn.com/img_a6339ee3e57d1d52bc7d02b338e15a60.gif?x-oss-process=image/resize,w_1400/format,webp)
<Hyperlink NavigateUri="page2.xaml">page 2</Hyperlink>
等价于以下后台代码:
NavigationService.GetNavigationService(this).Navigate(new Uri("page2.xaml", UriKind.Relative));
其中,NavigationService是一个提供静态导航方法的类,还有两个方法负责后退和前进:
NavigationService.GetNavigationService(this).GoForward();
NavigationService.GetNavigationService(this).GoBack();
可以放在按钮事件中完成导航。
配套源码的例子是可以用的(WpfPreReleaseBookSamples\ch01\beta2\MyNavApp)。