背水一战 Windows 10 (113) - 锁屏: 将 Application 的 Badge 通知和 Tile 通知发送到锁屏, 将 secondary tile 的 Badge 通知和 Tile 通知发送到锁屏
作者:webabcd
介绍
背水一战 Windows 10 之 锁屏
- 将 Application 的 Badge 通知和 Tile 通知发送到锁屏
- 将 secondary tile 的 Badge 通知和 Tile 通知发送到锁屏
示例
1、演示如何将 Application 的 Badge 通知和 Tile 通知发送到锁屏
LockScreen/ApplicationNotification.xaml
<Page
x:Class="Windows10.LockScreen.ApplicationNotification"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Windows10.LockScreen"
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"> <Button Name="btnBadgeNotification" Content="发送 Application 的 Badge 通知" Click="btnBadgeNotification_Click" Margin="5" /> <Button Name="btnTileNotification" Content="发送 Application 的 Tile 通知" Click="btnTileNotification_Click" Margin="5" /> </StackPanel>
</Grid>
</Page>
LockScreen/ApplicationNotification.xaml.cs
/*
* 演示如何将 Application 的 Badge 通知和 Tile 通知发送到锁屏
*
*
* 注:
* 1、需要在 Package.appxmanifest 中配置好是否支持锁屏徽章和文本,以及要配置好徽章图标。类似如下:
* <LockScreen Notification="badgeAndTileText" BadgeLogo="Assets\LockScreenLogo.png" />
* 2、在 app 安装好后,去“设置”->“个性化”->“锁屏界面”中做如下选择
* 在“选择要显示详细状态的应用”中选择你的 app,则对此 app 发送 tile 通知后,此 tile 通知的文本就会显示在锁屏
* 在“选择要显示快速状态的应用”中选择你的 app,则对此 app 发送 badge 通知后,此 badge 通知的图标就会显示在锁屏
*/ using System;
using Windows.Data.Xml.Dom;
using Windows.UI.Notifications;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls; namespace Windows10.LockScreen
{
public sealed partial class ApplicationNotification : Page
{
public ApplicationNotification()
{
this.InitializeComponent();
} // 发送 Application 的 Badge 通知
private void btnBadgeNotification_Click(object sender, RoutedEventArgs e)
{
// 用于描述 badge 通知的 xml 字符串(数字在 1 - 99 之间,如果大于 99 则会显示 99+ ,如果是 0 则会移除 badge,如果小于 0 则无效)
string badgeXml = "<badge value='3'/>"; // 将 xml 字符串转换为 Windows.Data.Xml.Dom.XmlDocument 对象
XmlDocument badgeDoc = new XmlDocument();
badgeDoc.LoadXml(badgeXml); // 实例化 BadgeNotification 对象
BadgeNotification badgeNotification = new BadgeNotification(badgeDoc); // 将指定的 BadgeNotification 对象更新到 application
BadgeUpdater badgeUpdater = BadgeUpdateManager.CreateBadgeUpdaterForApplication();
badgeUpdater.Update(badgeNotification);
} // 发送 Application 的 Tile 通知
private void btnTileNotification_Click(object sender, RoutedEventArgs e)
{
/*
* 这里有几个要特别注意的地方:
* 1、锁屏只能显示 tile 的文本,不能显示 tile 的图片之类的
* 2、锁屏只会显示 tile 的 TileWide 模板的文本
* 3、要想在锁屏显示文本,则 tile 的 text 必须要有 id 属性并指定一个整型值
* 4、锁屏文本会按照 tile 的 text 的 id 的大小按顺序显示,如果 id 值一样则只显示后面的
* 5、tile 上的文本显示规则与其 text 的 id 无关(只有锁屏文本才有关系)
*/ // 用于描述 tile 通知的 xml 字符串
string tileXml = $@"
<tile>
<visual>
<binding template='TileSmall'>
<text id='1'>Small 1(小){DateTime.Now.ToString("HH:mm:ss")}</text>
</binding>
<binding template='TileMedium'>
<text id=''>Medium (中){DateTime.Now.ToString("HH:mm:ss")}</text>
</binding>
<binding template='TileWide'>
<text id=''>Wide (宽){DateTime.Now.ToString("HH:mm:ss")}</text>
<text id=''>Wide (宽){DateTime.Now.ToString("HH:mm:ss")}</text>
<text id=''>Wide (宽){DateTime.Now.ToString("HH:mm:ss")}</text>
</binding>
<binding template='TileLarge'>
<text id=''>Large (大){DateTime.Now.ToString("HH:mm:ss")}</text>
</binding>
</visual>
</tile>"; /*
* 如果需要锁屏显示的 tile 内容与 TileWide 显示的 tile 内容不一样的话,可以像下面这样写
* 设置 TileWide 所属 binding 的 hint-lockDetailedStatus1 属性和 hint-lockDetailedStatus2 属性和 hint-lockDetailedStatus3 属性
*/
string tileXml2 = $@"
<tile>
<visual>
<binding template='TileSmall'>
<text>Small 1(小){DateTime.Now.ToString("HH:mm:ss")}</text>
</binding>
<binding template='TileMedium'>
<text>Medium (中){DateTime.Now.ToString("HH:mm:ss")}</text>
</binding>
<binding template='TileWide'
hint-lockDetailedStatus1='hint-lockDetailedStatus1'
hint-lockDetailedStatus2='hint-lockDetailedStatus2'
hint-lockDetailedStatus3='hint-lockDetailedStatus3'>
<text>Wide (宽){DateTime.Now.ToString("HH:mm:ss")}</text>
<text>Wide (宽){DateTime.Now.ToString("HH:mm:ss")}</text>
<text>Wide (宽){DateTime.Now.ToString("HH:mm:ss")}</text>
</binding>
<binding template='TileLarge'>
<text>Large (大){DateTime.Now.ToString("HH:mm:ss")}</text>
</binding>
</visual>
</tile>"; // 将 xml 字符串转换为 Windows.Data.Xml.Dom.XmlDocument 对象
XmlDocument tileDoc = new XmlDocument();
tileDoc.LoadXml(tileXml); // 实例化 TileNotification 对象
TileNotification tileNotification = new TileNotification(tileDoc); // 将指定的 TileNotification 对象更新到 application tile
TileUpdater tileUpdater = TileUpdateManager.CreateTileUpdaterForApplication();
tileUpdater.Update(tileNotification);
}
}
}
2、演示如何将 secondary tile 的 Badge 通知和 Tile 通知发送到锁屏
LockScreen/SecondaryTileNotification.xaml
<Page
x:Class="Windows10.LockScreen.SecondaryTileNotification"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Windows10.LockScreen"
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" /> <Button Name="btnBadgeNotification" Content="发送 secondary tile 的 Badge 通知" Click="btnBadgeNotification_Click" Margin="5" /> <Button Name="btnTileNotification" Content="发送 secondary tile 的 Tile 通知" Click="btnTileNotification_Click" Margin="5" /> </StackPanel>
</Grid>
</Page>
LockScreen/SecondaryTileNotification.xaml.cs
/*
* 演示如何将 secondary tile 的 Badge 通知和 Tile 通知发送到锁屏
*
*
* SecondaryTile - secondary tile
* LockScreenDisplayBadgeAndTileText - 是否允许此 secondary tile 在锁屏上显示徽章和文本
* LockScreenBadgeLogo - 锁屏上徽章图标的地址
*
* 注:
* 在 app 安装好后,先要将 secondary tile 固定到开始屏幕,然后去“设置”->“个性化”->“锁屏界面”中做如下选择
* 在“选择要显示详细状态的应用”中选择你的 secondary tile,则对此 secondary tile 发送 tile 通知后,此 tile 通知的文本就会显示在锁屏
* 在“选择要显示快速状态的应用”中选择你的 secondary tile,则对此 secondary tile 发送 badge 通知后,此 badge 通知的图标就会显示在锁屏
*/ using System;
using Windows.Data.Xml.Dom;
using Windows.UI.Notifications;
using Windows.UI.StartScreen;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Navigation; namespace Windows10.LockScreen
{
public sealed partial class SecondaryTileNotification : Page
{
private const string TILEID = "tile_lockscreen"; public SecondaryTileNotification()
{
this.InitializeComponent();
} // 在开始屏幕固定一个 secondary tile 磁贴
protected async override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e); Uri square150x150Logo = new Uri("ms-appx:///Assets/Square150x150Logo.png");
Uri wide310x150Logo = new Uri("ms-appx:///Assets/Wide310x150Logo.png");
Uri square310x310Logo = new Uri("ms-appx:///Assets/Square310x310Logo.png");
SecondaryTile secondaryTile = new SecondaryTile(TILEID, "我的 secondary tile", "arguments", square150x150Logo, TileSize.Wide310x150);
secondaryTile.VisualElements.Wide310x150Logo = wide310x150Logo;
secondaryTile.VisualElements.Square310x310Logo = square310x310Logo; // 允许此 secondary tile 在锁屏上显示徽章和文本
secondaryTile.LockScreenDisplayBadgeAndTileText = true;
// 此 secondary tile 在锁屏上显示徽章时的图标
secondaryTile.LockScreenBadgeLogo = new Uri("ms-appx:///Assets/LockScreenLogo.png"); try
{
bool isPinned = await secondaryTile.RequestCreateAsync();
lblMsg.Text = isPinned ? "固定成功" : "固定失败";
}
catch (Exception ex)
{
lblMsg.Text = "固定失败: " + ex.ToString();
}
} // 发送 secondary tile 的 Badge 通知
private void btnBadgeNotification_Click(object sender, RoutedEventArgs e)
{
// 用于描述 badge 通知的 xml 字符串(数字在 1 - 99 之间,如果大于 99 则会显示 99+ ,如果是 0 则会移除 badge,如果小于 0 则无效)
string badgeXml = "<badge value='3'/>"; // 将 xml 字符串转换为 Windows.Data.Xml.Dom.XmlDocument 对象
XmlDocument badgeDoc = new XmlDocument();
badgeDoc.LoadXml(badgeXml); // 实例化 BadgeNotification 对象
BadgeNotification badgeNotification = new BadgeNotification(badgeDoc); // 将指定的 BadgeNotification 对象更新到指定的 secondary tile 磁贴
BadgeUpdater badgeUpdater = BadgeUpdateManager.CreateBadgeUpdaterForSecondaryTile(TILEID);
badgeUpdater.Update(badgeNotification);
} // 发送 secondary tile 的 Tile 通知
private void btnTileNotification_Click(object sender, RoutedEventArgs e)
{
/*
* 这里有几个要特别注意的地方:
* 1、锁屏只能显示 tile 的文本,不能显示 tile 的图片之类的
* 2、锁屏只会显示 tile 的 TileWide 模板的文本
* 3、要想在锁屏显示文本,则 tile 的 text 必须要有 id 属性并指定一个整型值
* 4、锁屏文本会按照 tile 的 text 的 id 的大小按顺序显示,如果 id 值一样则只显示后面的
* 5、tile 上的文本显示规则与其 text 的 id 无关(只有锁屏文本才有关系)
*/ // 用于描述 tile 通知的 xml 字符串
string tileXml = $@"
<tile>
<visual>
<binding template='TileSmall'>
<text>Small 1(小){DateTime.Now.ToString("HH:mm:ss")}</text>
</binding>
<binding template='TileMedium'>
<text>Medium (中){DateTime.Now.ToString("HH:mm:ss")}</text>
</binding>
<binding template='TileWide'>
<text id=''>Wide (宽){DateTime.Now.ToString("HH:mm:ss")}</text>
<text id=''>Wide (宽){DateTime.Now.ToString("HH:mm:ss")}</text>
<text id=''>Wide (宽){DateTime.Now.ToString("HH:mm:ss")}</text>
</binding>
<binding template='TileLarge'>
<text>Large (大){DateTime.Now.ToString("HH:mm:ss")}</text>
</binding>
</visual>
</tile>"; /*
* 如果需要锁屏显示的 tile 内容与 TileWide 显示的 tile 内容不一样的话,可以像下面这样写
* 设置 TileWide 所属 binding 的 hint-lockDetailedStatus1 属性和 hint-lockDetailedStatus2 属性和 hint-lockDetailedStatus3 属性
*/
string tileXml2 = $@"
<tile>
<visual>
<binding template='TileSmall'>
<text>Small 1(小){DateTime.Now.ToString("HH:mm:ss")}</text>
</binding>
<binding template='TileMedium'>
<text>Medium (中){DateTime.Now.ToString("HH:mm:ss")}</text>
</binding>
<binding template='TileWide'
hint-lockDetailedStatus1='hint-lockDetailedStatus1'
hint-lockDetailedStatus2='hint-lockDetailedStatus2'
hint-lockDetailedStatus3='hint-lockDetailedStatus3'>
<text>Wide (宽){DateTime.Now.ToString("HH:mm:ss")}</text>
<text>Wide (宽){DateTime.Now.ToString("HH:mm:ss")}</text>
<text>Wide (宽){DateTime.Now.ToString("HH:mm:ss")}</text>
</binding>
<binding template='TileLarge'>
<text>Large (大){DateTime.Now.ToString("HH:mm:ss")}</text>
</binding>
</visual>
</tile>"; // 将 xml 字符串转换为 Windows.Data.Xml.Dom.XmlDocument 对象
XmlDocument tileDoc = new XmlDocument();
tileDoc.LoadXml(tileXml); // 实例化 TileNotification 对象
TileNotification tileNotification = new TileNotification(tileDoc); // 将指定的 TileNotification 对象更新到 secondary tile
TileUpdater tileUpdater = TileUpdateManager.CreateTileUpdaterForSecondaryTile(TILEID);
tileUpdater.Update(tileNotification);
}
}
}
OK
[源码下载]
背水一战 Windows 10 (113) - 锁屏: 将 Application 的 Badge 通知和 Tile 通知发送到锁屏, 将 secondary tile 的 Badge 通知和 Tile 通知发送到锁屏的更多相关文章
- 背水一战 Windows 10 (3) - UI: 窗口全屏, 窗口尺寸
[源码下载] 背水一战 Windows 10 (3) - UI: 窗口全屏, 窗口尺寸 作者:webabcd 介绍背水一战 Windows 10 之 UI 窗口全屏 窗口尺寸 示例1.窗口全屏UI/F ...
- 背水一战 Windows 10 (112) - 通知(Badge): application 的 badge 通知, secondary 的 badge 通知, 轮询服务端以更新 badge 通知
[源码下载] 背水一战 Windows 10 (112) - 通知(Badge): application 的 badge 通知, secondary 的 badge 通知, 轮询服务端以更新 bad ...
- 背水一战 Windows 10 (108) - 通知(Tile): application tile 基础, secondary tile 基础
[源码下载] 背水一战 Windows 10 (108) - 通知(Tile): application tile 基础, secondary tile 基础 作者:webabcd 介绍背水一战 Wi ...
- 背水一战 Windows 10 (91) - 文件系统: Application Data 中的文件操作, Application Data 中的“设置”操作, 通过 uri 引用 Application Data 中的媒体
[源码下载] 背水一战 Windows 10 (91) - 文件系统: Application Data 中的文件操作, Application Data 中的“设置”操作, 通过 uri 引用 Ap ...
- 背水一战 Windows 10 (121) - 后台任务: 推送通知
[源码下载] 背水一战 Windows 10 (121) - 后台任务: 推送通知 作者:webabcd 介绍背水一战 Windows 10 之 后台任务 推送通知 示例演示如何接收推送通知/WebA ...
- 背水一战 Windows 10 (2) - UI: 概述, 启动屏幕, 屏幕方向
[源码下载] 背水一战 Windows 10 (2) - UI: 概述, 启动屏幕, 屏幕方向 作者:webabcd 介绍背水一战 Windows 10 之 UI UI 设计概述 启动屏幕(闪屏) 屏 ...
- 背水一战 Windows 10 (114) - 后台任务: 后台任务的 Demo(与 app 不同进程), 后台任务的 Demo(与 app 相同进程)
[源码下载] 背水一战 Windows 10 (114) - 后台任务: 后台任务的 Demo(与 app 不同进程), 后台任务的 Demo(与 app 相同进程) 作者:webabcd 介绍背水一 ...
- 背水一战 Windows 10 (66) - 控件(WebView): 监听和处理 WebView 的事件
[源码下载] 背水一战 Windows 10 (66) - 控件(WebView): 监听和处理 WebView 的事件 作者:webabcd 介绍背水一战 Windows 10 之 控件(WebVi ...
- 背水一战 Windows 10 (57) - 控件(集合类): ListViewBase - 增量加载, 分步绘制
[源码下载] 背水一战 Windows 10 (57) - 控件(集合类): ListViewBase - 增量加载, 分步绘制 作者:webabcd 介绍背水一战 Windows 10 之 控件(集 ...
随机推荐
- L2-025 分而治之(并查集)
分而治之,各个击破是兵家常用的策略之一.在战争中,我们希望首先攻下敌方的部分城市,使其剩余的城市变成孤立无援,然后再分头各个击破.为此参谋部提供了若干打击方案.本题就请你编写程序,判断每个方案的可行性 ...
- Spring Boot HikariCP 一 ——集成多数据源
其实这里介绍的东西主要是参考的另外一篇文章,数据库读写分离的. 参考文章就把链接贴出来,里面有那位的代码,简单明了https://gitee.com/comven/dynamic-datasource ...
- centos7 安装部署jenkins
一.简介 jenkins是一个Java开发的开源持续集成工具,广泛用于项目开发,具有自动化构建.测试和部署等功能,它的运行需要Java环境. 二.搭建环境准备:# cat /etc/redhat-re ...
- SSH Config 那些你所知道和不知道的事 (转)
原文地址:https://deepzz.com/post/how-to-setup-ssh-config.html SSH(Secure Shell)是什么?是一项创建在应用层和传输层基础上的安全协议 ...
- redis常用服务安装部署
常用服务安装部署 学了前面的Linux基础,想必童鞋们是不是更感兴趣了?接下来就学习常用服务部署吧! 安装环境: centos7 + vmware + xshell 即将登场的是: mysql(m ...
- handsontable 常用 配置项 笔记
import React, { Component } from 'react'; import HotTable from 'react-handsontable'; import Handsont ...
- [转] spring framework体系结构及内部各模块jar之间的maven依赖关系
很多人都在用spring开发java项目,但是配置maven依赖的时候并不能明确要配置哪些spring的jar,经常是胡乱添加一堆,编译或运行报错就继续配置jar依赖,导致spring依赖混乱,甚至下 ...
- dskinlite(uieasy mfc界面库)使用记录2:绘制动态元素(按钮控件绘制元素动态控制,改变图片和文字)
效果图:这4个分别是按钮按下后4种状态的效果 第88行是显示默认的按钮文字,没有id,SetWindowText改的就是它了 第87行是左边的图片,id是ico,可以通过程序控制 第89行是蓝色的文字 ...
- 设计模式学习心得<装饰器模式 Decorator>
装饰器模式(Decorator Pattern)允许向一个现有的对象添加新的功能,同时又不改变其结构.这种类型的设计模式属于结构型模式,它是作为现有的类的一个包装. 这种模式创建了一个装饰类,用来包装 ...
- 数据库database
1.创建数据库:create datebase financials create database if not exists financilas 2.查看数据库(所有): show da ...