在Windows 10通常是使用Toast通知方式进行的消息通知,但是在应用通知是不需要通知带有音效的,但是又不能在系统通知中心留下记录,那么需要监听ToastNotification实例的Dismissed事件,利用ToastNotificationManager.History.Remove(toastTag)实现Toast通知在之后消失。
但是在PC上使用是由于通知中心在右下角,对用户可能不是太友好。
所以可以通过Popup+UserControl实现应用内的消息通知。当然实现方法也有很多,用处也不知消息通知,例如:[模态框进度指示器的实现](http://edi.wang/post/2016/2/25/windows-10-uwp-modal-progress-dialog) 。
UWP中实现时就是布置好UserControl的模板,然后延迟一秒之后执行淡出动画。

     <UserControl.Resources>
<Storyboard x:Name="Notification" >
<DoubleAnimationUsingKeyFrames Storyboard.TargetName="NotificationGrid"
Storyboard.TargetProperty="Opacity" BeginTime="0:0:0">
<SplineDoubleKeyFrame KeyTime="0:0:0.0" Value="1"/>
<SplineDoubleKeyFrame KeyTime="0:0:0.5" Value="0.0"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</UserControl.Resources>
<Grid Name="NotificationGrid">
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Border Grid.Row="1" HorizontalAlignment="Center" VerticalAlignment="Bottom" Margin="0,50" Padding="20,15" Background="Black" >
<TextBlock Name="NotificationContent" TextWrapping="Wrap" Foreground="#daffffff"></TextBlock>
</Border>
</Grid>

然后在cs中加入三个成员变量,分别是存储提示内容,自定延迟时间,还有就是用来显示的Popup类型的成员变量。
myNotification.xaml.cs

 public sealed partial class myNotification : UserControl
{
private string content;
private TimeSpan showTime;
private Popup popup;
private myNotification()
{
this.InitializeComponent();
this.popup = new Popup();
this.Width = Window.Current.Bounds.Width;
this.Height = Window.Current.Bounds.Height;
popup.Child = this;
this.Loaded += Notification_Loaded;
this.Unloaded += Notification_Unloaded;
}
public myNotification(string content,TimeSpan showTime):this()
{
this.content = content;
this.showTime = showTime;
}
public myNotification(string content):this(content,TimeSpan.FromSeconds())
{ }
public void show()
{
this.popup.IsOpen = true;
}
private void Notification_Unloaded(object sender, RoutedEventArgs e)
{
Window.Current.SizeChanged -= Current_SizeChanged;
} private void Notification_Loaded(object sender, RoutedEventArgs e)
{
NotificationContent.Text = this.content;
this.Notification.BeginTime = this.showTime;
this.Notification.Begin();
this.Notification.Completed += Notification_Completed;
Window.Current.SizeChanged += Current_SizeChanged;
} private void Current_SizeChanged(object sender, Windows.UI.Core.WindowSizeChangedEventArgs e)
{
this.Width = e.Size.Width;
this.Height = e.Size.Height;
} private void Notification_Completed(object sender, object e)
{
this.popup.IsOpen = false;
}
}

然后在MainPage.xaml中加入一个button,并加入click事件来显示通知。
在click事件中加入:

new myNotification("Hello Wrold").show();

运行效果:

UWP消息通知的更多相关文章

  1. [UWP]实现一个轻量级的应用内消息通知控件

    在UWP应用开发中,我们常常有向用户发送一些提示性消息的需求.这种时候我们一般会选择MessageDialog.ContentDialog或者ToastNotification来完成功能. 但是,我们 ...

  2. 使用 Windows10 自定义交互消息通知

    消息通知是最常用的应用功能之一了,但是由于平台的差异,IOS Android 以及 Windows 都有其特殊性,Android开发者在国内常常都是使用三方的一些推送服务,或者是使用自建的服务器为应用 ...

  3. Redis系列二之事务及消息通知

    一.事务 Redis中的事务是一组命令的集合.一个事务中的命令要么都执行,要么都不执行. 1.事务简介 事务的原理是先将一个事务的命令发送给Redis,然后再让Redis依次执行这些命令.下面看一个示 ...

  4. Redis笔记(六)Redis的消息通知

    Redis的消息通知可以使用List类型的LPUSH和RPOP(左进右出),当然更方便的是直接使用Redis的Pub/Sub(发布/订阅)模式. >>使用List实现队列 使用列表类型的L ...

  5. Android中的消息通知(NotificationManager和Notification)

    下面来谈谈notification,这个notification一般用在电话,短 信,邮件,闹钟铃声,在手机的状态栏上就会出现一个小图标,提示用户处理这个通知,这时手从上方滑动状态栏就可以展开并处理这 ...

  6. Android消息通知(notification)和PendingIntent传值

    通知栏的自定义布局:转:http://blog.csdn.net/vipzjyno1/article/details/25248021 拓展 实现自定义的通知栏效果: 这里要用到RemoteViews ...

  7. cordova的android notify消息通知插件

    最近在学习用CORDOVA(PHONEGAP)结合SENCHA TOUCH开发应用,想实现一个安卓下的消息通知功能,这个可以通过CORDOVA的插件来实现. 插件目录结构如下: notifyplugi ...

  8. Unity3D研究院之IOS本地消息通知LocalNotification的使用

    原地址:http://www.xuanyusong.com/archives/2632   现在的游戏里一般都会有本地消息,比如每天定时12点或者下午6点告诉玩家进入游戏领取体力.这种东西没必要服务器 ...

  9. HTML 5的消息通知机制

    译文来源:http://www.ido321.com/1130.html 原文:HTML 5 Notification 译文:HTML 5 的消息通知机制 译者:dwqs HTML 5 已经被应用到W ...

随机推荐

  1. 运用ASP.NET实现

    calation.cs using System; using System.Collections.Generic; using System.Linq; using System.Web; /// ...

  2. javascript平时小例子⑦(鼠标跟随的div)

    <!doctype html><html> <head> <meta charset="utf-8"> <title>无 ...

  3. C 符号

    语言的运算符可分为以下几类: 1 算术运算符 用于各类数值运算.包括加(+).减(-).乘(*).除(/).求余(或称模运算,%).自增(++).自减(–)共七种. 2.关系运算符 用于比较运算.包括 ...

  4. Nginx 和 Apache 开启目录浏览功能

    1.Nginx 在相应项目的 Server 段中的 location 段中,添加 autoindex on.例如: server { listen ; server_name www.dee.prac ...

  5. “菜”鸟理解.NET Framework(CLI,CLR,CTS,CLS,BCL,FCL)

    既然要学.NET,就要先认识认识她,我不喜欢大段大段文字的东西,自己通过理解,画个图,来看看.NET的沉鱼落雁,闭月羞花之容. 最下层蓝色部分是.NET Framework的基础,也是所有应用软件的基 ...

  6. crontab 管理指定用户的定时任务

    创建用户定时任务文件 touch /var/spool/cron/target_user crontab -u target_user /var/spool/cron/target_user 编辑用户 ...

  7. ax Mail

    SysMailer mailer = new SysMailer(); SysEmailParameters parameters = SysEmailParameters::find(); ; tr ...

  8. c# unchecked关键字。byte 合并short

    参考MSDN 代码: public class BytesOperate { /// <summary> /// 计算校验和,SUM /// </summary> public ...

  9. [PCL]点云渐进形态学滤波

    PCL支持点云的形态学滤波,四种操作:侵蚀.膨胀.开(先侵蚀后膨胀).闭(先膨胀后侵蚀) 在#include <pcl/filters/morphological_filter.h>中定义 ...

  10. 手机端页面自适应解决方案—rem布局

    只需在页面引入这段原生js代码就可以了 (function (doc, win) { var docEl = doc.documentElement, resizeEvt = 'orientation ...