UWP Popup 弹出提示框
一:需求
做一个类似于安卓的弹出消息框,如图。当用户点击下载或者选择时,能够从底部弹出一个提示框,用于提示用户。

二:Popup 类
不需要我们自己额外去写一个弹窗类,微软自己有一个Popup 弹窗类。当弹窗打开时,会自动放在当前应用页面的最顶层。
//获取或设置要在弹出项中承载的内容。
public UIElement Child { get; set; }
Popup类里有一个Child属性,用来存弹窗中的内容。
child的类型是UIElement。
UIElement 是具有可视外观并可以处理基本输入的大多数对象的基类。
因此child属性可以存grid stackpannel 这些......
//获取或设置弹出项当前是否显示在屏幕上。
//如果当前显示了弹出项,则为 **true**;否则为 **false**。 默认值为 **false**。
public bool IsOpen { get; set; }
Popup类还有一个IsOpen属性,当会true的时候,弹窗是打开的。false则相反。
三:ps。。。
当创建一个popup的对象,并且将它的IsOpen属性设置为true的时候,代表将会有一个弹窗 显示在当前应用的最顶层。
像上面图中的做法,看上去只有一小块是弹窗,其实我的做法是,最顶层的popup的child属性里放的是一个grid,在grid里才是我显示出来的那一小块提示框,因为grid如果没有背景颜色的话,底下一层是会显示的,所以没有什么问题。不会因为盖了一层grid,底下的内容会被盖住。
四:直接上代码
创建一个用户控件
<UserControl
x:Class="One.UC.PopupNotice"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:One.UC"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight=""
d:DesignWidth=""> <UserControl.Resources> <Storyboard x:Name="PopupIn">
<DoubleAnimation From=""
To=""
Duration="00:00:00.5"
Storyboard.TargetName="PopupContainer"
Storyboard.TargetProperty="Opacity"
>
<DoubleAnimation.EasingFunction>
<PowerEase EasingMode="EaseOut"></PowerEase>
</DoubleAnimation.EasingFunction>
</DoubleAnimation>
<DoubleAnimation From="-10"
To="-100"
Duration="00:00:00.5"
Storyboard.TargetName="PopupContainer"
Storyboard.TargetProperty="(UIElement.RenderTransform).(TranslateTransform.Y)"
>
<DoubleAnimation.EasingFunction>
<PowerEase EasingMode="EaseOut"></PowerEase>
</DoubleAnimation.EasingFunction>
</DoubleAnimation>
</Storyboard> <Storyboard x:Name="PopupOut">
<DoubleAnimation From=""
To=""
Duration="00:00:00.5"
Storyboard.TargetName="PopupContainer"
Storyboard.TargetProperty="Opacity"
>
<DoubleAnimation.EasingFunction>
<PowerEase EasingMode="EaseOut"></PowerEase>
</DoubleAnimation.EasingFunction>
</DoubleAnimation>
<DoubleAnimation From="-100"
To="-10"
Duration="00:00:00.5"
Storyboard.TargetName="PopupContainer"
Storyboard.TargetProperty="(UIElement.RenderTransform).(TranslateTransform.Y)"
>
<DoubleAnimation.EasingFunction>
<PowerEase EasingMode="EaseOut"></PowerEase>
</DoubleAnimation.EasingFunction>
</DoubleAnimation>
</Storyboard> </UserControl.Resources> <Grid> <StackPanel Background="#18C3D8"
Padding=""
HorizontalAlignment="Center"
VerticalAlignment="Bottom"
Name="PopupContainer"
Opacity=""> <!--改变Y轴和透明底-->
<StackPanel.RenderTransform>
<TranslateTransform Y="-10"></TranslateTransform>
</StackPanel.RenderTransform> <TextBlock Name="PopupContent"></TextBlock> </StackPanel> </Grid> </UserControl>
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Threading.Tasks;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation; // The User Control item template is documented at https://go.microsoft.com/fwlink/?LinkId=234236 namespace One.UC
{
public sealed partial class PopupNotice : UserControl
{
//存放弹出框中的信息
private string _popupContent; //创建一个popup对象
private Popup _popup = null; public PopupNotice()
{
this.InitializeComponent(); //将当前的长和框 赋值给控件
this.Width = Window.Current.Bounds.Width;
this.Height = Window.Current.Bounds.Height; //将当前的控价赋值给弹窗的Child属性 Child属性是弹窗需要显示的内容 当前的this是一个Grid控件。
_popup = new Popup();
_popup.Child = this; //给当前的grid添加一个loaded事件,当使用了ShowAPopup()的时候,也就是弹窗显示了,这个弹窗的内容就是我们的grid,所以我们需要将动画打开了。
this.Loaded += PopupNoticeLoaded; } /// <summary>
/// 重载
/// </summary>
/// <param name="popupContentString">弹出框中的内容</param>
public PopupNotice(string popupContentString):this()
{
_popupContent = popupContentString;
} /// <summary>
/// 显示一个popup弹窗 当需要显示一个弹窗时,执行此方法
/// </summary>
public void ShowAPopup()
{
_popup.IsOpen = true;
} /// <summary>
/// 弹窗加载好了
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
public void PopupNoticeLoaded(object sender, RoutedEventArgs e)
{
PopupContent.Text = _popupContent; //打开动画
this.PopupIn.Begin();
//当进入动画执行之后,代表着弹窗已经到指定位置了,再指定位置等一秒 就可以消失回去了
this.PopupIn.Completed += PopupInCompleted;
} /// <summary>
/// 当进入动画完成后 到此
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
public async void PopupInCompleted(object sender, object e)
{
//在原地续一秒
await Task.Delay(); //将消失动画打开
this.PopupOut.Begin();
//popout 动画完成后 触发
this.PopupOut.Completed += PopupOutCompleted;
} //弹窗退出动画结束 代表整个过程结束 将弹窗关闭
public void PopupOutCompleted(object sender, object e)
{
_popup.IsOpen = false;
} }
}
在要显示一个弹窗的代码里调用ShowAPopup()
PopupNotice popupNotice = new PopupNotice("正在后台下载......");
popupNotice.ShowAPopup();
最终效果:

