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 ...
随机推荐
- 银河麒麟操作系统打开VMware报vmmon无法编译
使用银河麒麟操作系统打开VMware可能会报vmmon无法编译 这个时候... 将/usr/src/linux-headers-xxx/include/miscdevice.h第71行void改为in ...
- 用List传递学生信息
集合在程序开发中经常用到,例如,在业务方法中将学生信息.商品信息等存储到集合中,然后作为方法的返回值返回给调用者,以此传递大量的有序数据. 本实例将使用List集合在方法之间传递学生的信息.实例效果如 ...
- Spring03-jdbc
1,Spring集成Jdbc,需要导入spring包和数据库驱动包,这里我们使用的是mysql驱动包 2,选择一个数据源(DBCP,C3P0),这里我们使用DBCP,需要导入DBCP驱动包 3,创建j ...
- PHP 动态调整内存限制
最近公司的一个PHP项目在操作大文件的时候总是抛出这个异常 Fixing PHP Fatal Error: Allowed Memory Size Exhausted 经过一番调试后发现是达到了PHP ...
- Redis的安装以及在项目中使用Redis的一些总结和体会
第一部分:为什么我的项目中要使用Redis 我知道有些地方没说到位,希望大神们提出来,我会吸取教训,大家共同进步! 注册时邮件激活的部分使用Redis 发送邮件时使用Redis的消息队列,减轻网站压力 ...
- 开源API集成测试工具 Hitchhiker v0.1.3 - 参数化请求
Hitchhiker 是一款开源的 Restful Api 集成测试工具,你可以轻松部署到本地,和你的team成员一起管理Api. 详细介绍请看: http://www.cnblogs.com/bro ...
- ajax 发送json 后台接收 遍历保存进数据库
前台怎么拿参数的我就不管了我也不会 反正用这个ajax没错 ajax 代码 一定要写明http请求类型 { contentType:"application/x-www-form-ur ...
- 初识oracle存储过程
参见:http://www.cnblogs.com/linjiqin/archive/2011/04/16/2018411.html 1.存储过程的语法结构: CREATE OR REPLACE PR ...
- C#操作SqlServer MySql Oracle通用帮助类Db_Helper_DG(默认支持数据库读写分离、查询结果实体映射ORM)
[前言] 作为一款成熟的面向对象高级编程语言,C#在ADO.Net的支持上已然是做的很成熟,我们可以方便地调用ADO.Net操作各类关系型数据库,在使用了多年的Sql_Helper_DG后,由于项目需 ...
- django之快速分页
本文介绍djanog两种分页,第一是普通分页,第二是使用haystack全文检索的分页. 1.django自带分页功能,这个功能非常好用.基本知识点:Django提供了数据分页的类,这些类被定义在dj ...