xamarin UWP平台下 HUD 自定义弹窗
在我的上一篇博客中我写了一个在xamarin的UWP平台下的自定义弹窗控件。在上篇文章中介绍了一种弹窗的写法,但在实际应用中发现了该方法的不足:
1、当弹窗出现后,我们拖动整个窗口大小的时候,弹窗的窗口大小没有随着主窗口大小变化。
2、当弹窗出现时,在我们的主窗口上的后退按钮并没有被弹窗遮罩住,这导致了在弹窗的时候窗口还能返回。
为解决上述问题,我们需更改原来的方式,方法如下:
1、定义一个uwp平台的用户控件
xaml文件代码:
<UserControl
x:Class="Test.UWP.ExtendControls.UWPHUD"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Test.UWP.ExtendControls"
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=""> <Grid Name="mask_grid" Background="{ThemeResource TKHUDColorBrush}" >
<Grid Grid.Row="">
<Border Background="Black" CornerRadius="" HorizontalAlignment="Center" VerticalAlignment="Center">
<TextBlock Margin="" Name="msg_Txt" Foreground="White" Text="..." MinWidth="" ></TextBlock>
</Border>
</Grid> </Grid>
</UserControl>
UWPHUD.xaml
xaml.cs文件代码:
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Core;
using Windows.UI.ViewManagement;
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 http://go.microsoft.com/fwlink/?LinkId=234236 namespace Test.UWP.ExtendControls
{
public sealed partial class UWPHUD : UserControl
{ Popup popup;
public UWPHUD()
{
this.InitializeComponent();
SystemNavigationManager.GetForCurrentView().BackRequested += UWPHUD_BackRequested;
}
public UWPHUD(string message)
{
this.InitializeComponent();
SystemNavigationManager.GetForCurrentView().BackRequested += UWPHUD_BackRequested;
msg_Txt.Text = message;
} private void UWPHUD_BackRequested(object sender, BackRequestedEventArgs e)
{
HUDClose();
} public void Show()
{
//var appView = ApplicationView.GetForCurrentView();
popup = new Popup();
popup.Child = this;
var bounds = Window.Current.Bounds;
this.Width = bounds.Width;
this.Height = bounds.Height;
popup.IsOpen = true;
}
public void HUDClose()
{
if (popup.IsOpen)
{
popup.IsOpen = false;
}
} }
}
UWPHUD.xaml.cs
同时在原来的基础代码上调用现在定义好的uwp用户控件,代码如下:
using Mixin.Dependencies;
using Mixin.UWP.ExtendControls;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.UI;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Media;
using Xamarin.Forms; [assembly: Dependency(typeof(Mixin.UWP.Dependencies.HUD))]
namespace Test.UWP.Dependencies
{
public class HUD : IHUD
{
private UWPHUD uwpHUD = null;
public HUD() { } public void Show(string msg)
{
ShowProgress(msg);
}
public void ShowSuccess(string msg)
{
ShowProgress(msg, );
}
public void ShowError(string msg)
{
ShowProgress(msg, );
}
public void ShowErrorLong(string msg)
{
ShowProgress(msg, );
} public void ShowProgress(string msg, int second = )
{
uwpHUD = new UWPHUD(msg);
uwpHUD.Show(); if (second > )
{
Task.Delay(second)
.ContinueWith(t =>
{
Device.BeginInvokeOnMainThread(() =>
{
uwpHUD.HUDClose();
});
}
);
}
else
{
Task.Delay()
.ContinueWith(t =>
{
Device.BeginInvokeOnMainThread(() =>
{
uwpHUD.HUDClose();
});
}
);
}
}
public void Dismiss()
{
Device.BeginInvokeOnMainThread(() =>
{
uwpHUD.HUDClose();
});
}
}
}
HUD.cs
经如上方式可解决弹窗的两个问题。
xamarin UWP平台下 HUD 自定义弹窗的更多相关文章
- xamarin UWP设置HUD加载功能
使用xamarin开发的时候经常用到加载HUD功能,就是我们常见的一个加载中的动作,Android 下使用 AndHUD , iOS 下使用 BTProgressHUD, 这两个在在 NuGet 上都 ...
- xamarin UWP中MessageDialog与ContentDialog的区别
MessageDialog与ContentDialog的异同点解析: 相同点一:都是uwp应用上的一个弹窗控件.都能做为弹出应用. 相异点一:所在命名空间不同,MessageDialog在Window ...
- [转]Windows平台下Makefile学习笔记
Windows平台下Makefile学习笔记(一) 作者:朱金灿 来源:http://blog.csdn.net/clever101 决心学习Makefile,一方面是为了解决编译开源代码时需要跨编译 ...
- wchar_t是内置还是别名(亲测有效:wchar_t在windows下是16位整数的别名,在linux等平台下是32位整数的别名。MSVC2008开始默认是/Zc:wchar_t)
接前一篇C++ ABI之名字改编(以Qt为例),继续看看C++名字改编相关的问题. 问题 MSVC 有一对选项/Zc:wchar_t- 与 /Zc:wchar_t控制wchar_t 于是 wchar_ ...
- node.js平台下,利用cookie实现记住密码登陆(Express+Ejs+Mysql)
本博文需有node.js+express+mysql入门基础,若基础薄弱,可参考博主的其他几篇node.就是博文: 1.下载Mysql数据库,安装并配置 创建用户表供登录使用: 2.node.js平台 ...
- 【VS开发】Windows平台下Makefile学习笔记
作者:朱金灿 来源:http://blog.csdn.net/clever101 决心学习Makefile,一方面是为了解决编译开源代码时需要跨编译平台的问题(发现一些开源代码已经在使用VS2010开 ...
- Caffe介绍与测试及相关Hi35xx平台下caffe yolox的使用参考
这一篇我大概讲讲Caffe框架下MNIST的实现与基于Hi35xx平台下caffe yolox的运用等,供大家参考 1.Caffe介绍与测试 caffe全称Caffe Convolutional Ar ...
- ExtJs基础知识总结:自定义弹窗和ComboBox自动联想加载(四)
概述 Extjs弹窗可以分为消息弹窗.对话框,这些弹窗的方式ExtJs自带的Ext.Msg.alert就已经可以满足简单消息提示,但是相对复杂的提示,比如如何将Ext.grid.Panel的控件显示嵌 ...
- xamarin UWP证书问题汇总
打算开发一个软件使用rsa加密的东西,所以有用到数字证书这块,最近遇到些问题, 问题一:使用如下代码添加数字证书后,在证书管理器的当前用户和本地计算机下都找不到这张证书. using (X509Sto ...
随机推荐
- 用nexus搭建maven私服
首先介绍一下背景,公司访问外网有限制,项目组大部分人员不能访问maven的central repository,因此在局域网里找一台有外网权限的机器,搭建nexus私服,然后开发人员连到这台私服上 环 ...
- ubuntu添加桌面或launcher快捷方式
以eclipse为例,自行下载的. 创建文件/usr/share/applications/eclipse-kepler.desktop 文件内容: #------------------------ ...
- VM12安装OS X10.11步骤及说明
参考文献: 1. http://www.crsay.com/network/enable-hardware-based-dep.html 2. http://jingyan.baidu.com/art ...
- SVN修改用户名与密码
由于在svn的界面中并没有为我们提供直接更换用户名密码的地方,所以一旦我们需要更换用户名的就需要自己想一些办法. 解决方案如下: 在Eclipse使用SVN的过程中大多数人往往习惯把访问SVN的用户名 ...
- Postman-进阶
Postman-简单使用 Postman-进阶使用 Postman-CI集成Jenkins 管理请求 保存请求-添加“打开百度首页请求” 设置请求方式为Get,地址为www.baidu.com.点击右 ...
- iOS进阶_三方使用步骤
一.配置环境(:后为在终端输入的命令) 打开终端 查看自己电脑的Ruby环境:gem sources -l 如果环境已经是淘宝镜像了,此时不需要再进行环境的修改. 如果不是,发送gem sources ...
- smartupload 上传与下载(转载)
前台: <form action="uploadimage.jsp" method="post" enctype="multipart/form ...
- 网页中插入FLASH(swf文件)的html代码
一.简单插入flash图像<embed src="你的flash地址.swf"width="300" height="220"> ...
- 用ADMM求解大型机器学习问题
[本文链接:http://www.cnblogs.com/breezedeus/p/3496819.html,转载请注明出处] 从等式约束的最小化问题说起: ...
- STAF no JSTAF in java.library.path 的终极解决办法
最近两天在研究利用STAF 实现程序更新包的自动部署测试.运行Demo代码时遇到一个坑.我的安装路径是默认的.C:\STAF\samples\demo在命令行窗口用执行命令:java STAFDemo ...