WPF 蒙版弹窗(背景层是一个半透明的遮罩蒙版)

蒙版弹窗

        蒙版弹窗是背景层是一个半透明的遮罩蒙版,作用是给用户提供信息的时候,强调弹窗信息,用户需要在关掉弹窗后才能操作其他界面。

代码实现

新建蒙版窗体


    
        
        
            
                
                    
                    
                
                
                
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
{
    /// 
    /// MaskMessagePoump.xaml 的交互逻辑
    /// 
    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;
        }

    }
}

主窗体使用蒙版弹窗


    
        
            
            
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
{
    /// 
    /// MainWindow.xaml 的交互逻辑
    /// 
    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

你可能感兴趣的:(wpf,ui)