UWP消息通知
在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消息通知的更多相关文章
- [UWP]实现一个轻量级的应用内消息通知控件
在UWP应用开发中,我们常常有向用户发送一些提示性消息的需求.这种时候我们一般会选择MessageDialog.ContentDialog或者ToastNotification来完成功能. 但是,我们 ...
- 使用 Windows10 自定义交互消息通知
消息通知是最常用的应用功能之一了,但是由于平台的差异,IOS Android 以及 Windows 都有其特殊性,Android开发者在国内常常都是使用三方的一些推送服务,或者是使用自建的服务器为应用 ...
- Redis系列二之事务及消息通知
一.事务 Redis中的事务是一组命令的集合.一个事务中的命令要么都执行,要么都不执行. 1.事务简介 事务的原理是先将一个事务的命令发送给Redis,然后再让Redis依次执行这些命令.下面看一个示 ...
- Redis笔记(六)Redis的消息通知
Redis的消息通知可以使用List类型的LPUSH和RPOP(左进右出),当然更方便的是直接使用Redis的Pub/Sub(发布/订阅)模式. >>使用List实现队列 使用列表类型的L ...
- Android中的消息通知(NotificationManager和Notification)
下面来谈谈notification,这个notification一般用在电话,短 信,邮件,闹钟铃声,在手机的状态栏上就会出现一个小图标,提示用户处理这个通知,这时手从上方滑动状态栏就可以展开并处理这 ...
- Android消息通知(notification)和PendingIntent传值
通知栏的自定义布局:转:http://blog.csdn.net/vipzjyno1/article/details/25248021 拓展 实现自定义的通知栏效果: 这里要用到RemoteViews ...
- cordova的android notify消息通知插件
最近在学习用CORDOVA(PHONEGAP)结合SENCHA TOUCH开发应用,想实现一个安卓下的消息通知功能,这个可以通过CORDOVA的插件来实现. 插件目录结构如下: notifyplugi ...
- Unity3D研究院之IOS本地消息通知LocalNotification的使用
原地址:http://www.xuanyusong.com/archives/2632 现在的游戏里一般都会有本地消息,比如每天定时12点或者下午6点告诉玩家进入游戏领取体力.这种东西没必要服务器 ...
- HTML 5的消息通知机制
译文来源:http://www.ido321.com/1130.html 原文:HTML 5 Notification 译文:HTML 5 的消息通知机制 译者:dwqs HTML 5 已经被应用到W ...
随机推荐
- Flume_使用
案例一: source:hive.log channel: memory sink: logger输出 拷贝一份flume-conf.properties.template改名为hive-mem-l ...
- 日志分析_使用shell完整日志分析案例
一.需求分析 1. 日志文件每天生成一份(需要将日志文件定时上传至hdfs) 2. 分析日志文件中包含的字段:访问IP,访问时间,访问URL,访问状态,访问流量 3. 现在有"昨日" ...
- 一些稍微复杂点的sql语句
UPDATE test SET content = REPLACE(content,'国家级',''),content = REPLACE(content,'世界级',''),content = RE ...
- 总结-computer
常见问题 1.任务栏位置:%AppData%\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar 2.锁定到任务栏的图标不见了: ...
- The Path Attribute
https://tools.ietf.org/html/rfc6265#section-5.1.1 4.1.2.4. The Path Attribute The scope of each cook ...
- Tomcat 随机挂掉
最近遇到一些诡异的事情,1Apache + 4Tomcat的系统中,每天偶尔会发现其中的一台或几台Tomcat宕机了. 今天特别频繁,宕了有6次之多. 环境: Windows Server 20 ...
- 使用git@osc管理现有项目
首先安装git和powershell集成git工具 参考 http://www.cnblogs.com/kreo/p/4685988.html 打开windows powershell,进入项目目录, ...
- EntityFramework 性能优化
1. 查询时如果不缓存数据,可以加快加载速度 //连接数据库 TestDbContext db = new TestDbContext(); //使用 AsNoTracking() 方法后将不会在 D ...
- css基础知识
CSS 规则由两个主要的部分构成:选择器,以及一条或多条声明.其中选择器通常是您需要改变样式的 HTML 元素(比如p标签),也可以是节点的属性的值(比如id,class):每条声明都是一条字典key ...
- windows 系统时钟
偶然发现了一个函数用以查询操作系统的时钟间隔: BOOL WINAPI GetSystemTimeAdjustment( _Out_ PDWORD lpTimeAdjustment, _Out_ PD ...