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 ...
随机推荐
- STL的迭代器和类型萃取
今天就可以把STL库中迭代器的实现,和类型萃取好好整理一下了 迭代器的设计思维是STL的关键所在,在STL的实际运用和泛型思维,迭代器都扮演着十分重要的角色,STL力求把数据容器和算法的概念分开来,于 ...
- the fifth class
1.实际比背景长,怎么做到的? 2个父级一个做头背景一个做尾背景 2.2层,每次自带背景上下是覆盖关系,如何做到 2层?,子浮动 3.标签 4.border可覆盖:margin-bottom 为负 ...
- 在64位windows下使用instsrv.exe和srvany.exe创建windows服务[转]
本文转自:https://www.iflym.com/index.php/computer-use/201205020001.html 在32位的windows下,包括windows7,windows ...
- UDP 一个封锁操作被对 WSACancelBlockingCall 的调用中断
using System; using System.Collections.Generic; using System.Text; using System.Net.Sockets; using S ...
- UIAlertController的使用
在iOS8中,苹果对UIAlertView和UIActionSheet进行了重新的封装,成为适应性更强,灵活性更高的UIAlertController.具体使用方法如下. UIAlertControl ...
- Mac下git命令自动补全
当我第一次在mac上安装git,[tab]补全装成功了,但是我没有记录,当我过一段时间在重装的时候,我已经忘记了,又是各种查资料,再次做一下简单的记录. 首先,我因为还是mac小白,所以使用Homeb ...
- java代码中获取classpath路径
Javaweb工程中,有时候需要自己手动的去读取classpath下面的配置文件,这里总结一点读取classpath路径的方法,分享一下. 方法一: String path = Test.class. ...
- [转]WinForms GridListEditor - How to restore values in the auto filter row
http://dennisgaravsky.blogspot.hk/2016/05/winforms-gridlisteditor-how-to-restore.html using System; ...
- solr&lucene3.6.0源码解析(四)
本文要描述的是solr的查询插件,该查询插件目的用于生成Lucene的查询Query,类似于查询条件表达式,与solr查询插件相关UML类图如下: 如果我们强行将上面的类图纳入某种设计模式语言的话,本 ...
- java-多线程新特性
Java定时器相关Timer和TimerTask类 每个Timer对象相对应的是单个后台线程,用于顺序地执行所有计时器任务TimerTask对象. Timer有两种执行任务的模式,最常用的是sched ...