有关Navigation的研究——Silverlight学习笔记[29]
在Silverlight的程序設計中經常需要在多個XAML頁面之間進行切換,以進行不同的功能操作。Silverlight為我們提供了一組控件以實現這一功能。本文將為大家介紹如何在Silverlight中實現頁面導航功能。
?
與導航有關的控件
1)Frame
該組件的主要作用是承載Silverlight的XAML頁面。
組件所在命名空間:
System.Windows.Controls
?
組件常用方法:
GoBack:返回前一個瀏覽頁面,抑或是拋出無前一瀏覽頁面異常。
GoForward:返回后一個瀏覽頁面,抑或是拋出無后一瀏覽頁面異常。
Navigate:導航至由URI具體指定的內容。
StopLoading:停止還未被處理的異步頁面加載。
?
組件常用屬性:
CanGoBack:獲取一個值用以判定是否能導航至前一個頁面。
CanGoForward:獲取一個值用以判定是否能導航至后一個頁面。
CurrentSource:獲取目前顯示內容的URI。
JournalOwnership:獲取或設置一個Frame組件是否負責管理它自己的導航歷史,抑或是與Web Browser的導航相集成。
Source:獲取或設置目前內容的URI或者是正在被導航到的內容的URI。
UriMapper:為Frame組件獲取或設置一個對象來將一個URI轉至另一個URI。
?
組件常用事件:
FragmentNavigation:當內容段落導航開始時發生。
Navigated:當頁面內容已導航完畢且可得時發生。
Navigating:當一個新的導航在被請求時發生。
NavigationFailed:當被請求導航內容發生錯誤時發生。
NavigationStopped:當一個導航因為調用StopLoading方法而終止,或在當前導航正在進行中,一個新的導航被請求時發生。
?
2)HyperlinkButton
顯示超鏈接的按鈕
組件所在命名空間:
System.Windows.Controls
?
組件常用屬性:
NavigateUri:獲取或設置導航的URI,當該組件被點擊時。
TargetName:獲取或設置頁面能被打開的目標窗口或Frame,或者是Silverlight應用程序中需要導航至的對象。
?
實例:
說明:首先,在StackPanel組件中添加HyperlinkButton作為導航欄。其次,設定作為目標框架的Frame組件。在Silverlight項目文件夾中添加2個Silverlight Page文件。
詳細的說明在代碼中給出。
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>
????????? <!--導航欄-->
????????? <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的內容!"/>
??? </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的內容!"/>
??? </Grid>
</navigation:Page>
最終效果圖:
圖一:頁面1
圖二:頁面2
?
| 五皇冠 三春牌多功功能 可調四合一暖手寶/暖腳寶 電暖器 | ||
| 45.0元? | ||
文章出處:Kinglee’s Blog (http://www.cnblogs.com/Kinglee/)
版權聲明:本文的版權歸作者與博客園共有。轉載時須注明本文的詳細鏈接,否則作者將保留追究其法律責任。
轉載于:https://www.cnblogs.com/Kinglee/archive/2009/09/15/1567367.html
總結
以上是生活随笔為你收集整理的有关Navigation的研究——Silverlight学习笔记[29]的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: esx4.0 tpm模块初始化失败
- 下一篇: 白蛇