有关Navigation的研究——Silverlight学习笔记[29]
在Silverlight的程序設(shè)計(jì)中經(jīng)常需要在多個(gè)XAML頁面之間進(jìn)行切換,以進(jìn)行不同的功能操作。Silverlight為我們提供了一組控件以實(shí)現(xiàn)這一功能。本文將為大家介紹如何在Silverlight中實(shí)現(xiàn)頁面導(dǎo)航功能。
?
與導(dǎo)航有關(guān)的控件
1)Frame
該組件的主要作用是承載Silverlight的XAML頁面。
組件所在命名空間:
System.Windows.Controls
?
組件常用方法:
GoBack:返回前一個(gè)瀏覽頁面,抑或是拋出無前一瀏覽頁面異常。
GoForward:返回后一個(gè)瀏覽頁面,抑或是拋出無后一瀏覽頁面異常。
Navigate:導(dǎo)航至由URI具體指定的內(nèi)容。
StopLoading:停止還未被處理的異步頁面加載。
?
組件常用屬性:
CanGoBack:獲取一個(gè)值用以判定是否能導(dǎo)航至前一個(gè)頁面。
CanGoForward:獲取一個(gè)值用以判定是否能導(dǎo)航至后一個(gè)頁面。
CurrentSource:獲取目前顯示內(nèi)容的URI。
JournalOwnership:獲取或設(shè)置一個(gè)Frame組件是否負(fù)責(zé)管理它自己的導(dǎo)航歷史,抑或是與Web Browser的導(dǎo)航相集成。
Source:獲取或設(shè)置目前內(nèi)容的URI或者是正在被導(dǎo)航到的內(nèi)容的URI。
UriMapper:為Frame組件獲取或設(shè)置一個(gè)對象來將一個(gè)URI轉(zhuǎn)至另一個(gè)URI。
?
組件常用事件:
FragmentNavigation:當(dāng)內(nèi)容段落導(dǎo)航開始時(shí)發(fā)生。
Navigated:當(dāng)頁面內(nèi)容已導(dǎo)航完畢且可得時(shí)發(fā)生。
Navigating:當(dāng)一個(gè)新的導(dǎo)航在被請求時(shí)發(fā)生。
NavigationFailed:當(dāng)被請求導(dǎo)航內(nèi)容發(fā)生錯(cuò)誤時(shí)發(fā)生。
NavigationStopped:當(dāng)一個(gè)導(dǎo)航因?yàn)檎{(diào)用StopLoading方法而終止,或在當(dāng)前導(dǎo)航正在進(jìn)行中,一個(gè)新的導(dǎo)航被請求時(shí)發(fā)生。
?
2)HyperlinkButton
顯示超鏈接的按鈕
組件所在命名空間:
System.Windows.Controls
?
組件常用屬性:
NavigateUri:獲取或設(shè)置導(dǎo)航的URI,當(dāng)該組件被點(diǎn)擊時(shí)。
TargetName:獲取或設(shè)置頁面能被打開的目標(biāo)窗口或Frame,或者是Silverlight應(yīng)用程序中需要導(dǎo)航至的對象。
?
實(shí)例:
說明:首先,在StackPanel組件中添加HyperlinkButton作為導(dǎo)航欄。其次,設(shè)定作為目標(biāo)框架的Frame組件。在Silverlight項(xiàng)目文件夾中添加2個(gè)Silverlight Page文件。
詳細(xì)的說明在代碼中給出。
MainPage.xaml文件代碼:
<UserControl
?? ?xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
?? ?xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
?? ?xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
?? ?mc:Ignorable="d" xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation" x:Class="SilverlightClient.MainPage"
?? ?d:DesignWidth="320" d:DesignHeight="240">
? <Grid x:Name="LayoutRoot" Width="320" Height="240" Background="White">
????? <StackPanel>
????????? <!--導(dǎo)航欄-->
????????? <StackPanel Orientation="Horizontal" Background="WhiteSmoke">
????????????? <HyperlinkButton Content="頁面1" FontSize="14" NavigateUri="/Page1.xaml" TargetName="tgFrame"/>
????????????? <HyperlinkButton Content="頁面2" FontSize="14" NavigateUri="/Page2.xaml" TargetName="tgFrame"/>
????????? </StackPanel>
????????? <!--承載頁面的Frame-->
????????? <navigation:Frame x:Name="tgFrame" FontSize="14" Source="/Page1.xaml" Margin="2" VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch"/>
??? </StackPanel>
? </Grid>
</UserControl>
?
Page1.xaml文件代碼:
<navigation:Page x:Class="SilverlightClient.Page1"
????????? ?xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
????????? ?xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
????????? ?xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
????????? ?xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
????????? ?mc:Ignorable="d"
????????? ?xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
????????? ?d:DesignWidth="640" d:DesignHeight="480"
????????? ?Title="Page1 Page">
??? <Grid x:Name="LayoutRoot">
??????? <TextBlock Text="這里是頁面1的內(nèi)容!"/>
??? </Grid>
</navigation:Page>
Page2.xaml文件代碼:
<navigation:Page x:Class="SilverlightClient.Page2"
?? ????????xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
????????? ?xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
????????? ?xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
????????? ?xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
????????? ?mc:Ignorable="d"
????????? ?xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
????????? ?d:DesignWidth="640" d:DesignHeight="480"
????????? ?Title="Page2 Page">
??? <Grid x:Name="LayoutRoot">
??????? <TextBlock Text="這里是頁面2的內(nèi)容!"/>
??? </Grid>
</navigation:Page>
最終效果圖:
圖一:頁面1
圖二:頁面2
?
| 五皇冠 三春牌多功功能 可調(diào)四合一暖手寶/暖腳寶 電暖器 | ||
| 45.0元? | ||
文章出處:Kinglee’s Blog (http://www.cnblogs.com/Kinglee/)
版權(quán)聲明:本文的版權(quán)歸作者與博客園共有。轉(zhuǎn)載時(shí)須注明本文的詳細(xì)鏈接,否則作者將保留追究其法律責(zé)任。
轉(zhuǎn)載于:https://www.cnblogs.com/Kinglee/archive/2009/09/15/1567367.html
總結(jié)
以上是生活随笔為你收集整理的有关Navigation的研究——Silverlight学习笔记[29]的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: esx4.0 tpm模块初始化失败
- 下一篇: 白蛇