蒙版弹窗
蒙版弹窗是背景层是一个半透明的遮罩蒙版,作用是给用户提供信息的时候,强调弹窗信息,用户需要在关掉弹窗后才能操作其他界面。
代码实现
新建蒙版窗体
<Window x:Class="MaskPoumpDemo.MaskMessagePoump"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:MaskPoumpDemo"
mc:Ignorable="d"
Title="MaskMessagePoump" Height="450" Width="800"
ShowInTaskbar="False" WindowStyle="None" AllowsTransparency="True" Background="{x:Null}"
Loaded="Window_Loaded" >
<Grid>
<Border x:Name="backBorder" Background="#181818" Opacity="0.3" CornerRadius="6" />
<Border Height="300" Width="400" CornerRadius="6" Background="PaleGreen">
<Grid>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<TextBlock Text="欢迎来到新世界!" FontSize="30" HorizontalAlignment="Center" VerticalAlignment="Center"/>
<Button x:Name="btnGo" Content="开启" Click="btnGo_Click" FontSize="18" Width="100" Height="30" Grid.Row="1"/>
</Grid>
</Border>
</Grid>
</Window>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace MaskPoumpDemo
{
/// <summary>
/// MaskMessagePoump.xaml 的交互逻辑
/// </summary>
public partial class MaskMessagePoump : Window
{
public MaskMessagePoump()
{
InitializeComponent();
}
public MaskMessagePoump(Window win)
{
InitializeComponent();
this.Width = win.ActualWidth;
this.Height = win.ActualHeight;
this.Left = win.Left;
this.Top = win.Top;
}
private void btnGo_Click(object sender, RoutedEventArgs e)
{
DialogResult = true;
}
}
}
主窗体使用蒙版弹窗
<Window x:Class="MaskPoumpDemo.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:MaskPoumpDemo"
mc:Ignorable="d" WindowStyle="None" AllowsTransparency="True" Background="{x:Null}"
Title="MainWindow" Height="450" Width="800" WindowStartupLocation="CenterScreen">
<Border Background="LightSkyBlue" CornerRadius="8" MouseLeftButtonDown="Border_MouseLeftButtonDown">
<Grid>
<TextBlock Text="主窗体上显示蒙版弹窗" FontSize="30" Foreground="White" Margin="20"/>
<Button x:Name="btnMessage" Content="显示蒙版弹窗" Click="btnMessage_Click" Width="120" Height="40"/>
</Grid>
</Border>
</Window>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace MaskPoumpDemo
{
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void btnMessage_Click(object sender, RoutedEventArgs e)
{
new MaskMessagePoump(this).ShowDialog();
}
private void Border_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
if (e.LeftButton == MouseButtonState.Pressed)
{
this.DragMove();
}
}
}
}
实例链接:https://download.csdn.net/download/lvxingzhe3/88683471?spm=1001.2014.3001.5503