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 { };
}
}
}

UI: 标题栏的更多相关文章

  1. 背水一战 Windows 10 (5) - UI: 标题栏

    [源码下载] 背水一战 Windows 10 (5) - UI: 标题栏 作者:webabcd 介绍背水一战 Windows 10 之 UI 标题栏 示例TitleBarDemo.xaml <P ...

  2. 上门洗车APP --- Androidclient开发 之 项目结构介绍

    上门洗车APP --- Androidclient开发 之 项目结构介绍 前言 尽管公司项目较紧,但还是抽空给大家继续更新. o_O"~ 欢迎大家的关注,非常高兴和大家共同学习.前面给大家分 ...

  3. 【Android UI】自定义带按钮的标题栏

    自定义标题栏在很多的android app中很常见,可以说是一种很有用的UI设计方法.自 己也本着学习的态度,经过一番各种坑,终于实现了,现总结如下: 一:大致流程 1.      对指定的andro ...

  4. 【Android UI设计与开发】8.顶部标题栏(一)ActionBar 奥义·详解

    一.ActionBar介绍 在Android 3.0中除了我们重点讲解的Fragment外,Action Bar也是一个非常重要的交互元素,Action Bar取代了传统的tittle bar和men ...

  5. 【Android UI设计与开发】8.顶部标题栏(一)ActionBar 奥义·详解

    一.ActionBar介绍 在Android 3.0中除了我们重点讲解的Fragment外,Action Bar也是一个非常重要的交互元素,Action Bar取代了传统的tittle bar和men ...

  6. UWP中实现自定义标题栏

    UWP中实现自定义标题栏 0x00 起因 在UWP开发中,有时候我们希望实现自定义标题栏,例如在标题栏中加入搜索框.按钮之类的控件.搜了下资料居然在一个日文网站找到了一篇介绍这个主题的文章: http ...

  7. Android中通过ActionBar为标题栏添加搜索以及分享视窗

    在Android3.0之后,Google对UI导航设计上进行了一系列的改革,其中有一个非常好用的新功能就是引入的ActionBar,他用于取代3.0之前的标题栏,并提供更为丰富的导航效果.Action ...

  8. 【Win10 应用开发】自定义应用标题栏

    Win 10 app对窗口标题栏的自定义包括两个层面:一是只定义标题中各部分的颜色,如标题栏上文本的颜色.三个系统按钮(最大化,最小化,关闭)的背景颜色等:另一层是把窗口的可视区域直接扩展到标题栏上, ...

  9. WPF 自定义标题栏 自定义菜单栏

    自定义标题栏 自定义列表,可以直接修改WPF中的ListBox模板,也用这样类似的效果.但是ListBox是不能设置默认选中状态的. 而我们需要一些复杂的UI效果,还是直接自定义控件来的快 GitHu ...

随机推荐

  1. iOS 设置状态栏的背景颜色

    设置状态栏的背景颜色 - (void)setStatusBarBackgroundColor:(UIColor *)color { UIView *statusBar = [[[UIApplicati ...

  2. ios 提取html 字符串中的img 的地址(图片地址)

    本文原文地址 http://www.cnblogs.com/qianLL/p/6082287.html 有时候 后台返回的是一串html'字符串 我们需要把里面的图片地址提取出来  这个关键就是一个正 ...

  3. 【代码笔记】iOS-图文混排(HBLabelDemo)

    一,效果图. 二,工程图. 三,代码. ViewController.h #import <UIKit/UIKit.h> @interface ViewController : UIVie ...

  4. 数据结构->直接插入排序

    数据结构->直接插入排序 实现效果 从小到大排序 算法原理 有一个已经有序的数据序列,要求在这个已经排好的数据序列中插入一个数,但要求插入后此数据序列仍然有序. 算法步骤 从第一个元素开始,该元 ...

  5. webapp开发调试环境--weinre配置

    用谷歌调试工具中的手机模拟器模拟手机进行webapp的开发,与真机上的效果还是有些偏差,opera手机模拟器的效果亦不佳.有时在pc上开发出来的webapp效果良好,在部分真机上就出现了偏差,这时候就 ...

  6. MySQL ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)的真正原因

    在博客Linux mysql 5.6: ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: N ...

  7. Linux命令学习总结: file命令

    命令简介: 该命令用来识别文件类型,也可用来辨别一些文件的编码格式.它是通过查看文件的头部信息来获取文件类型,而不是像Windows通过扩展名来确定文件类型的. 执行权限 :All User 指令所在 ...

  8. hive load数据为null

    建表语句: CREATE EXTERNAL TABLE IF NOT EXISTS student2 > (sno INT,sname STRING,age INT,sex STRING) &g ...

  9. truncate 、delete与drop区别

    原博文地址:http://www.cnblogs.com/8765h/archive/2011/11/25/2374167.html 相同点: 1.truncate和不带where子句的delete. ...

  10. 【SQL篇章--DATABASE/EVENTS】

    [SQL篇章][SQL语句梳理 :--基于MySQL5.6][已梳理:DATABASE/EVENTS][会坚持完善]   目录: 1. Data Definition Statements: 1.1 ...