在我的上一篇博客中我写了一个在xamarin的UWP平台下的自定义弹窗控件。在上篇文章中介绍了一种弹窗的写法,但在实际应用中发现了该方法的不足:
1、当弹窗出现后,我们拖动整个窗口大小的时候,弹窗的窗口大小没有随着主窗口大小变化。
2、当弹窗出现时,在我们的主窗口上的后退按钮并没有被弹窗遮罩住,这导致了在弹窗的时候窗口还能返回。
为解决上述问题,我们需更改原来的方式,方法如下:
1、定义一个uwp平台的用户控件
xaml文件代码:
1 <UserControl 2 x:Class="Test.UWP.ExtendControls.UWPHUD" 3 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 4 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 5 xmlns:local="using:Test.UWP.ExtendControls" 6 xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 7 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 8 mc:Ignorable="d" 9 d:DesignHeight="300" 10 d:DesignWidth="400"> 11 12 <Grid Name="mask_grid" Background="{ThemeResource TKHUDColorBrush}" > 13 <Grid Grid.Row="0"> 14 <Border Background="Black" CornerRadius="10" HorizontalAlignment="Center" VerticalAlignment="Center"> 15 <TextBlock Margin="10" Name="msg_Txt" Foreground="White" Text="..." MinWidth="30" ></TextBlock> 16 </Border> 17 </Grid> 18 19 </Grid> 20 </UserControl>