一:需求

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

二: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 弹出的更多相关文章

  1. UWP Popup 弹出提示框

    一:需求 做一个类似于安卓的弹出消息框,如图.当用户点击下载或者选择时,能够从底部弹出一个提示框,用于提示用户. 二:Popup 类 不需要我们自己额外去写一个弹窗类,微软自己有一个Popup 弹窗类 ...

  2. vant - 弹框 【Popup 弹出层】【DatetimePicker 时间选择】

    [HelloWorld.vue] <template> <div class="hello"> <van-row class="m-head ...

  3. 【ABAP系列】SAP ABAP POPUP弹出框自建内容

    公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[MM系列]SAP ABAP POPUP弹出框自 ...

  4. Popup - 弹出层

    //图片类快捷弹出层 <a href="" target="_blank"> <div class="panlifang1" ...

  5. pentaho cde popup弹出框口

    弹出窗口在pentaho cde里面相对比较容易,不过还是记录一下,以防时间久了,忘记关键参数. 先看一下效果图: 画出自己想要在弹出框展示的图形,把他的HtmlObject设置成弹出窗口,如图: 然 ...

  6. Django:popup弹出框简单应用实例

    效果:在p1.html页面点击,弹出p2的弹出框,填写数据,在 popup_response页面处理数据 1.url设置 urlpatterns = patterns( url(r'^p1.html' ...

  7. Xamarin 自定义 ToolbarItem 溢出菜单实现(Popover/Popup) 弹出下拉效果

    使用  Rg.Plugins.Popup 插件 1.  新建 PopupMenu.xaml <?xml version="1.0" encoding="utf-8& ...

  8. 背水一战 Windows 10 (36) - 控件(弹出类): ToolTip, Popup, PopupMenu

    [源码下载] 背水一战 Windows 10 (36) - 控件(弹出类): ToolTip, Popup, PopupMenu 作者:webabcd 介绍背水一战 Windows 10 之 控件(弹 ...

  9. 控件(弹出类): ToolTip, Popup, PopupMenu

    示例1.ToolTip 的示例Controls/FlyoutControl/ToolTipDemo.xaml <Page x:Class="Windows10.Controls.Fly ...

随机推荐

  1. OSGi-入门篇之生命周期层(03)

    前言 生命周期层在OSGi框架中属于模块层上面的一层,它的运作是建立在模块层的功能之上的.生命周期层一个主要的功能就是让你能够从外部管理应用或者建立能够自我管理的应用(或者两者的结合),并且给了应用本 ...

  2. 监控-CPU使用率

    原始脚本来自TG,自己对部分脚本做了调整,分享出来仅供参考,请勿整篇Copy! 使用以下语句获取[CPU使用率] USE [DBA_Monitor] GO /****** 对象: StoredProc ...

  3. mysql水平分表和垂直分表的优缺点

    表分割有两种方式: 1.水平分割:根据一列或多列数据的值把数据行放到两个独立的表中. 水平分割通常在下面的情况下使用. •表很大,分割后可以降低在查询时需要读的数据和索引的页数,同时也降低了索引的层数 ...

  4. PHP buffer的机制

    PHP的buffer是这样的: 输出的字符串 => PHP buffer => 等待输出 => web 服务器的缓冲区 => tcp 缓冲区 => 客户端.过程其实相当的 ...

  5. unset与unlink

    unset() -- 释放给定的变量 详见->http://www.kuqin.com/php5_doc/function.unset.html unlink() --删除文件    常用于用户 ...

  6. java基本的要点

    我想告诉大家的不是什么java基本要点,只是对初学者的一点忠告,本人是从八维学校亲身经历过的学生,要想学好并且快速了解java,那你首先必须有英语底子,没有英语底子,几个单词都不会的,我觉得还是放弃学 ...

  7. 如何将解压版的tomcat设置为windows 服务启动

    在web服务器上通常需要是web容器随开机自动启动,恰好Tomcat可以作为服务启动,只要经过我们简单的配置,就可以将免安装版的Tomcat添加到系统服务中. 首先需要配置以下环境变量: JAVA_H ...

  8. Java面向对象 IO (四)

     Java面向对象  IO  (四) 知识概要:                 (1)打印流 (2)序列流 SequenceInputStream (3)ObjectInputStream与Ob ...

  9. mybatis一对一嵌套查询

    要求:查询一个员工的时候,把他对应的部门也查询出来 实现(其他配置这里不作说明,框架基于spring_springMVC_mybatis_oracle): 如有不对或不适的地方,请多多指教. 1.新建 ...

  10. WPF之DataGrid应用

    前几天打算尝试下DataGrid的用法,起初以为应该很简单,可后来被各种使用方法和功能实现所折磨.网络上的解决方法太多,但也太杂.没法子,我只好硬着头皮阅览各种文献资料,然后不断的去尝试,总算小有成果 ...