[源码下载]

背水一战 Windows 10 (110) - 通知(Tile): secondary tile 模板之基础, secondary tile 模板之文本

作者:webabcd

介绍
背水一战 Windows 10 之 通知(Tile)

  • secondary tile 模板之基础
  • secondary tile 模板之文本

示例
1、本例用于演示 tile 显示模板的基础
Notification/Tile/TemplateBasic.xaml

<Page
x:Class="Windows10.Notification.Tile.TemplateBasic"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Windows10.Notification.Tile"
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="btnSample1" Content="为不同规格的磁贴指定不同的显示内容" Click="btnSample1_Click" Margin="5" /> <Button Name="btnSample2" Content="在 binding 节点指定磁贴左下角的名称显示和右下角的图标显示" Click="btnSample2_Click" Margin="5" /> <Button Name="btnSample3" Content="在 visual 节点指定磁贴左下角的名称显示和右下角的图标显示" Click="btnSample3_Click" Margin="5" /> </StackPanel>
</Grid>
</Page>

Notification/Tile/TemplateBasic.xaml.cs

/*
* 本例用于演示 tile 显示模板的基础
*
*
* tile - 磁贴元素
* visual - 可视元素
* branding - 如何显示磁贴左下角的名称和右下角的图标
* none - 不参与(默认值)
* logo - 显示右下角的图标
* name - 显示左下角的名称
* nameAndLogo - 显示左下角的名称和右下角的图标
* displayName - 指定显示在磁贴左下角的名称(不指定且设置为显示时,则显示的是 SecondaryTile 对象的 DisplayName)
* binding - 绑定元素
* template - 指定 tile 的规格(小,中,宽,大)
* branding - 如何显示磁贴左下角的名称和右下角的图标
* none - 不参与(默认值)
* logo - 显示右下角的图标
* name - 显示左下角的名称
* nameAndLogo - 显示左下角的名称和右下角的图标
* displayName - 指定显示在磁贴左下角的名称(不指定且设置为显示时,则显示的是 SecondaryTile 对象的 DisplayName)
*/ 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.Notification.Tile
{
public sealed partial class TemplateBasic : Page
{
private const string TILEID = "tile_template_basic"; public TemplateBasic()
{
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, "name", "arguments", square150x150Logo, TileSize.Wide310x150);
secondaryTile.VisualElements.Wide310x150Logo = wide310x150Logo;
secondaryTile.VisualElements.Square310x310Logo = square310x310Logo; try
{
bool isPinned = await secondaryTile.RequestCreateAsync();
lblMsg.Text = isPinned ? "固定成功" : "固定失败";
}
catch (Exception ex)
{
lblMsg.Text = "固定失败: " + ex.ToString();
}
} // 为不同规格的磁贴指定不同的显示内容
private void btnSample1_Click(object sender, RoutedEventArgs e)
{
string tileXml = $@"
<tile>
<visual>
<binding template='TileSmall'>
<text>Small(小){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>Wide(宽){DateTime.Now.ToString("HH:mm:ss")}</text>
</binding>
<binding template='TileLarge'>
<text>Large(大){DateTime.Now.ToString("HH:mm:ss")}</text>
</binding>
</visual>
</tile>"; UpdateTileNotification(tileXml);
} // 在 binding 节点指定磁贴左下角的名称显示和右下角的图标显示
private void btnSample2_Click(object sender, RoutedEventArgs e)
{
string tileXml = $@"
<tile>
<visual>
<binding template='TileWide' branding='nameAndLogo' displayName='name 2'>
<text>Wide(宽){DateTime.Now.ToString("HH:mm:ss")}</text>
</binding>
<binding template='TileLarge' branding='nameAndLogo' displayName='name 3'>
<text>Large(大){DateTime.Now.ToString("HH:mm:ss")}</text>
</binding>
</visual>
</tile>"; UpdateTileNotification(tileXml);
} // 在 visual 节点指定磁贴左下角的名称显示和右下角的图标显示
private void btnSample3_Click(object sender, RoutedEventArgs e)
{
string tileXml = $@"
<tile>
<visual branding='nameAndLogo' displayName='name 4'>
<binding template='TileWide'>
<text>Wide(宽){DateTime.Now.ToString("HH:mm:ss")}</text>
</binding>
</visual>
</tile>"; UpdateTileNotification(tileXml);
} private void UpdateTileNotification(string tileXml)
{
XmlDocument tileDoc = new XmlDocument();
tileDoc.LoadXml(tileXml); TileNotification tileNotification = new TileNotification(tileDoc); TileUpdater tileUpdater = TileUpdateManager.CreateTileUpdaterForSecondaryTile(TILEID);
tileUpdater.Update(tileNotification);
}
}
}

2、本例用于演示 tile 显示模板的文本相关的知识点
Notification/Tile/TemplateText.xaml

