背水一战 Windows 10 (41) - 控件(导航类): Frame
生活随笔
收集整理的這篇文章主要介紹了
背水一战 Windows 10 (41) - 控件(导航类): Frame
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
原文:背水一戰 Windows 10 (41) - 控件(導航類): Frame
[源碼下載]
作者:webabcd
介紹
背水一戰 Windows 10 之 控件(導航類)
- Frame
示例
Controls/NavigationControl/FrameDemo.xaml
Controls/NavigationControl/FrameDemo.xaml.cs
/** Frame - 框架控件,用于導航內容(繼承自 ContentControl, 請參見 /Controls/BaseControl/ContentControlDemo/)* BackStackDepth - 返回 stack 中的條目數* BackStack - 返回向后導航歷史記錄的 PageStackEntry 實例的集合(可以根據需求對集合增刪改查)* ForwardStack - 返回向前導航歷史記錄的 PageStackEntry 實例的集合(可以根據需求對集合增刪改查)* CanGoBack - 可否可以向后導航* CanGoForward - 可否可以向前導航* GoBack() - 向后導航,可以指定過渡效果* GoForward() - 向前導航* Navigate() - 導航到指定的 Type,可以傳遞一個 object 類型的參數,可以指定過渡效果* CurrentSourcePageType - 獲取 Frame 當前內容的 Type* SourcePageType - 獲取或設置 Frame 當前內容的 Type* * CacheSize - 所支持的最大緩存頁數,默認值 10* CacheSize 與被導航的頁的 Page.NavigationCacheMode 屬性相關(詳見 Frame1.xaml.cs 和 Frame2.xaml.cs 的示例代碼)* NavigationCacheMode.Disabled - 每次導航到頁時,都重新實例化此頁,默認值(CacheSize 無效)* NavigationCacheMode.Enabled - 每次導航到頁時,首先緩存此頁,此時如果已緩存的頁數大于 CacheSize,則按先進先出的原則丟棄最早的緩存頁(CacheSize 有效)* NavigationCacheMode.Required - 每次導航到頁時,都緩存此頁(CacheSize 無效)* * Navigating - 導航開始時觸發的事件* Navigated - 導航完成后觸發的事件* NavigationFailed - 導航失敗時觸發的事件* NavigationStopped - 導航過程中,又請求了一個新的導航時觸發的事件* * GetNavigationState() - 獲取 Frame 當前的導航狀態,返回字符串類型的數據,僅當導航無參數傳遞或只傳遞簡單參數(int, char, string, guid, bool 等)時有效* SetNavigationState(string navigationState) - 將 Frame 還原到指定的導航狀態* * * PageStackEntry - 保存在 stack 中的頁對象* SourcePageType - 獲取此頁的類型* Parameter - 獲取之前導航至此頁時的參數** * NavigationEventArgs - 導航的事件參數* NavigationMode - 導航方式,只讀(Windows.UI.Xaml.Navigation.NavigationMode 枚舉)* New, Back, Forward, Refresh* Parameter - 傳遞給導航目標頁的參數,只讀* SourcePageType - 導航的目標頁的類型,只讀* * * 注:* 1、關于導航過程中的過渡效果請參見 /Animation/ThemeTransition/NavigationTransitionInfo/ 中的內容* 2、Frame 中與過渡效果有關的是 GoBack() 和 Navigate() 中的 NavigationTransitionInfo 類型的參數*/using System; using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; using Windows.UI.Xaml.Navigation;namespace Windows10.Controls.NavigationControl {public sealed partial class FrameDemo : Page{public FrameDemo(){this.InitializeComponent();}protected override void OnNavigatedTo(NavigationEventArgs e){frame.Navigated += frame_Navigated;}void frame_Navigated(object sender, NavigationEventArgs e){lblMsg.Text = "CacheSize: " + frame.CacheSize;lblMsg.Text += Environment.NewLine;lblMsg.Text += "BackStackDepth: " + frame.BackStackDepth;lblMsg.Text += Environment.NewLine;lblMsg.Text += "CanGoBack: " + frame.CanGoBack;lblMsg.Text += Environment.NewLine;lblMsg.Text += "CanGoForward: " + frame.CanGoForward;lblMsg.Text += Environment.NewLine;lblMsg.Text += "CurrentSourcePageType: " + frame.CurrentSourcePageType;lblMsg.Text += Environment.NewLine;// 顯示 frame 的當前的導航狀態,記錄此值后,可以在需要的時候通過 SetNavigationState() 將 frame 還原到指定的導航狀態lblMsg.Text += "NavigationState: " + frame.GetNavigationState();}private void btnGotoFrame1_Click(object sender, RoutedEventArgs e){frame.Navigate(typeof(Frame1), "param1");}private void btnGotoFrame2_Click(object sender, RoutedEventArgs e){frame.SourcePageType = typeof(Frame2);}private void btnBack_Click(object sender, RoutedEventArgs e){if (frame.CanGoBack)frame.GoBack();}private void btnForward_Click(object sender, RoutedEventArgs e){if (frame.CanGoForward)frame.GoForward();}} }
Controls/NavigationControl/Frame1.xaml
Controls/NavigationControl/Frame1.xaml.cs
using System; using Windows.UI.Xaml.Controls; using Windows.UI.Xaml.Navigation;namespace Windows10.Controls.NavigationControl {public sealed partial class Frame1 : Page{public Frame1(){this.InitializeComponent();/** Page.NavigationCacheMode - 使用 Frame 導航到此頁面時,頁面的緩存模式* Disabled - 每次導航到頁時,都重新實例化此頁,默認值(Frame.CacheSize 無效)* Enabled - 每次導航到頁時,首先緩存此頁,此時如果已緩存的頁數大于 Frame.CacheSize,則按先進先出的原則丟棄最早的緩存頁(Frame.CacheSize 有效)* Required - 每次導航到頁時,都緩存此頁(Frame.CacheSize 無效)*/this.NavigationCacheMode = Windows.UI.Xaml.Navigation.NavigationCacheMode.Enabled;this.Loaded += Frame1_Loaded;}void Frame1_Loaded(object sender, Windows.UI.Xaml.RoutedEventArgs e){lblMsg.Text += Environment.NewLine;lblMsg.Text += "Loaded: " + DateTime.Now.ToString();}// 來了protected override void OnNavigatedTo(NavigationEventArgs e){lblMsg.Text += Environment.NewLine;lblMsg.Text += "OnNavigatedTo: " + DateTime.Now.ToString();lblMsg.Text += " param: " + (string)e.Parameter;}// 準備走了,但是可以取消protected override void OnNavigatingFrom(NavigatingCancelEventArgs e){lblMsg.Text += Environment.NewLine;lblMsg.Text += "OnNavigatingFrom(NavigatingCancelEventArgs): " + DateTime.Now.ToString();lblMsg.Text += " param: " + (string)e.Parameter;}// 已經走了protected override void OnNavigatedFrom(NavigationEventArgs e){lblMsg.Text += Environment.NewLine;lblMsg.Text += "OnNavigatedFrom(NavigationEventArgs): " + DateTime.Now.ToString();lblMsg.Text += " param: " + (string)e.Parameter;}} }
Controls/NavigationControl/Frame2.xaml
Controls/NavigationControl/Frame2.xaml.cs
using System; using Windows.UI.Xaml.Controls; using Windows.UI.Xaml.Navigation;namespace Windows10.Controls.NavigationControl {public sealed partial class Frame2 : Page{public Frame2(){this.InitializeComponent();/** Page.NavigationCacheMode - 使用 Frame 導航到此頁面時,頁面的緩存模式* Disabled - 每次導航到頁時,都重新實例化此頁,默認值(Frame.CacheSize 無效)* Enabled - 每次導航到頁時,首先緩存此頁,此時如果已緩存的頁數大于 Frame.CacheSize,則按先進先出的原則丟棄最早的緩存頁(Frame.CacheSize 有效)* Required - 每次導航到頁時,都緩存此頁(Frame.CacheSize 無效)*/this.NavigationCacheMode = Windows.UI.Xaml.Navigation.NavigationCacheMode.Enabled;this.Loaded += Frame2_Loaded;}void Frame2_Loaded(object sender, Windows.UI.Xaml.RoutedEventArgs e){lblMsg.Text += Environment.NewLine;lblMsg.Text += "Loaded: " + DateTime.Now.ToString();}protected override void OnNavigatedTo(NavigationEventArgs e){lblMsg.Text += Environment.NewLine;lblMsg.Text += "OnNavigatedTo: " + DateTime.Now.ToString();}} }
OK
[源碼下載]
總結
以上是生活随笔為你收集整理的背水一战 Windows 10 (41) - 控件(导航类): Frame的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 深度deepin安装apache tom
- 下一篇: 奇闻异事之NoSuchMethodErr