[源码下载]

背水一战 Windows 10 (41) - 控件(导航类): Frame

作者:webabcd

介绍
背水一战 Windows 10 之 控件(导航类)

  • Frame

示例
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="导航至 Frame1" Click="btnGotoFrame1_Click" /> <Button Name="btnGotoFrame2" Content="导航至 Frame2" Click="btnGotoFrame2_Click" Margin="0 10 0 0" /> <Button Name="btnBack" Content="后退" 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" VerticalAlignment="Top" Margin="10 0 0 0" /> </StackPanel>
</Grid>
</Page>

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

<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 - 使用 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

<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 - 使用 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的更多相关文章

  1. 背水一战 Windows 10 (40) - 控件(导航类): AppBar, CommandBar

    [源码下载] 背水一战 Windows 10 (40) - 控件(导航类): AppBar, CommandBar 作者:webabcd 介绍背水一战 Windows 10 之 控件(导航类) App ...

  2. 背水一战 Windows 10 (42) - 控件(导航类): Frame 动画

    [源码下载] 背水一战 Windows 10 (42) - 控件(导航类): Frame 动画 作者:webabcd 介绍背水一战 Windows 10 之 控件(导航类) Frame 动画 示例An ...

  3. 背水一战 Windows 10 (31) - 控件(按钮类): ButtonBase, Button, HyperlinkButton, RepeatButton, ToggleButton, AppBarButton, AppBarToggleButton

    [源码下载] 背水一战 Windows 10 (31) - 控件(按钮类): ButtonBase, Button, HyperlinkButton, RepeatButton, ToggleButt ...

  4. 背水一战 Windows 10 (39) - 控件(布局类): VariableSizedWrapGrid, Border, Viewbox, SplitView

    [源码下载] 背水一战 Windows 10 (39) - 控件(布局类): VariableSizedWrapGrid, Border, Viewbox, SplitView 作者:webabcd ...

  5. 背水一战 Windows 10 (76) - 控件(控件基类): Control - 基础知识, 焦点相关, 运行时获取 ControlTemplate 和 DataTemplate 中的元素

    [源码下载] 背水一战 Windows 10 (76) - 控件(控件基类): Control - 基础知识, 焦点相关, 运行时获取 ControlTemplate 和 DataTemplate 中 ...

  6. 背水一战 Windows 10 (37) - 控件(弹出类): MessageDialog, ContentDialog

    [源码下载] 背水一战 Windows 10 (37) - 控件(弹出类): MessageDialog, ContentDialog 作者:webabcd 介绍背水一战 Windows 10 之 控 ...

  7. 背水一战 Windows 10 (36) - 控件(弹出类): ToolTip, Popup, PopupMenu

    [源码下载] 背水一战 Windows 10 (36) - 控件(弹出类): ToolTip, Popup, PopupMenu 作者:webabcd 介绍背水一战 Windows 10 之 控件(弹 ...

  8. 背水一战 Windows 10 (35) - 控件(弹出类): FlyoutBase, Flyout, MenuFlyout

    [源码下载] 背水一战 Windows 10 (35) - 控件(弹出类): FlyoutBase, Flyout, MenuFlyout 作者:webabcd 介绍背水一战 Windows 10 之 ...

  9. 背水一战 Windows 10 (34) - 控件(进度类): RangeBase, Slider, ProgressBar, ProgressRing

    [源码下载] 背水一战 Windows 10 (34) - 控件(进度类): RangeBase, Slider, ProgressBar, ProgressRing 作者:webabcd 介绍背水一 ...

随机推荐

  1. sqlserver 误删数据库恢复

    本文为转载 原文:https://blog.csdn.net/xwnxwn/article/details/53537841 由于长时间从事企业应用系统开发,前往用户现场升级.调试系统是比较常做的事情 ...

  2. putty中查询乱码问题

    我们在putty连接Linux时候,有时候查询会出现乱码问题...如下图 这个是因为putty中设置编码字符集的原因..将此换为utf8格式的即可解决 解决后查询如下:

  3. http://itellyou.cn/

    http://itellyou.cn/ 这里提供了微软MSDN上所有能下载的软件. 下载完记得检验. 这是更详细的介绍:http://wenku.baidu.com/link?url=_dZ0mYvl ...

  4. PHP字符串转实体函数

    与HTML实体相关的函数 htmlspecialchars函数 描述:预定义的字符转换为HTML实体 语法:string htmlspecialchars(string $string [,int $ ...

  5. 异常处理(异常解析器) 和 对于Properties类型的属性的配置

    在程序运行中,有可能因为用户的不当操作,发生异常.. 在springmvc中可以根据不同的异常配置不同的处理方式 1.例如出现 这个类型异常 org.springframework.web.multi ...

  6. MyBatis 实现新增

    MyBatis实现新增 1.概念学习:(角度不同) 1.1 功能:从应用程序角度出发,软件具有哪些功能 1.2 业务:完成功能时的逻辑,对应Service中一个方法 1.3 事务:从数据库角度出发,完 ...

  7. 747. Largest Number At Least Twice of Others

    static int wing=[]() { std::ios::sync_with_stdio(false); cin.tie(NULL); ; }(); class Solution { publ ...

  8. windows下误修改了环境变量path怎么办

    1.在我的电脑图标中右键属性调出系统属性窗口2.在系统属性窗口中找到高级选择卡3.在高级选项卡中找到环境变量按扭并单击打开4.在弹出的环境变量窗口中,在系统变量(S)下的框框中找到并单击选择Path变 ...

  9. 牛客训练六:海啸(二维树状数组+vector函数的使用)

    题目链接:传送门 思路: 二维树状数组, vector(first,last)函数中assign函数相当于将first中的函数清空,然后将last中的值赋值给first. 参考文章:传送门 #incl ...

  10. 使用Wireshark分析网络数据

    一. Wireshark中查看TCP的三次握手和四次挥手: 上面的数据发送和接收两部分的info提示都是 [TCP segment of a reassembled PDU],网上的解释是TCP分片的 ...