<Page
x:Class="Windows10.Notification.Tile.TemplateText"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Windows10.Notification.Tile"
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="btnSample1" Content="文本的样式" Click="btnSample1_Click" Margin="5" /> <Button Name="btnSample2" Content="水平对齐方式和文本换行" Click="btnSample2_Click" Margin="5" /> <Button Name="btnSample3" Content="垂直对齐方式" Click="btnSample3_Click" Margin="5" /> </StackPanel>
</Grid>
</Page>

Notification/Tile/TemplateText.xaml.cs

/*
* 本例用于演示 tile 显示模板的文本相关的知识点
*
*
* tile - 磁贴元素
* visual - 可视元素
* binding - 绑定元素
* hint-textStacking - 垂直对齐方式
* top - 顶部对齐(默认值)
* center - 垂直居中
* bottom - 底部对齐
* text - 文本元素
* hint-style - 文本样式
* hint-align - 水平对齐方式
* left - 居左(默认值)
* center - 居中
* right - 居右
* hint-wrap - 是否可换行(默认值为 false)
* hint-minLines - 最小行数
* hint-maxLines - 最大行数
*
*
*
*
*
* 关于 hint-style 的详细说明如下
*
* 1、基本样式(epx - effective pixels 有效像素)
* caption: 12epx 常规
* body: 15epx 常规
* base: 15epx 半粗
* subtitle: 20epx 常规
* title: 24epx 半细
* subheader: 34epx 细体
* header: 46epx 细体
*
* 2、基本样式的 Numeral 变体(减小了行高)
* titleNumeral, subheaderNumeral, headerNumeral
*
* 3、“基本样式”和“基本样式的 Numeral 变体”的 Subtle 变体(透明度 60%)
* captionSubtle, bodySubtle, baseSubtle, subtitleSubtle, titleSubtle, titleNumeralSubtle, subheaderSubtle, subheaderNumeralSubtle, headerSubtle, headerNumeralSubtle
*/ 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.Notification.Tile
{
public sealed partial class TemplateText : Page
{
private const string TILEID = "tile_template_text"; public TemplateText()
{
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, "name", "arguments", square150x150Logo, TileSize.Wide310x150);
secondaryTile.VisualElements.Wide310x150Logo = wide310x150Logo;
secondaryTile.VisualElements.Square310x310Logo = square310x310Logo; try
{
bool isPinned = await secondaryTile.RequestCreateAsync();
lblMsg.Text = isPinned ? "固定成功" : "固定失败";
}
catch (Exception ex)
{
lblMsg.Text = "固定失败: " + ex.ToString();
}
} // 文本的样式
private void btnSample1_Click(object sender, RoutedEventArgs e)
{
string tileXml = $@"
<tile>
<visual>
<binding template='TileWide'>
<text hint-style='base'>base</text>
<text hint-style='baseSubtle'>baseSubtle</text>
<text hint-style='captionSubtle'>captionSubtle</text>
<text hint-style='titleNumeral'>titleNumeral</text>
</binding>
</visual>
</tile>"; UpdateTileNotification(tileXml);
} // 水平对齐方式和文本换行
private void btnSample2_Click(object sender, RoutedEventArgs e)
{
string tileXml = $@"
<tile>
<visual>
<binding template='TileWide'>
<text hint-style='caption' hint-align='center'>hint-align='center'</text>
<text hint-style='caption' hint-wrap='true' hint-minLines='1' hint-maxLines='10'>hint-wrap='true' hint-minLines='1' hint-maxLines='10'</text>
</binding>
</visual>
</tile>"; UpdateTileNotification(tileXml);
} // 垂直对齐方式
private void btnSample3_Click(object sender, RoutedEventArgs e)
{
string tileXml = $@"
<tile>
<visual>
<binding template='TileWide' hint-textStacking='bottom'>
<text hint-style='caption'>caption 1</text>
<text hint-style='caption'>caption 2</text>
</binding>
</visual>
</tile>"; UpdateTileNotification(tileXml);
} private void UpdateTileNotification(string tileXml)
{
XmlDocument tileDoc = new XmlDocument();
tileDoc.LoadXml(tileXml); TileNotification tileNotification = new TileNotification(tileDoc); TileUpdater tileUpdater = TileUpdateManager.CreateTileUpdaterForSecondaryTile(TILEID);
tileUpdater.Update(tileNotification);
}
}
}

OK
[源码下载]

