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 弹出的更多相关文章
- UWP Popup 弹出提示框
一:需求 做一个类似于安卓的弹出消息框,如图.当用户点击下载或者选择时,能够从底部弹出一个提示框,用于提示用户. 二:Popup 类 不需要我们自己额外去写一个弹窗类,微软自己有一个Popup 弹窗类 ...
- vant - 弹框 【Popup 弹出层】【DatetimePicker 时间选择】
[HelloWorld.vue] <template> <div class="hello"> <van-row class="m-head ...
- 【ABAP系列】SAP ABAP POPUP弹出框自建内容
公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[MM系列]SAP ABAP POPUP弹出框自 ...
- Popup - 弹出层
//图片类快捷弹出层 <a href="" target="_blank"> <div class="panlifang1" ...
- pentaho cde popup弹出框口
弹出窗口在pentaho cde里面相对比较容易,不过还是记录一下,以防时间久了,忘记关键参数. 先看一下效果图: 画出自己想要在弹出框展示的图形,把他的HtmlObject设置成弹出窗口,如图: 然 ...
- Django:popup弹出框简单应用实例
效果:在p1.html页面点击,弹出p2的弹出框,填写数据,在 popup_response页面处理数据 1.url设置 urlpatterns = patterns( url(r'^p1.html' ...
- Xamarin 自定义 ToolbarItem 溢出菜单实现(Popover/Popup) 弹出下拉效果
使用 Rg.Plugins.Popup 插件 1. 新建 PopupMenu.xaml <?xml version="1.0" encoding="utf-8& ...
- 背水一战 Windows 10 (36) - 控件(弹出类): ToolTip, Popup, PopupMenu
[源码下载] 背水一战 Windows 10 (36) - 控件(弹出类): ToolTip, Popup, PopupMenu 作者:webabcd 介绍背水一战 Windows 10 之 控件(弹 ...
- 控件(弹出类): ToolTip, Popup, PopupMenu
示例1.ToolTip 的示例Controls/FlyoutControl/ToolTipDemo.xaml <Page x:Class="Windows10.Controls.Fly ...
随机推荐
- 更自然的解决字典数组插入nil而导致crash
最近在优化项目虽说小优化一直在持续,大版本的优化也进行了两个版本了但是bug列表依旧血淋淋的摆在那里.有的看一眼也能找到问题所在但是有的就是想破头也不知道问题在哪里,毕竟整个项目经过了N个人的手代码风 ...
- 在腾讯云上搭建WordPress博客
笔者一直很羡慕那些搭建了个人博客的大牛,在最近工作之余也尝试着搭建了自己的博客,历时1周,这篇文章就将踩过的坑记录下来,先看下成果,链接在此 1- 购买腾讯云主机 腾讯云官网,我选了79元/月的最便宜 ...
- 移动商城第四篇【Controller配置、添加品牌之文件上传和数据校验】
Controller层配置 编写SpringMVC的配置文件 springmvc.xml <?xml version="1.0" encoding="UTF-8&q ...
- oracle-外连接left join的应用
需求 自助设备交易统计 输入项 类型 可为空 备注 机构 选择 Y 采用下拉框的形式 终端号 手输 Y 与柜员号二选一 交易柜员号 手输 与终端号二选一 时间 选择 N 时间区间 状态 多选 设备状态 ...
- Spring MVC 的文件下载
在看Spring MVC文件下载之前请先看Spring MVC文件上传 地址:http://www.cnblogs.com/dj-blog/p/7535101.html 文件下载比较简单,在超链接中指 ...
- 庞玉栋:浅谈seo优化对于网站建设的重要性
根据最近做SEO优化经验而写 写的也都是我的方法 大神勿喷 SEO:英文Search Engine Optimization缩写而来, 中文意译为搜索引擎优化 如果你连个网站都没有那就点这里:如何拥 ...
- 关于IOS的屏幕适配(iPhone)——Auto Layout和Size Classes
Auto Layout和Size Classes搭配使用极大的方便了开发者,具体如何使用Auto Layout和Size Classes大家可以参考其他文章或者书籍,这里只提一点,在我们设置Size ...
- AES加解密算法Qt实现
[声明] (1) 本文源码 在一位未署名网友源码基础上,利用Qt编程,实现了AES加解密算法,并添加了文件加解密功能.在此表示感谢!该源码仅供学习交流,请勿用于商业目的. (2) 图片及描述 除图1外 ...
- Hive基础(2)---(启动HiveServer2)Hive严格模式
启动方式 1, hive 命令行模式,直接输入/hive/bin/hive的执行程序,或者输入 hive –service cli 用于linux平台命令行查询,查询语句基本跟mysql查询语句类似 ...
- 关于 HashTable
hashTable 的一些认识: 底层使用散列表,存贮键值对,键值非null 使用synchronize 保证线程安全 (线程安全) ■全局变量 //The hash table data. //底层 ...