为了让用户有个更好的UI交互,可以增加自动淡出的消息弹窗,例如:网易云音乐UWP,切换播放模式时,出现的类似消息提示。

右键项目,添加用户控件

UserControlDemo.xaml:

<UserControl
<UserControl.Resources>
<Storyboard x:Name="story_Board" >
<DoubleAnimationUsingKeyFrames Storyboard.TargetName="main_Grid"
Storyboard.TargetProperty="Opacity"
BeginTime="0:0:0">
<SplineDoubleKeyFrame KeyTime="00:00:00.00" Value="1"/>
<SplineDoubleKeyFrame KeyTime="00:00:00.400" Value="0.0"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</UserControl.Resources>
<Grid x:Name="main_Grid">
<Border CornerRadius="10"
Background="Transparent"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Padding="15,5">
<TextBlock x:Name="showContent_textBlock" Margin="10,0,0,2" Foreground="WhiteSmoke" FontSize="30"/>
</Border>
</Grid>
</UserControl>

UserControlDemo.xaml.cs:

public sealed partial class UserControlDemo : UserControl
{
private Popup popup;
private string str;
private TimeSpan showTime_tmr;
public UserControlDemo()
{
this.InitializeComponent();
popup = new Popup();
popup.Child = this;
MeasurePopupSize();
this.Loaded += NotifyPopup_Loaded;
this.Unloaded += NotifyPopup_Unloaded;
} public VolumeContentDialog(string content, TimeSpan showTime) : this()
{
this.str = content;
this.showTime_tmr = showTime; } public VolumeContentDialog(string content) : this(content, TimeSpan.FromSeconds(2))
{
} public void Show()
{
this.popup.IsOpen = true;
} public void Hide()
{
this.popup.IsOpen = false;
} private void MeasurePopupSize()
{
this.Width = ApplicationView.GetForCurrentView().VisibleBounds.Width; double marginTop = 0;
if (ApiInformation.IsTypePresent("Windows.UI.ViewManagement.StatusBar"))
marginTop = StatusBar.GetForCurrentView().OccludedRect.Height;
this.Height = ApplicationView.GetForCurrentView().VisibleBounds.Height;
this.Margin = new Thickness(0, marginTop, 0, 0);
} private void NotifyPopup_Loaded(object sender, RoutedEventArgs e)
{
this.showContent_textBlock.Text = str;
this.story_Board.BeginTime = this.showTime_tmr;
this.story_Board.Begin();
this.story_Board.Completed += storyBoard_Completed;
ApplicationView.GetForCurrentView().VisibleBoundsChanged += NotifyPopup_VisibleBoundsChanged;
}
private void NotifyPopup_VisibleBoundsChanged(ApplicationView sender, object args)
{
MeasurePopupSize();
} private void storyBoard_Completed(object sender, object e)
{
this.popup.IsOpen = false;
} private void NotifyPopup_Unloaded(object sender, RoutedEventArgs e)
{
ApplicationView.GetForCurrentView().VisibleBoundsChanged -= NotifyPopup_VisibleBoundsChanged;
}
}

然后直接在MianPage.cs中实例化引用就可以了。

MainPage.xaml.cs:

UserControlDemo demo = new UserControlDemo("Demo");
demo.Show();