背水一战 Windows 10 (110) - 通知(Tile): secondary tile 模板之基础, secondary tile 模板之文本的更多相关文章

  1. 背水一战 Windows 10 (113) - 锁屏: 将 Application 的 Badge 通知和 Tile 通知发送到锁屏, 将 secondary tile 的 Badge 通知和 Tile 通知发送到锁屏

    [源码下载] 背水一战 Windows 10 (113) - 锁屏: 将 Application 的 Badge 通知和 Tile 通知发送到锁屏, 将 secondary tile 的 Badge ...

  2. 背水一战 Windows 10 (111) - 通知(Tile): secondary tile 模板之图片, secondary tile 模板之分组

    [源码下载] 背水一战 Windows 10 (111) - 通知(Tile): secondary tile 模板之图片, secondary tile 模板之分组 作者:webabcd 介绍背水一 ...

  3. 背水一战 Windows 10 (108) - 通知(Tile): application tile 基础, secondary tile 基础

    [源码下载] 背水一战 Windows 10 (108) - 通知(Tile): application tile 基础, secondary tile 基础 作者:webabcd 介绍背水一战 Wi ...

  4. 背水一战 Windows 10 (109) - 通知(Tile): 按计划显示 tile 通知, 轮询服务端以更新 tile 通知

    [源码下载] 背水一战 Windows 10 (109) - 通知(Tile): 按计划显示 tile 通知, 轮询服务端以更新 tile 通知 作者:webabcd 介绍背水一战 Windows 1 ...

  5. 背水一战 Windows 10 (112) - 通知(Badge): application 的 badge 通知, secondary 的 badge 通知, 轮询服务端以更新 badge 通知

    [源码下载] 背水一战 Windows 10 (112) - 通知(Badge): application 的 badge 通知, secondary 的 badge 通知, 轮询服务端以更新 bad ...

  6. 背水一战 Windows 10 (107) - 通知(Toast): 提示音, 特定场景

    [源码下载] 背水一战 Windows 10 (107) - 通知(Toast): 提示音, 特定场景 作者:webabcd 介绍背水一战 Windows 10 之 通知(Toast) 提示音 特定场 ...

  7. 背水一战 Windows 10 (106) - 通知(Toast): 通过 toast 打开协议, 通过 toast 选择在指定的时间之后延迟提醒或者取消延迟提醒

    [源码下载] 背水一战 Windows 10 (106) - 通知(Toast): 通过 toast 打开协议, 通过 toast 选择在指定的时间之后延迟提醒或者取消延迟提醒 作者:webabcd ...

  8. 背水一战 Windows 10 (105) - 通知(Toast): 带按钮的 toast, 带输入的 toast(文本输入框,下拉选择框)

    [源码下载] 背水一战 Windows 10 (105) - 通知(Toast): 带按钮的 toast, 带输入的 toast(文本输入框,下拉选择框) 作者:webabcd 介绍背水一战 Wind ...

  9. 背水一战 Windows 10 (104) - 通知(Toast): 纯文本 toast, 短时 toast, 长时 toast, 图文 toast

    [源码下载] 背水一战 Windows 10 (104) - 通知(Toast): 纯文本 toast, 短时 toast, 长时 toast, 图文 toast 作者:webabcd 介绍背水一战 ...

随机推荐

  1. Linux下普通IO文件操作函数---C语言

    普通文件IO总结 FILE结构体    typedef struct   {       int level; /*填充/清空一级缓存*/     unsigned flag; /*文件状态指针*/ ...

  2. Java 数据类型与运算符

    JAVA数据类型分基本(内置)数据类型和引用数据类型. 区别: 基本数据类型在被创建时,在栈上给其划分一块内存,将数值直接存储在栈上. 引用数据类型在被创建时,首先要在栈上给其引用(句柄)分配一块内存 ...

  3. 分支&循环

    分支 单分支 if 条件: 满足条件后要执行的代码 双分支 if 条件: 满足条件执行代码 else: if条件不满足就走这段 多分支: if 条件: 满足条件执行代码 elif 条件: 上面的条件不 ...

  4. 思科模拟器GNS3-2.1.8安装笔记 (适用于版本2.0.3以上的GNS3)

    当前现阶段学习经常使用的路由交换设备主要来自于思科.华为和华三三家,这三家的设备操作配置大致类似,却又不尽相同.因为实体设备通常都非常昂贵,所以作为学习,我们通常会使用它们提供的模拟器.华为的模拟器是 ...

  5. 基于服务器的AAA配置实验(Cisco PT)

    一.实验拓扑 二.网络地址分配 Device Interface IP Address Subnet Mask R1 Fa0/0 192.168.1.1 255.255.255.0 S0/0/0 10 ...

  6. python 代码求阶乘

    递归实现 1: #递归实现 def factorial(n): if n == 0: return 1 else: return n * factorial(n - 1)# 递归实现 递归实现 2: ...

  7. python 杨辉三角实现逻辑

    程序输出需要实现如下效果: [1] [1,1] [1,2,1] [1,3,3,1] ...... 方法:迭代,生成器 def triangles() L = [1] while True: yiled ...

  8. EasyPR源码剖析(6):车牌判断之LBP特征

    一.LBP特征 LBP指局部二值模式,英文全称:Local Binary Pattern,是一种用来描述图像局部特征的算子,LBP特征具有灰度不变性和旋转不变性等显著优点. 原始的LBP算子定义在像素 ...

  9. [翻译]理解分析Linux里的101个ELF文件

    原文:https://linux-audit.com/elf-binaries-on-linux-understanding-and-analysis/

  10. Moving or disabling the package cache for Visual Studio 2017

    Moving or disabling the package cache for Visual Studio 2017 | Setup & Install by Heath Stewart ...