--------some words----------
1.Popup 弹出
2.UIElement ui元素
----------the end------------
UWP Popup 弹出提示框的更多相关文章
- android标题栏上面弹出提示框(二) PopupWindow实现,带动画效果
需求:上次用TextView写了一个从标题栏下面弹出的提示框.android标题栏下面弹出提示框(一) TextView实现,带动画效果, 总在找事情做的产品经理又提出了奇葩的需求.之前在通知栏显示 ...
- android标题栏下面弹出提示框(一) TextView实现,带动画效果
产品经理用的是ios手机,于是android就走上了模仿的道路.做这个东西也走了一些弯路,写一篇博客放在这里,以后自己也可用参考,也方便别人学习. 弯路: 1.刚开始本来用PopupWindow去实现 ...
- PHP弹出提示框并跳转到新页面即重定向到新页面
本文为大家介绍下使用PHP弹出提示框并跳转到新页面,也就是大家所认为的重定向,下面的示例大家可以参考下 这两天写一个demo,需要用到提示并跳转,主要页面要求不高,觉得没必要使用AJAX,JS等, ...
- [转] 在Asp.net前台和后台弹出提示框
一.在前台弹出提示框 1.点击"A"标记或者"控件按钮"弹出提示框 <asp:LinkButton ID="lbtnDel" runa ...
- SilverLight 页面后台方法XX.xaml.cs 创建JS,调用JS ,弹出提示框
1.Invoke和InvokeSelf [c-sharp] view plaincopy public partial class CreateJSDemo : UserControl { publi ...
- 基于Jquery 简单实用的弹出提示框
基于Jquery 简单实用的弹出提示框 引言: 原生的 alert 样子看起来很粗暴,网上也有一大堆相关的插件,但是基本上都是大而全,仅仅几句话可以实现的东西,可能要引入好几十k的文件,所以话了点时间 ...
- iOS bug 之 H5 页面没有弹出提示框
描述:在安卓上有提示框,但是在iOS上没有提示框. step 1: 失误,是我没有在正确的位置设置网址. step 2: 修改之后,测试页能弹出提示框,但是正式的页面没有提示框. step 3: 我输 ...
- C#自动关闭弹出提示框
自动关闭弹出提示框(用一个小窗体显示提示信息):例如在一个form窗体中弹出自动关闭的提示框1.首先创建一个弹出提示信息的窗体 AutoCloseMassageBox,在里面拖一个lable控件,去掉 ...
- 关于winform窗体关闭时弹出提示框,选择否时窗体也关闭的问题
在窗体中有FormClosing这个事件,这个事件是在窗体关闭时候运行的.如果要取消某个事件的操作,那么就在该事件中写上e.Cancel=true就能取消该事件,也就是不执行该事件.所以,你要在窗体关 ...
随机推荐
- iOS 9已下的获取APP进程信息
- (NSDictionary *)getAppInfo:(NSString *)exec withBundleID:(NSString *)bundle { if ([exec isKindOfCl ...
- HTML页面下雪特效
1. [代码][HTML]代码 <a href="javascript:void(function(){var d = document,a = 'setAttribute' ...
- 让tomcat启动时,自动加载你的项目
在tomcat-->conf-->serve.xml文件最后加上 <Context path="/atest" docBase="E:\Workspac ...
- SqlServer--学习触发器
触发器是一种特殊的存储过程,一种不能被显式执行,而必须依附于一个事件的过程 主要作用:自动化操作;减少手动操作以及出错的几率. 触发器分类:DML(Data Manipulation Language ...
- js日期的初始化的格式
js在初始化日期对象时,如果有传入日期.则格式有兼容性问题: //下面的写法在谷歌下没有问题,在火狐和ie下有问题var time = new Date('2014-11-27 00:00:00'); ...
- C#中XML解析的增加修改和删除
01添加xml节点 private void AddXml(string image, string title) { XmlDocument xmlDoc = n ...
- (QA-LSTM)自然语言处理:智能问答 IBM 保险QA QA-LSTM 实现笔记.md
train集: 包含若干条与保险相关的问题,每一组问题对为一行,示意如下: 可分为四项,第三项为问题,第四项为答案: 1.build_vocab 统计训练集中出现的词,返回结果如下(一个包含3085个 ...
- Swift类型转换
关于「类型转换」(Type Casting),<The Swift Programming Language>描述如下: Type casting is a way to check th ...
- ZOJ3496 Assignment
传送门 这题也是真恶心-- 题目大意是俩公司要运货,每条路有容量上限.然后B公司手里有p个--(技能点?)如果在一条路上放了x个技能点,这条路经过了y个货物,那么B公司就会收x*y的钱.现在要求的是, ...
- JavaScript-Tool-导向:jquery.steps-un
ylbtech-JavaScript-Tool-导向:jquery.steps 1.返回顶部 2.返回顶部 3.返回顶部 4.返回顶部 5.返回顶部 0. http://www.jqu ...