时间如流水,只能流去不流回!

点赞再看,养成习惯,这是您给我创作的动力!

本文 Dotnet9 https://dotnet9.com 已收录,站长乐于分享dotnet相关技术,比如Winform、WPF、ASP.NET Core、Xamarin.Forms等,亦有C++桌面相关的Qt Quick和Qt Widgets等,只分享自己熟悉的、自己会的。

阅读导航:

  • 一、先看效果
  • 二、本文背景
  • 三、代码实现
  • 四、文章参考
  • 五、代码下载

一、先看效果

二、本文背景

YouTube  Design com WPF 大神处习得,常用的遮罩对话框实现,使用的开源 C# WPF控件库 MaterialDesignInXAML ,本站曾有介绍:开源C# WPF控件库《MaterialDesignInXAML》

三、代码实现

3.1 添加Nuget库

站长使用.Net Core 3.1创建的WPF工程,创建“ScreenOverlayMessage”解决方案后,需要添加两个Nuget库:MaterialDesignThemes和MaterialDesignColors,上图的效果是使用该控件库实现的,非常强大。

3.2 工程结构

不需要截图,只修改了两个文件,App.xaml添加MD控件4个样式文件,MainWindow主窗口实现效果。

3.3 App.xaml引入MD控件样式

<Application x:Class="DropDownMenu.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:DropDownMenu"
StartupUri="MainWindow.xaml">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Light.xaml"/>
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Defaults.xaml"/>
<ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Primary/MaterialDesignColor.Blue.xaml"/>
<ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Accent/MaterialDesignColor.Indigo.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>

3.4 主窗体

MainWindow.xaml,整体布局,看上图加上下面的界面代码,添加界面左上角logo图标、左侧导航菜单等,下面即是全部代码。

<Window x:Class="ScreenOverlayMessage.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:ScreenOverlayMessage"
mc:Ignorable="d"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes" MouseDown="Window_MouseDown"
Title="MainWindow" Height="576" Width="1024" ResizeMode="NoResize" WindowStartupLocation="CenterScreen" WindowStyle="None" Background="#FF423A3A">
<Grid>
<materialDesign:DialogHost BorderBrush="{DynamicResource MaterialDesignDivider}">
<materialDesign:DialogHost.DialogContent>
<Grid Width="300" Height="150" HorizontalAlignment="Center">
<StackPanel Orientation="Horizontal" Margin="15">
<materialDesign:PackIcon Kind="Folder" Foreground="{StaticResource PrimaryHueMidBrush}" Width="50" Height="50"/>
<TextBlock Foreground="Gray" Width="200" Margin="15 5" TextWrapping="Wrap">
允许应用程序访问您计算机上的照片、媒体和文件?
</TextBlock>
</StackPanel>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" VerticalAlignment="Bottom" Margin="15">
<Button Command="{x:Static materialDesign:DialogHost.CloseDialogCommand}" Style="{DynamicResource MaterialDesignFlatButton}" Margin="4" VerticalAlignment="Center">
拒绝
</Button>
<Button Command="{x:Static materialDesign:DialogHost.CloseDialogCommand}" Style="{DynamicResource MaterialDesignFlatButton}" Margin="4" VerticalAlignment="Center">
允许
</Button>
</StackPanel>
</Grid>
</materialDesign:DialogHost.DialogContent>
<Grid>
<StackPanel Width="200" HorizontalAlignment="Left" Background="#FF472076">
<Grid Height="150" Background="White">
<Image Source="https://img.dotnet9.com/logo.png"/>
</Grid>
<Button Style="{StaticResource MaterialDesignFlatButton}" Command="{x:Static materialDesign:DialogHost.OpenDialogCommand}">
<StackPanel Orientation="Horizontal" Height="30">
<materialDesign:PackIcon Kind="PhotoAlbum" Width="20" Height="20" VerticalAlignment="Center"/>
<TextBlock Text="照片" Margin="20 0" FontSize="15" VerticalAlignment="Center"/>
</StackPanel>
</Button>
<Button Style="{StaticResource MaterialDesignFlatButton}" Command="{x:Static materialDesign:DialogHost.OpenDialogCommand}">
<StackPanel Orientation="Horizontal" Height="30">
<materialDesign:PackIcon Kind="Music" Width="20" Height="20" VerticalAlignment="Center"/>
<TextBlock Text="音乐" Margin="20 0" FontSize="15" VerticalAlignment="Center"/>
</StackPanel>
</Button>
</StackPanel>
</Grid>
</materialDesign:DialogHost>
</Grid>
</Window>

重点讲解:

  • materialDesign:DialogHost:设置遮罩对话框覆盖的地方,即弹出遮罩对话框后,背后有阴影的位置。
  • materialDesign:DialogHost.DialogContent:对话框内容,即弹出的对话框配置

后台有个拖动窗体代码:

private void Window_MouseDown(object sender, MouseButtonEventArgs e)
{
DragMove();
}

四、文章参考

建议直接打开大神视频学习,他的YouTube上还有很多代码视频哦,参考:
参考视频: Design com WPF: https://www.youtube.com/watch?v=Dwi9o3K73XM

五、代码下载

文章中代码已经全部贴出。

除非注明,文章均由 Dotnet9 整理发布,欢迎转载。

转载请注明本文地址:https://dotnet9.com/6769.html

欢迎扫描下方二维码关注 Dotnet9 的微信公众号,本站会及时推送最新技术文章(微信公众号“dotnet9_com”):

