方便自己以后用,原文:https://blog.csdn.net/lwwl12/article/details/78472235

直接上代码

public partial class BaseWindow : Window
{
public BaseWindow() : base()
{
this.Closed += Window_Closed;
this.WindowStartupLocation = WindowStartupLocation.CenterOwner;
this.ResizeMode = ResizeMode.NoResize;
} public void SyncComplete()
{
this.Dispatcher.Invoke(() =>
{
MessageBox.Show(this, "操作完成!", "提示");
});
} private void Window_Closed(object sender, EventArgs e)
{
//容器Grid
Grid grid = this.Owner.Content as Grid;
//父级窗体原来的内容
UIElement original = VisualTreeHelper.GetChild(grid, ) as UIElement;
//将父级窗体原来的内容在容器Grid中移除
grid.Children.Remove(original);
//赋给父级窗体
this.Owner.Content = original;
} public bool? ShowDialog(Window owner)
{
//蒙板
Grid layer = new Grid() { Background = new SolidColorBrush(Color.FromArgb(, , , )) };
//父级窗体原来的内容
UIElement original = owner.Content as UIElement;
owner.Content = null;
//容器Grid
Grid container = new Grid();
container.Children.Add(original);//放入原来的内容
container.Children.Add(layer);//在上面放一层蒙板
//将装有原来内容和蒙板的容器赋给父级窗体
owner.Content = container;
this.Owner = owner;
return this.ShowDialog();
}
}

xaml

<local:BaseWindow x:Class="Modules.wnd_TimeSync"
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:Modules"
mc:Ignorable="d" WindowStyle="None" AllowsTransparency="True" Background="Transparent"
Title="wnd_TimeSync" Height="20" Width="220" Closed="Window_Closed" >
<StackPanel>
<ProgressBar Name="pb" Height="20" Width="200" Maximum="100"></ProgressBar>
</StackPanel>
</local:BaseWindow>

使用方法

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
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 Modules
{
/// <summary>
/// wnd_TimeSync.xaml 的交互逻辑
/// </summary>
public partial class wnd_TimeSync : BaseWindow
{
public wnd_TimeSync()
{
InitializeComponent();
} public static void ShowDialog(Window owner)
{
//弹出消息框
wnd_TimeSync box = new wnd_TimeSync();
box.ShowDialog(owner);
}
}
}

wpf遮罩~~~(搬运过来的)的更多相关文章

  1. C# WPF遮罩对话框(Popup Message Overlay/ Dialog Host)

    时间如流水,只能流去不流回! 点赞再看,养成习惯,这是您给我创作的动力! 本文 Dotnet9 https://dotnet9.com 已收录,站长乐于分享dotnet相关技术,比如Winform.W ...

  2. WPF loading遮罩层 LoadingMask

    原文:WPF loading遮罩层 LoadingMask 大家可能很纠结在异步query数据的时候想在wpf程序中显示一个loading的遮罩吧 今天就为大家介绍下遮罩的制作 源码下载 点击此处 先 ...

  3. 【WPF】BusyIndicator做Loading遮罩层

    百度了一下,粗略看了几个国内野人的做法,花了时间看下去感觉不太好用(比如有Loading居然只是作为窗体的一个局部控件的,没法全屏遮罩,那要你有何用?),于是谷歌找轮子去. 好用的轮子:http:// ...

  4. WPF 通过透明度遮罩和变换制作倒影效果

      倒影效果 代码 <Canvas xmlns="http://schemas.microsoft.com/client/2007" xmlns:x="http:/ ...

  5. “WPF老矣,尚能饭否”—且说说WPF今生未来(上):担心

    近日微软公布了最新的WPF路线图,一片热议:对于老牌控件提供商葡萄城来说,这是WPF系列控件一个重要的机遇,因此,Spread Studio for WPF产品做了一次重要更新,并随着Spread S ...

  6. [WPF系列]Adorner应用-自定义控件ImageHotSpot

    引言 项目中有时需要在图片上标注热区,在HTML中有<area>标签,但在WPF中目前还没现成的控件来实现这这一功能.至于图片热区功能有道词典的[图解词典]是个不错的例子,如图1: 图 1 ...

  7. WPF的二维绘图(一)——DrawingContext

    DrawingContext比较类似WinForm中的Graphics 类,是基础的绘图对象,用于绘制各种图形,它主要API有如下几种: 绘图API 绘图API一般形为DrawingXXX系列,常用的 ...

  8. 一个简单WPF登陆界面,包含记住密码,自动登录等功能,简洁美观

    简介:这是一个自己以前用WPF设计的登陆界面,属于一个实验性的界面窗体,如果用于产品还很有不足.但也是有一点学习价值.后台代码略有复杂,但基本上都有注释 分类,略有代码经验的一般都能看懂. 登陆界面外 ...

  9. WPF 截屏软件开发

    最近由于工程需要开始研发基于Windows的自动录屏软件,很多细节很多功能需要处理,毕竟一个完美的录屏软件不是你随随便便就可以写出来的.首先参考了大部分的录屏软件,在研发的过程中遇到了很多的问题:比如 ...

随机推荐

  1. 提取网址的python练习

    import urllib, urllib2, cookielib from HTMLParser import HTMLParser import sys reload(sys) sys.setde ...

  2. 解决/home磁盘空间不足问题

    最近在Linux下做仿真实验,但是渐渐的发现,/home原来分配的空间不足.通过先建硬盘分区,然后挂载到/home文件的方法,在网上查了好多资料 建立分区并挂载分区http://www.se126.c ...

  3. thinkphp5.0 空模块、空控制器、空方法

    空模块 'exception_handle' => function(Exception $e){ // 参数验证错误 if ($e instanceof \think\exception\Va ...

  4. python 字典元素删减

  5. pytorch源码解析:Python层 pytorchmodule源码

    尝试使用了pytorch,相比其他深度学习框架,pytorch显得简洁易懂.花时间读了部分源码,主要结合简单例子带着问题阅读,不涉及源码中C拓展库的实现. 一个简单例子 实现单层softmax二分类, ...

  6. 项目中容易出现的BUG预警

    之前没有记录BUG的习惯导致在同一个坑里边栽了好几次,于是将最近几个项目中遇到的问题整理一下,在进行新项目时预警一遍: 使用携带有搜索功能的分页查询时,注意当用户更改了查询条件但没有点击查询按钮直接点 ...

  7. Mysql 锁表处理

    -- 查看正在被锁定的的表 show ; -- 查看进程号 show processlist; -- 杀掉进程 : -- 表级锁次数 show status like 'Table%'; +----- ...

  8. iphone开发中调用系统打电话功能

    iphone开发中调用打电话功能,一般有2种: 1.系统的打电话代码,不返回当前程序: Java代码 [[UIApplication sharedApplication] openURL:[NSURL ...

  9. H3C TCP连接的拆除

  10. JS遍历数组

    for 如果用var会造成变量声明提前等问题for(var i = 1; i <= arr.length; i++){ console.log(arr[i - 1]);} for(let i = ...