UWP笔记-消息弹窗自动淡出的更多相关文章

  1. Sagit.Framework For IOS 开发框架入门教程5:消息弹窗STMsgBox

    前言: 昨天刚写了一篇IT连创业的文章:IT连创业系列:产品设计之答题模块,(欢迎大伙关注!) 感觉好久没写IOS的文章了,今天趁机,来补一篇,Sagit的教程. Sagit 开源地址:https:/ ...

  2. Storm学习笔记 - 消息容错机制

    Storm学习笔记 - 消息容错机制 文章来自「随笔」 http://jsynk.cn/blog/articles/153.html 1. Storm消息容错机制概念 一个提供了可靠的处理机制的spo ...

  3. ArcGIS案例学习笔记-CAD数据自动拓扑检查

    ArcGIS案例学习笔记-CAD数据自动拓扑检查 联系方式:谢老师,135-4855-4328,xiexiaokui#qq.com 功能:针对CAD数据,自动进行拓扑检查 优点:类别:地理建模项目实例 ...

  4. 【WPF】对话框/消息弹窗

    非模式对话框 需求:弹窗是非模式对话框,即可以多个弹窗弹出,且弹窗后面的窗体可以被操作,不会被锁定. 自定义的窗体Window实现以下步骤: 在C#代码中弹出窗体时,使用 window.Show() ...

  5. ASP.NET 多语言的实现(后台消息+前台消息+页面自动绑定)

    一 前言 界面支持多种语言,在使用ASP.NET自带的多语言方案时遇到下列问题: 在做管理类的功能时,有添加.修改和查看页面,需要支持多语言的控件基本相同,但要维护多处,产生冗余(ASP.NET有共享 ...

  6. JDBC学习笔记(6)——获取自动生成的主键值&处理Blob&数据库事务处理

    获取数据库自动生成的主键 [孤立的技术是没有价值的],我们这里只是为了了解具体的实现步骤:我们在插入数据的时候,经常会需要获取我们插入的这一行数据对应的主键值. 具体的代码实现: /** * 获取数据 ...

  7. objc_msgSend消息传递学习笔记 – 消息转发

    该文是 objc_msgSend消息传递学习笔记 – 对象方法消息传递流程 的基础上继续探究源码,请先阅读上文. 消息转发机制(message forwarding) Objective-C 在调用对 ...

  8. js封装好的模仿qq消息弹窗代码

    在我们的日常开发中,或者生活中.常常须要用到弹出窗.这里我们就用js模拟一下qq消息一样的弹出窗. 直接贴代码: <!DOCTYPE html PUBLIC "-//W3C//DTD ...

  9. ArcGIS API for JavaScript 4.2学习笔记[15] 弹窗内容的格式与自定义格式

    先看结果截图吧(不看过程可以直接看总结,在文末): 随便点击了两个城市斑块,出现结果如图. 我来解读一下这结果和以前的有什么不同: 这个例子使用了PopupTemplate,数据是Layer(使用Po ...

随机推荐

  1. Docker搭建Redis一主两从三哨兵

    作者:oscarwin juejin.im/post/5d26b03de51d454fa33b1960 这次实验准备了三台云主机,系统为Debian,ip分别为:35.236.172.131 ,35. ...

  2. flutter布局-1-column

    1.mainAxisAlignment:主轴布局方式,column主轴方向是垂直的方向   mainaxis.png 默认值:MainAxisAlignment.start: start ,沿着主轴方 ...

  3. centos安装JDK、Tomcat、mysql

    1.下载 jdk-8u131-linux-x64.tar.gz 下载地址: https://pan.baidu.com/s/1o8LW9eE 密码: miva 2.下载 apache-tomcat-8 ...

  4. Gradle 如何配置将编译的 JAR 发布到 Archiva 中

    有时候我们希望将我们的jar 开发包发布到 Archiva 中. 如何配置 Gradle 的编译脚本呢? 首先你需要启用 Gradle 的 Maven-publish 插件. plugins { id ...

  5. 外网可以反问lxr

    , 'baseurl_aliases' => 174       [ 'http://172.168.2.4/lxr' 175       , 'http://mydomain/lxr' 176 ...

  6. c++ demo code

    /* //多继承 #include <iostream> using namespace std; class Sofa { public: Sofa(); ~Sofa(); void s ...

  7. Java 使用线程池分批插入或者更新数据

    需求:在开发业务报表时,需要从MySQL数据库读取数据后进行操作,然后写入数据库,使用定时任务跑批. 分析:①兼顾性能,②  MySQL没有Oracle那么方便.强大的存储过程.综上所述,使用线程池以 ...

  8. JavaWeb_(Spring框架)Spring与JDBC

    一.用Spring中的JdbcTemplate操作数据库 在MySQL中准备一个user表,表中增加一条假数据 用Spring中的JdbcTemplate操作数据库,在JdbcTemplate中实现增 ...

  9. HDU 1069 Monkey and Banana ——(DP)

    简单DP. 题意:给出若干种长方体,如果摆放时一个长方体的长和宽小于另一个的长宽,那么它可以放在另一个的上面,问最高能放多少高度.每种长方体的个数都是无限的. 做法:因为每种个数都是无限,那么每种按照 ...

  10. 64位linux下玩32位汇编编程

    利用下假期,打算把linux下的汇编语言给熟悉下,结果是以32位为版本的,只能在办公室的机器上跑了个opensuse的32位版本,家里的suse挂了,无法输入中文.打算再安装下32位系统,今天找到了个 ...