如有收获,请大力转发,给Dotnet9赞助和支持,谢谢大家对dotnet技术的关注和支持 。

C# WPF遮罩对话框(Popup Message Overlay/ Dialog Host)的更多相关文章

  1. Angular 学习笔记 (动态组件 & Material Overlay & Dialog 分析)

    更新: 2019-11-24  dialog vs router link refer : https://stackoverflow.com/questions/51821766/angular-m ...

  2. java.sql.SQLException: null, message from server: “Host ‘xxx’ is not allowed to connect

    java.sql.SQLException: null, message from server: “Host ‘xxx’ is not allowed to connect 2014年06月29日  ...

  3. Could not create pool connection. The DBMS driver exception was: null, message from server: "Host '192.168.XX.XX' is blocked because of many connection errors; unblock with 'mysqladmin flush-hosts'

    早上打开浏览器准备登陆某个系统,发现Error 404--Not Found,有点奇怪,这个服务器应该没人用了才对,然后到weblogic后台去看日志,报如下错误: "Could not c ...

  4. Mysql报错java.sql.SQLException:null,message from server:"Host '27,45,38,132' is not allowed to connect

    Mysql报错java.sql.SQLException:null,message from server:"Host '27,45,38,132' is not allowed to co ...

  5. java.sql.SQLException: null, message from server: "Host 'xxx' is not allowed to connect to this MySQL server"

    java.sql.SQLException: null,  message from server: "Host 'xxx' is not allowed to connect to thi ...

  6. message from server: "Host '192.168.6.68' is blocked because of many connection errors; unblock with 'mysqladmin flush-hosts

    系统或者程序连接数据报错 null, message from server: "Host '192.168.6.68' is blocked because of many connect ...

  7. Cannot create PoolableConnectionFactory (null, message from server: "Host 'admin-PC' is not allowed to connect to this MySQL server")

    1.别人在用自己的tomcat访问我留的查询接口时,出现Cannot create PoolableConnectionFactory (null,  message from server: &qu ...

  8. matlab GUI之常用对话框(三)-- dialog \ errordlg \ warndlg \ helpdlg \ msgbox \questdlg

    常用的对话框(三) 1.普通对话框  dialog 调用格式: h=dialog('PropertyName','PropertyValue'......) %普通对话框 h=dialog( ]); ...

  9. 2000条你应知的WPF小姿势 基础篇<78-81 Dialog/Location/WPF设备无关性>

    在正文开始之前需要介绍一个人:Sean Sexton. 来自明尼苏达双城的软件工程师.最为出色的是他维护了两个博客:2,000ThingsYou Should Know About C# 和 2,00 ...

随机推荐

  1. 连接数据库的方法---ODBC

    2012-12-10 11:50 (分类:计算机程序) 技术博客,对抗遗忘…… 1.ODBC   Open Database Connectivity    1.1 简介:提供了一组对数据库访问的标准 ...

  2. PHP 安装扩展步骤

    一般来说php安装扩展需要几下几个步骤   1.下载扩展包    比如  pdo_mysql.tar.gz  (如果不想下载,可以到php安装目录,(类似php-5.3.3/ext/)的ext文件中找 ...

  3. phpstorm设置debug调试

    先去下载xdebug.dll文件.将下面自己的phpinfo的文字信息复制到https://xdebug.org/wizard.php中,下载它提供的xdebug.dll的版本 下载完成后将php_x ...

  4. 关于ETH/BTC区块的监控

    此次我写的是一个小型的shell, 链接钉钉的机器人, 使用过的应该会比较娴熟的了,下面就简述一下把 主要的功能就是, 当发现本地数据库区块跟网络上的区块差距相差较大的时候就代表, 数据同步有问题, ...

  5. 【idea激活码】,【WebStorm激活码】,【DataGrip激活码】,【IntelliJ 全家桶系列】,【定期更新】,【第一期】

    IntelliJ IDEA.PyCharm.PhpStorm.WebStorm.RubyMide.AppCode.CLion.GoLand.DataGrip.Rider.Android Studio可 ...

  6. Python3.7+Pycharm+cuda10.0+tensorflow GPU版本 安装

    处理器:I5-7500 显卡   :GTX1050Ti 系统   :Win10 1. 首先搭建Python环境. 官网https://www.python.org/downloads/下载Python ...

  7. C#里面低消耗获取当前时间的思路

    Linux下有vsyscall来优化一些例如time(NULL), gettimeofday这种调用的消耗; 但是Windows下, 没有类似的东西, 但是思路还是有的 1. 程序启动的时候, 获取一 ...

  8. Java基础之五、Java编程思想(1-7)

    一.对象导论 1:多态的可互换对象 面向对象程序设计语言使用了后期绑定的概念. 当向对象发送消息时,被调用的代码直到运行时才能确定.也叫动态绑定. 2:单根继承结构 所有的类最终都继承自单一的基类,这 ...

  9. Xilinx FPGA控制器的Everspin STT-DDR4设计指南

    自旋转移扭矩磁阻随机存取存储器(STT-MRAM)是一种持久性存储技术,可利用各种工业标准接口提供性能,持久性和耐用性. Everspin推出了STT-MRAM产品,该产品利用称为JE-DDR4的JE ...

  10. 简单的OO ALV显示ALV及下载

    REPORT OO_ALV. CLASS OO_ALV DEFINITION. PUBLIC SECTION. METHODS:GET_DATA IMPORTING AMOUNT TYPE I,&qu ...