在我的上一篇博客中我写了一个在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 自定义弹窗的更多相关文章

  1. xamarin UWP设置HUD加载功能

    使用xamarin开发的时候经常用到加载HUD功能,就是我们常见的一个加载中的动作,Android 下使用 AndHUD , iOS 下使用 BTProgressHUD, 这两个在在 NuGet 上都 ...

  2. xamarin UWP中MessageDialog与ContentDialog的区别

    MessageDialog与ContentDialog的异同点解析: 相同点一:都是uwp应用上的一个弹窗控件.都能做为弹出应用. 相异点一:所在命名空间不同,MessageDialog在Window ...

  3. [转]Windows平台下Makefile学习笔记

    Windows平台下Makefile学习笔记(一) 作者:朱金灿 来源:http://blog.csdn.net/clever101 决心学习Makefile,一方面是为了解决编译开源代码时需要跨编译 ...

  4. 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_ ...

  5. node.js平台下,利用cookie实现记住密码登陆(Express+Ejs+Mysql)

    本博文需有node.js+express+mysql入门基础,若基础薄弱,可参考博主的其他几篇node.就是博文: 1.下载Mysql数据库,安装并配置 创建用户表供登录使用: 2.node.js平台 ...

  6. 【VS开发】Windows平台下Makefile学习笔记

    作者:朱金灿 来源:http://blog.csdn.net/clever101 决心学习Makefile,一方面是为了解决编译开源代码时需要跨编译平台的问题(发现一些开源代码已经在使用VS2010开 ...

  7. Caffe介绍与测试及相关Hi35xx平台下caffe yolox的使用参考

    这一篇我大概讲讲Caffe框架下MNIST的实现与基于Hi35xx平台下caffe yolox的运用等,供大家参考 1.Caffe介绍与测试 caffe全称Caffe Convolutional Ar ...

  8. ExtJs基础知识总结:自定义弹窗和ComboBox自动联想加载(四)

    概述 Extjs弹窗可以分为消息弹窗.对话框,这些弹窗的方式ExtJs自带的Ext.Msg.alert就已经可以满足简单消息提示,但是相对复杂的提示,比如如何将Ext.grid.Panel的控件显示嵌 ...

  9. xamarin UWP证书问题汇总

    打算开发一个软件使用rsa加密的东西,所以有用到数字证书这块,最近遇到些问题, 问题一:使用如下代码添加数字证书后,在证书管理器的当前用户和本地计算机下都找不到这张证书. using (X509Sto ...

随机推荐

  1. Spring mvc 中使用ftl引用共通文件出错 FreeMarker template error: Error reading included file "/WEB-INF/ftl/common/errormessage.ftl"

    初次接触spring mvc,想做一个小的练习项目,结果在ftl文件中引用其它的共通ftl文件时出错.

  2. 【Java源码分析】LinkedList类

    LinkedList<E> 源码解读 继承AbstractSequentialList<E> 实现List<E>, Deque<E>, Cloneabl ...

  3. c#利用WebClient和WebRequest获取网页源代码的比较

    前几天举例分析了用asp+xmlhttp获取网页源代码的方法,但c#中一般是可以利用WebClient类和WebRequest类获取网页源代码.下面分别说明这两种方法的实现. WebClient类获取 ...

  4. ubuntu 下安装boost库

    ubuntu下安装boost库,,在网上试了一些其他人推荐的libboost-dev 但是会缺少,编译程序会报错: /usr/bin/ld: cannot find -lboost_serializa ...

  5. Linux下Chrome浏览器不支持WebGL的解决方式。

    今天使用Chrome浏览器,总是报这样一个错误: Uncaught TypeError: Cannot read property 'canvas' of null. 细看之下是无法获取WebGL上下 ...

  6. shell循环

    for循环 for循环一般格式为: for 变量 in 列表 do command1 command2 ... commandN done 列表是一组值(数字.字符串等)组成的序列,每个值通过空格分隔 ...

  7. 《python核心编程》笔记——系统限制

    输出当前系统关于数字的范围 import sys l = {} maxint = sys.maxint minint = -maxint maxlong = sys.maxsize minlong = ...

  8. Alpha、Beta、RC、GA版本的区别 ZT

    http://www.blogjava.net/RomulusW/archive/2008/05/04/197985.html Alpha:是内部测试版,一般不向外部发布,会有很多Bug.一般只有测试 ...

  9. c#dataGridView奇偶数行变色

    dataGridView_Performance.RowsDefaultCellStyle.BackColor = Color.Bisque; dataGridView_Performance.Alt ...

  10. [转]c++中vector的使用

    C++中的vector使用范例 一.概述 vector是C++标准模板库中的部分内容,它是一个多功能的,能够操作多种数据结构和算法的模板类和函数库.vector是一个容器,它能够存放各种类型的对象,简 ...