World War I Windows 10 (41) and World War I 41
[Download source code]
Back to Water World War I Windows 10 (41)-Controls (navigation class): Frame
Author: webabcd
Introduction
Controls for Windows 10 (navigation class)
Example
Controls/NavigationControl/FrameDemo. xaml
<Page x: Class = "Windows10.Controls. NavigationControl. FrameDemo" xmlns =" http://schemas.microsoft.com/winfx/2006/xaml /Presentation "xmlns: x =" http://schemas.microsoft.com/winfx/2006/xaml "Xmlns: local =" using: Windows10.Controls. NavigationControl "xmlns: d =" http://schemas.microsoft.com/expression/blend/2008 "Xmlns: mc =" http://schemas.openxmlformats.org/markup-compatibility/2006 "Mc: ignorable = "d"> <Grid Background = "Transparent"> <StackPanel Margin = "10 0 10 10" Orientation = "Horizontal"> <StackPanel Width = "400"> <Button name = "btnGotoFrame1" Content = "navigate to Frame1" Click = "btngotoframeworkclick"/> <Button Name = "btnGotoFrame2" Content = "navigate to Frame2" Click = "btnGotoFrame2_Click" Margin = ""0 10 0 0"/> <Button Name = "btnBack" Content = "back" Click = "btnBack_Click" Margin = "0 10 0 0"/> <Button Name =" btnForward "Content =" "Click =" btnForward_Click "Margin =" 0 10 0 0 "/> <TextBlock Name =" lblMsg "TextWrapping =" Wrap "Margin =" 0 10 0 0 "/> </StackPanel> <Frame Name =" frame "verticalignment =" Top "Margin =" 10 0 0 0 "/> </StackPanel> </Grid> </ page>
Controls/NavigationControl/FrameDemo. xaml. cs
/** Frame-framework control, used for navigation content (inherited from ContentControl, see/Controls/BaseControl/ContentControlDemo /) * BackStackDepth-return the number of entries in the stack * BackStack-Return to the set of PageStackEntry instances in the back navigation history * ForwardStack-Return to the set of PageStackEntry instances in the forward navigation history * CanGoBack-can you back navigation * CanGoForward-can you navigate forward * GoBack () -backward navigation: You can specify the transition effect * GoForward ()-Forward Navigation * Navigate ()-Navigate to the specified Type. A parameter of the object Type can be passed, you can specify the transition effect * CurrentSourcePageType-get the Type * SourcePageType of the current content of the Frame-Get or set the Type of the current content of the Frame ** CacheSize-the maximum number of pages that can be cached, the default value is 10 * CacheSize and the Page of the Page to be navigated. navigationCacheMode attributes (for details, see Frame1.xaml. cs and Frame2.xaml. cs sample code) * NavigationCacheMode. disabled-this page is re-instantiated every time you navigate to the page. The default value (invalid CacheSize) * NavigationCacheMode. enabled-this page is first cached when you navigate to the page. If the number of cached pages is greater than CacheSize, the earliest cache page is discarded (CacheSize is valid) * NavigationCacheMode. required-this page is cached every time you navigate to the page (the CacheSize is invalid) ** Navigating-events triggered when navigation starts * Navigated-events triggered after navigation is complete * NavigationFailed-events triggered when navigation fails * NavigationStopped-events in the navigation process, another event triggered when a new navigation is requested ** GetNavigationState ()-obtains the current navigation status of the Frame and returns string-type data, * SetNavigationState (string navigationState) is valid only when no parameters are passed in the navigation or only simple parameters (int, char, string, guid, bool, etc.) are passed) -restore the Frame to the specified navigation status ** PageStackEntry-the Page Object saved in the stack * SourcePageType-get the type of this page * Parameter-get the parameters that were previously navigated to this page ** * NavigationEventArgs-event parameter of the navigation * NavigationMode-navigation mode, read-Only (Windows. UI. xaml. navigation. navigationMode enumeration) * New, Back, Forward, Refresh * Parameter-parameters passed to the target page of the navigation, read-only * SourcePageType-type of the target page of the navigation, read-only ** note: * 1. For information on the transition effect in the navigation process, see/Animation/ThemeTransition/NavigationTransitionInfo/* 2. GoBack () and Navigate () are related to the transition effect in the Frame () */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; // display the current navigation status of the frame. After recording this value, you can use SetNavigationState () to restore the frame to the specified navigation status lblMsg as needed. text + = "NavigationState:" + frame. getNavigationState ();} private void btngotoframeworkclick (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
<Page x:Class="Windows10.Controls.NavigationControl.Frame1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="using:Windows10.Controls.NavigationControl" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d"> <Grid Background="Transparent"> <StackPanel Margin="10 0 10 10"> <TextBlock Name="lblMsg" Margin="5" TextWrapping="Wrap" /> </StackPanel> </Grid></Page>
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-When Frame is used to navigate to this page, the cache mode of the page * Disabled-this page is re-instantiated every time you navigate to the page. The default value is Frame. invalid CacheSize) * Enabled-this page is first cached every time you navigate to the page. If the number of cached pages is greater than Frame. cacheSize, the earliest cache page (Frame. effective CacheSize) * Required-this page (Frame. invalid CacheSize) */this. navigationCacheMode = Windows. UI. xaml. navigation. navigationCacheMode. enabled; this. loaded + = frameuploloaded;} void frameuploloaded (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;} // ready to go, but you can cancel 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
<Page x:Class="Windows10.Controls.NavigationControl.Frame2" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="using:Windows10.Controls.NavigationControl" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d"> <Grid Background="Transparent"> <StackPanel Margin="10 0 10 10"> <TextBlock Name="lblMsg" Margin="5" TextWrapping="Wrap" /> </StackPanel> </Grid></Page>
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-When Frame is used to navigate to this page, the cache mode of the page * Disabled-this page is re-instantiated every time you navigate to the page. The default value is Frame. invalid CacheSize) * Enabled-this page is first cached every time you navigate to the page. If the number of cached pages is greater than Frame. cacheSize, the earliest cache page (Frame. effective CacheSize) * Required-this page (Frame. invalid 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
[Download source code]