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 ...
随机推荐
- maven SpringMVC easyUI项目创建
在Eclipse中使用Maven创建SpringMVC项目,项目所需软件及工具可以在官网下载.Maven.Nexus及Eclipse集成Maven等到此配置完毕. 1.Maven创建Web项目. 打开 ...
- PHP对redis操作详解【转】
/*1.Connection*/ $redis = new Redis(); $redis->connect('127.0.0.1',6379,1);//短链接,本地host,端口为6379,超 ...
- hadoop多次搭建后,完整总结(累死宝宝了,搭建了十多遍了)
1.安装JDK1.1上传运用软件FileZilla,将windows上的jdk压缩包放到linux的root目录下 1.2解压jdk #创建文件夹 mkdir /usr/java(不要挂在在" ...
- Android应用:StatusBar状态栏、NavigationBar虚拟按键栏、ActionBar标题栏、Window屏幕内容区域等的宽高
一.屏幕中各种栏目以及屏幕的尺寸 当我们需要计算屏幕中一些元素的高度时,或许需要先获取到屏幕或者各种栏目的高度,下面这个类包含了Status bar状态栏,Navigation bar虚拟按键栏,Ac ...
- WEB响应布局
[15/06月,15] em是相对长度单位.相对于当前对象内文本的字体尺寸.如当前对行内文本的字体尺寸未被人为设置,则相对于浏览器的默认字体尺寸.(引自CSS2.0手册) 任意浏览器的默认字体高都是1 ...
- Xcode调用旧版本库出现Undefined symbols for architecture x86_64: ld: symbol(s) not found for architecture x86_64
问题:Undefined symbols for architecture x86_64: ld: symbol(s) not found for architecture x86_64 问题原因 ...
- 分析Linux内核创建一个新进程的过程
一.原理分析 1.进程的描述 进程控制块PCB——task_struct,为了管理进程,内核必须对每个进程进行清晰的描述,进程描述符提供了内核所需了解的进程信息. struct task_struct ...
- Eclipse中支持js提示
使用eclipse自带的插件,无需另外安装插件,具体步骤如下 1.打开eclipse→Windows→Preferences→Java→Editor→Content Assist 修改Auto Act ...
- Mac OS环境下配置Myeclipse2015的经验
反复测试装了多次,现在把成功安装的方法陈列如下: 1. 相关的资源: (1)下载 myeclipse-2015-stable-2.0-offline-installer-macosx.dmg 链接:h ...
- Sqlite 管理工具收藏
1.SQLite Administrator http://download.orbmu2k.de/files/sqliteadmin.zip 2.SQLite2009Pro-v3.8.3.1 h ...