背水一战 Windows 10 (5) - UI: 标题栏
作者:webabcd
介绍
背水一战 Windows 10 之 UI
- 标题栏
示例
TitleBarDemo.xaml
<Page
x:Class="Windows10.UI.TitleBarDemo"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Windows10.UI"
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="0 10 0 0" /> <Button Name="btnTitle" Content="改变标题" Click="btnTitle_Click" Margin="0 10 0 0" /> <Button Name="btnColor" Content="改变颜色" Click="btnColor_Click" Margin="0 10 0 0" /> <Button Name="btnBack" Content="显示/隐藏返回按钮" Click="btnBack_Click" Margin="0 10 0 0" /> <Button Name="btnHidden" Content="显示/隐藏标题栏" Click="btnHidden_Click" Margin="0 10 0 0" /> <Button Name="btnFullScreen" Content="全屏/取消全屏" Click="btnFullScreen_Click" Margin="0 10 0 0" /> </StackPanel>
</Grid>
</Page>
TitleBarDemo.xaml.cs
/*
* 演示 TitleBar 相关知识点
*
* 通过 ApplicationView.GetForCurrentView().TitleBar 获取当前的 ApplicationViewTitleBar
* 通过 CoreApplication.GetCurrentView().TitleBar 获取当前的 CoreApplicationViewTitleBar
*
* 注:手工测量 TitleBar 高度为 32 像素
*/ using System;
using Windows.ApplicationModel.Core;
using Windows.UI;
using Windows.UI.Core;
using Windows.UI.ViewManagement;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls; namespace Windows10.UI
{
public sealed partial class TitleBarDemo : Page
{
public TitleBarDemo()
{
this.InitializeComponent(); this.Loaded += TitleBarDemo_Loaded;
} private void TitleBarDemo_Loaded(object sender, RoutedEventArgs e)
{ } // 改变 Title
private void btnTitle_Click(object sender, RoutedEventArgs e)
{
// 改变左上角 Title 的显示内容
ApplicationView.GetForCurrentView().Title = $"My Title Bar({new Random().Next(1000, 10000).ToString()})";
} // 改变 TitleBar 上的相关颜色
private void btnColor_Click(object sender, RoutedEventArgs e)
{
// 获取当前的 ApplicationViewTitleBar
ApplicationViewTitleBar titleBar = ApplicationView.GetForCurrentView().TitleBar; if (titleBar.BackgroundColor != Colors.Orange)
{
// 背景色
titleBar.BackgroundColor = Colors.Orange;
// 前景色
titleBar.ForegroundColor = Colors.White;
// 窗口为非活动状态时的背景色(活动状态就是焦点在窗口上,非活动状态就是焦点不在窗口上)
titleBar.InactiveBackgroundColor = Colors.Yellow;
// 窗口为非活动状态时的前景色
titleBar.InactiveForegroundColor = Colors.Gray; // TitleBar 上的按钮的背景色(按钮包括:最小化按钮,最大化按钮,关闭按钮,返回按钮)
titleBar.ButtonBackgroundColor = Colors.Orange;
// TitleBar 上的按钮的鼠标经过的背景色
titleBar.ButtonHoverBackgroundColor = Colors.Blue;
// TitleBar 上的按钮的鼠标按下的背景色
titleBar.ButtonPressedBackgroundColor = Colors.Green;
// TitleBar 上的按钮的非活动状态的背景色
titleBar.ButtonInactiveBackgroundColor = Colors.Yellow; // TitleBar 上的按钮的前景色
titleBar.ButtonForegroundColor = Colors.White;
// TitleBar 上的按钮的鼠标经过的前景色
titleBar.ButtonHoverForegroundColor = Colors.Red;
// TitleBar 上的按钮的鼠标按下的前景色
titleBar.ButtonPressedForegroundColor = Colors.Purple;
// TitleBar 上的按钮的非活动状态的前景色
titleBar.ButtonInactiveForegroundColor = Colors.Gray;
}
else
{
titleBar.BackgroundColor = null;
titleBar.ForegroundColor = null;
titleBar.InactiveBackgroundColor = null;
titleBar.InactiveForegroundColor = null; titleBar.ButtonBackgroundColor = null;
titleBar.ButtonHoverBackgroundColor = null;
titleBar.ButtonPressedBackgroundColor = null;
titleBar.ButtonInactiveBackgroundColor = null; titleBar.ButtonForegroundColor = null;
titleBar.ButtonHoverForegroundColor = null;
titleBar.ButtonPressedForegroundColor = null;
titleBar.ButtonInactiveForegroundColor = null;
}
} // 显示或隐藏 TitleBar 左上角的返回按钮
private void btnBack_Click(object sender, RoutedEventArgs e)
{
// 当前 TitleBar 左上角的返回按钮是隐藏状态
if (SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility == AppViewBackButtonVisibility.Collapsed)
{
// 显示 TitleBar 左上角的返回按钮
SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = AppViewBackButtonVisibility.Visible;
// 监听 TitleBar 左上角的返回按钮的点击事件
SystemNavigationManager.GetForCurrentView().BackRequested += TitleBarDemo_BackRequested;
}
else
{
SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = AppViewBackButtonVisibility.Collapsed;
SystemNavigationManager.GetForCurrentView().BackRequested -= TitleBarDemo_BackRequested;
}
}
// 处理 TitleBar 左上角的返回按钮的点击事件
private void TitleBarDemo_BackRequested(object sender, BackRequestedEventArgs e)
{
if (MainPage.Current.Container.CanGoBack)
MainPage.Current.Container.GoBack();
} // 显示或隐藏 TitleBar
private void btnHidden_Click(object sender, RoutedEventArgs e)
{
// 切换 TitleBar 的显示/隐藏状态
// 注:TitleBar 隐藏时,仍会显示最小化按钮、最大化按钮、关闭按钮
CoreApplication.GetCurrentView().TitleBar.ExtendViewIntoTitleBar ^= true; /*
* 如果需要自定义 TitleBar 的话,就隐藏它,然后自定义一个自己的即可
* 要注意 TitleBar 的 Height, SystemOverlayLeftInset, SystemOverlayRightInset
* 要注意如果收到 CoreApplicationViewTitleBar.LayoutMetricsChanged 事件,则 Height, SystemOverlayLeftInset, SystemOverlayRightInset 的值可能发生了变化
* 要注意窗口大小发生变化时的处理
*/
CoreApplicationViewTitleBar titleBar = CoreApplication.GetCurrentView().TitleBar;
// Height - TitleBar 的高度
// SystemOverlayLeftInset - TitleBar 浮层左侧的间隔,在这个间隔部分不要放置自定义内容
// SystemOverlayRightInset - TitleBar 浮层右侧的间隔,在这个间隔部分不要放置自定义内容(右侧间隔部分是用于放置最小化按钮,最大化按钮,关闭按钮的。经过测试这个间隔明显多出来一些,也许是预留给其他按钮的)
lblMsg.Text = $"titleBarHeight: {titleBar.Height}, titleBarLeftInset: {titleBar.SystemOverlayLeftInset}, titleBarRightInset: {titleBar.SystemOverlayRightInset}";
} // 进入全屏模式,退出全屏模式
private void btnFullScreen_Click(object sender, RoutedEventArgs e)
{
ApplicationView view = ApplicationView.GetForCurrentView();
// 判断当前是否是全屏模式
if (view.IsFullScreenMode)
{
// 退出全屏模式
view.ExitFullScreenMode();
lblMsg.Text = "退出全屏模式";
}
else
{
// 尝试进入全屏模式
bool isSuccess = view.TryEnterFullScreenMode();
if (isSuccess)
{
lblMsg.Text = "进入全屏模式";
}
else
{
lblMsg.Text = "尝试进入全屏模式失败";
}
} // 注意,进入全屏模式后,TitleBar 会消失,鼠标移动到顶部,则 TitleBar 会再次出现(当然这个行为的具体表现取决于 FullScreenSystemOverlayMode,参见 FullScreen.xaml)
CoreApplicationViewTitleBar titleBar = CoreApplication.GetCurrentView().TitleBar;
// TitleBar 是否是可见状态
bool titleBarIsVisible = titleBar.IsVisible;
// TitleBar 的可见性发生变化时触发的事件
titleBar.IsVisibleChanged += delegate { };
}
}
}
OK
[源码下载]
背水一战 Windows 10 (5) - UI: 标题栏的更多相关文章
- 背水一战 Windows 10 (3) - UI: 窗口全屏, 窗口尺寸
[源码下载] 背水一战 Windows 10 (3) - UI: 窗口全屏, 窗口尺寸 作者:webabcd 介绍背水一战 Windows 10 之 UI 窗口全屏 窗口尺寸 示例1.窗口全屏UI/F ...
- 背水一战 Windows 10 (4) - UI: 多窗口
[源码下载] 背水一战 Windows 10 (4) - UI: 多窗口 作者:webabcd 介绍背水一战 Windows 10 之 UI 多窗口 示例1.自定义帮助类,用于简化 Secondary ...
- 背水一战 Windows 10 (2) - UI: 概述, 启动屏幕, 屏幕方向
[源码下载] 背水一战 Windows 10 (2) - UI: 概述, 启动屏幕, 屏幕方向 作者:webabcd 介绍背水一战 Windows 10 之 UI UI 设计概述 启动屏幕(闪屏) 屏 ...
- 背水一战 Windows 10 (8) - 控件 UI: StateTrigger
[源码下载] 背水一战 Windows 10 (8) - 控件 UI: StateTrigger 作者:webabcd 介绍背水一战 Windows 10 之 控件 UI VisualState 之 ...
- 背水一战 Windows 10 (7) - 控件 UI: VisualState, VisualStateManager, 控件的默认 UI
[源码下载] 背水一战 Windows 10 (7) - 控件 UI: VisualState, VisualStateManager, 控件的默认 UI 作者:webabcd 介绍背水一战 Wind ...
- 背水一战 Windows 10 (6) - 控件 UI: 字体的自动继承的特性, Style, ControlTemplate
[源码下载] 背水一战 Windows 10 (6) - 控件 UI: 字体的自动继承的特性, Style, ControlTemplate 作者:webabcd 介绍背水一战 Windows 10 ...
- 背水一战 Windows 10 (11) - 资源: CustomResource, ResourceDictionary, 加载外部的 ResourceDictionary 文件
[源码下载] 背水一战 Windows 10 (11) - 资源: CustomResource, ResourceDictionary, 加载外部的 ResourceDictionary 文件 作者 ...
- 背水一战 Windows 10 (13) - 绘图: Stroke, Brush
[源码下载] 背水一战 Windows 10 (13) - 绘图: Stroke, Brush 作者:webabcd 介绍背水一战 Windows 10 之 绘图 Stroke - 笔划 Brush ...
- 背水一战 Windows 10 (12) - 绘图: Shape, Path
[源码下载] 背水一战 Windows 10 (12) - 绘图: Shape, Path 作者:webabcd 介绍背水一战 Windows 10 之 绘图 Shape - 图形 Path - 路径 ...
随机推荐
- VS2015的一些资料
http://blog.csdn.net/hk_5788/article/details/48466295 主要看一下js支持方面的,另外今天复习了promise,刚入职的时候看得有些问题,今晚抽时间 ...
- AFNetworking+Python+Flask+pyOpenSSL构建iOS HTTPS客户端&服务器端
对于HTTPS我在网上找了一堆资料看了下, 各种协议和证书已经有点晕了 最后我现有的感觉是, 在HTTP服务器上放一个证书, 在原本的HTTP访问之前客户端先检查证书是否正确 如果客户端证书检查正确, ...
- 知方可补不足~sqlserver中使用sp_who查看sql的进程
回到目录 在SQLSERVER中每个会话,即每个查询分析器窗口都会产生一个SQL进程,对于那些持续时间短的进程,它们转瞬即失,而对于持续时间比较长的,我们需要希望查看它的运行状态,就可以借助SQL提供 ...
- Atitit qzone qq空间博客自动点赞与评论工具的设计与实现
Atitit qzone qq空间博客自动点赞与评论工具的设计与实现 Qzone发送评论的原理 首先,有个a标签, <a class="c_tx3" href="j ...
- 《轻量级Java Web整合开发入门SSH》 - 快速理解Java框架的又一积木
学习JAVA不难,难的是没有多余的时间给你仔细学习. 伴随着项目的不断跟进,责任重于泰山,必须快速提升. 我不能期望把一本书或者一个项目完全吃透,只希望能用数量去 ...
- 使用 flow.ci 实现 Android 自动化测试与持续集成
在上篇文章--如何实现 Android 应用的持续部署中,我们使用的是 flow.ci + Github + fir.im 实现 Android 应用的持续部署.对于 Android 开发者,他们可能 ...
- iOS-SDWebImage
我之前写过一篇博客,介绍缓存处理的三种方式,其中最难,最麻烦,最占内存资源的还是图片缓存,最近做的项目有大量的图片处理,还是采用了SDWebImage来处理,但是发现之前封装好的代码报错了.研究发现, ...
- oracle11g AUD$维护
SYSTEM表空间使用率达到了85%,查出是用来记录审计记录的aud$表占用了很大的空间. 备份后truncate掉AUD$,问题临时解决.记得oracle11.2可以把aud$迁移到普通的表空 间. ...
- WP中的语音识别(上):基本识别
WP 8.1目前许多内容仍处于未确定状态,因此,本文所提及的语音识别,是基于WP8的,在8.1中也差不多,也是使用运行时API来实现,如果大家不知道什么是运行时API,也没关系,不影响学习和开发,因为 ...
- codeforces——Little Pony and Sort by Shift
/* 题目大意:给你一个序列,不断地将最后边的数值移动到最前边,问最少经过多少次可以变成一个单调递增的序列! 如果不能则输出-1. 如果该序列按照不断从后向前移动排序成功,那么该序列要么只有一个单调递 ...