UWP 有关应用标题栏 TitleBar 的文章比较多,但介绍 StatusBar 的却没几篇,在这里随便写写。状态栏 StatusBar 用法比较简单,花点心思稍微设计一下,对应用会是个很好的点缀。

  说明一下,当应用运行在 PC 上时我们叫 TitleBar ,运行在 Mobile 上时我们叫 StatusBar ,这是两个不同的玩意儿。

  

  在使用 StatusBar 之前,你需要在项目的引用里添加 Windows Mobile Extensions for the UWP ,并且引用 Windows.UI.ViewManagement 命名空间。

  StatusBar 类中一共有三个方法。分别为一个静态方法 GetForCurrentView() ,用于取得当前 StatusBar 实例。两个异步方法 HideAsync()ShowAsync() ,分别用来显示与隐藏 StatusBar 。

  五个属性。两个可空的 Color 类型 BackgroundColorForegroundColor ,分别用来设置背景色与前景色。 double 类型的 BackgroundOpacity ,取值范围为 0-1 ,用来设置 StatusBar 透明度。两个只读属性,返回 Rect 矩形的 OccludedRect 和 StatusBarProgressIndicator 类型的 ProgressIndicator ,ProgressIndicator 属性不太了解。

  两个事件。HidingShowing

  下面给出一个简单的示例(GitHub : https://github.com/ZhangGaoxing/uwp-demo/tree/master/StatusBarDemo

  

  MainPage.xaml

<Page
x:Class="StatusBarDemo.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:StatusBarDemo"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"> <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions> <TextBlock Text="Status Bar Demo" FontSize="35" Margin="15" /> <StackPanel Grid.Row="1" Margin="15">
<TextBlock Text="Show or hide status bar" />
<RadioButton Name="Show" GroupName="ShowOrHide" IsChecked="True" Checked="RadioButton_Checked">Show</RadioButton>
<RadioButton Name="Hide" GroupName="ShowOrHide" Checked="RadioButton_Checked">Hide</RadioButton>
</StackPanel> <StackPanel Grid.Row="2" Margin="15">
<TextBlock Text="Change status bar background color" />
<RadioButton Name="Black" GroupName="Color" IsChecked="True" Checked="Color_Checked">Black</RadioButton>
<RadioButton Name="White" GroupName="Color" Checked="Color_Checked">White</RadioButton>
<RadioButton Name="Accent" GroupName="Color" Checked="Color_Checked">System Accent Color</RadioButton>
</StackPanel> <StackPanel Grid.Row="3" Margin="15">
<TextBlock Text="Change status bar background opacity" />
<Slider Name="Opacity" Minimum="0" Maximum="10" Value="10" ValueChanged="Opacity_ValueChanged" />
</StackPanel> </Grid>
</Page>

  MainPage.xaml.cs

using System;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.ViewManagement;
using Windows.Foundation.Metadata;
using Windows.UI;
using Windows.UI.Xaml.Media; namespace StatusBarDemo
{
public sealed partial class MainPage : Page
{
StatusBar statusBar;
// 获取系统当前颜色
SolidColorBrush accentColor = (SolidColorBrush)Application.Current.Resources["SystemControlBackgroundAccentBrush"]; public MainPage()
{
// 判断是否存在 StatusBar
if (ApiInformation.IsTypePresent("Windows.UI.ViewManagement.StatusBar"))
{
statusBar = StatusBar.GetForCurrentView();
}
else
{
Application.Current.Exit();
} this.InitializeComponent();
} // 显示,隐藏
private async void RadioButton_Checked(object sender, RoutedEventArgs e)
{
RadioButton r = sender as RadioButton; if (r.Name == "Show")
{
await statusBar.ShowAsync();
}
else
{
await statusBar.HideAsync();
}
} // 颜色
private void Color_Checked(object sender, RoutedEventArgs e)
{
RadioButton r = sender as RadioButton; if (r.Name == "Black")
{
statusBar.BackgroundColor = Colors.Black;
statusBar.ForegroundColor = Colors.White;
}
else if(r.Name == "White")
{
statusBar.BackgroundColor = Colors.White;
statusBar.ForegroundColor = Colors.Black;
statusBar.BackgroundOpacity = ;
}
else
{
statusBar.BackgroundColor = accentColor.Color;
statusBar.ForegroundColor = Colors.Black;
statusBar.BackgroundOpacity = ;
}
} // 透明度
private void Opacity_ValueChanged(object sender, Windows.UI.Xaml.Controls.Primitives.RangeBaseValueChangedEventArgs e)
{
statusBar.BackgroundOpacity = Opacity.Value / ;
}
}
}

张高兴的 UWP 开发笔记:手机状态栏 StatusBar的更多相关文章

  1. 张高兴的 UWP 开发笔记:横向 ListView

    ListView 默认的排列方向是纵向 ( Orientation="Vertical" ) ,但如果我们需要横向显示的 ListView 怎么办? Blend for Visua ...

  2. 张高兴的 UWP 开发笔记:用 Thumb 控件仿制一个可拖动 Button

    在 WPF 上可用的控件拖动方法在 UWP 上大多没用,那干脆用 Thumb 仿制一个吧. 关于 Thumb 控件的教程也不多,毕竟在 WPF 控件拖动有很多种方法, Thumb 就显得很鸡肋了.下面 ...

  3. 张高兴的 UWP 开发笔记:应用内启动应用 (UWP Launch UWP)

    需求:在 A 应用内启动 B 应用,如果 B 应用未安装则跳转应用商店搜索. 启动方式使用 Uri 启动,本文使用尽可能简单,并且能拿来直接用的代码.不涉及启动后的应用数据交互,如需深入了解,请戳 M ...

  4. 张高兴的 UWP 开发笔记:汉堡菜单进阶

    不同于Windows 8应用,Windows 10引入了"汉堡菜单"这一导航模式.说具体点,就拿官方的天气应用来说,左上角三条横杠的图标外加一个SplitView控件组成的这一导航 ...

  5. 张高兴的 UWP 开发笔记:定制 ContentDialog 样式

    我需要一个背景透明的 ContentDialog,像下图一样.如何定制?写了一个简单的示例(https://github.com/ZhangGaoxing/uwp-demo/tree/master/C ...

  6. UWP开发笔记——嵌套式页面的实现

    绪论 UWP开发中,Page是最常用的Control之一,通常情况下,在开发的application中,每一个页面就是一个Page.有时候,为了开发整合度更高,UI表现更为一致的UI,开发者需要把UI ...

  7. [UWP开发]处理手机后退事件

    众所周知,uwp程序是一套代码,可以run在不同的平台上.但是不同的设备肯定有其独特之处,所以针对这些独特之处,必须用“独特的代码”来处理. 所以微软提供了一系列的拓展类库来实现这种特殊处理. 如上图 ...

  8. UWP开发砸手机系列(一)—— Accessibility

    因为今天讨论的内容不属于入门系列,所以我把标题都改了.这个啥Accessibility说实话属于及其蛋疼的内容,即如何让视力有障碍的人也能通过声音来使用触屏手机……也许你这辈子也不会接触,但如果有一天 ...

  9. UWP开发砸手机系列(二)—— “讲述人”识别自定义控件Command

    上一篇我们提到如何让“讲述人”读出自定义的CanReadGrid,但“讲述人”仍然无法识别CanReadGrid上绑定的Command.XAML代码如下: <StackPanel> < ...

随机推荐

  1. 学号:201521123116 《java程序设计》第七周学习总结

    1. 本周学习总结 2. 书面作业 Q1 ArrayList代码分析 1.1 解释ArrayList的contains源代码ArrayList的contains源代码 1.2 解释E remove(i ...

  2. 201521123063 《Java程序设计》 第12周学习总结

    1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结多流与文件相关内容. 读操作 (1)读取控制台输入: BufferedReader br = new BufferedReader( ...

  3. Hibernate哪点事?

    1.为什么在Hibernate的实体类中要提供一个无参数的构造器这一点非常重要?每个Hibernate实体类必须包含一个 无参数的构造器, 这是因为Hibernate框架要使用Reflection A ...

  4. 浅谈IT技术女转战微电商初体验

    今天闲来无事,突然想翻看下之前写的技术博客,很是意外,居然那么多阅读量,于是想想做微商也有一段时间了,决定写写初入微商的初体验. 先自我介绍一下,本人是一名理工女,做IT行业的,这个行业也许有人了解, ...

  5. 关于linux下的文件权限

    在ls指令加 -l 参数能看到文件权限 就像这样: drwxrwxr-x 2 asml users 4096 Jul 24 02:45 desktop 第一个d表示这是个目录,若为"-&qu ...

  6. JavaScript中的ASCII碼轉換成字符的兩種方法

    方法一:轉義字符 \xxx:用十六進制的ASCII碼值轉換成字符. 方法二:String方法 String.fromCharCode(value): //用十進制的ASCII碼值轉換成字符. 舉例:結 ...

  7. 双击打开Jar文件

    最近发现个诡异的问题,java环境变量明明配好了.但是双击xx.jar文件,就是不能直接打开运行. 先想到了第一个解决办法: 运行cmd.exe,cd到jar目录,执行 javaw -jar xxx. ...

  8. Bootstrap对齐方式

    <p class="text-left">我居左</p> <p class="text-center">我居中</p& ...

  9. 个人从源码理解angular项目在JIT模式下的启动过程

    通常一个angular项目会有一个个模块(Module)来管理各自的业务,并且必须有一个根模块(AppModule)作为应用的入口模块,整个应用都围绕AppModule展开.可以这么说,AppModu ...

  10. C++Builder中MessageBox的基本用法

    C++Builder中MessageBox的基本用法 返回值:IDYES=Application->MessageBox("","",MBYESNO) i ...