当前位置: 首页 > article >正文

最完美的WPF无边框设计!

常规的无边框方法设计

常规的WPF无边框设计方法都是通过AllowsTransparency="True"和WindowStyle=“None”,并且使用WindowChrome样式来实现,但是这样会有问题就是,窗体最大化的时候将底部任务栏给挡住了,另外最大化的时候不能拖动窗体。参考这个大佬的设计@ 若汝棋茗 WPF制作无边框窗体、圆角窗体、支持改变大小、拖动分屏等(一)
但是感觉好麻烦啊。

比较完美的无边框设计

参照这个大佬的设计:梦机器工作室。保留了原改生的最小化、最大化、关闭、拖拽、伸缩窗体大小等操作。
在这里插入图片描述
可以看到在设计器内还是保留了默认的WindowStyle。

运行效果

在这里插入图片描述
完整的源码。

资源字典

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:WpfApp1"><Style x:Key="BorderlessButton" TargetType="Button"><Setter Property="Template"><Setter.Value><ControlTemplate TargetType="Button"><Grid Width="{TemplateBinding Width}" Height="{TemplateBinding Height}" Background="{TemplateBinding Background}"><Border x:Name="bg" Background="{StaticResource TransparentColor}" /><Path x:Name="content"Width="{TemplateBinding local:Icon.Width}"Height="{TemplateBinding local:Icon.Height}"Data="{TemplateBinding local:Icon.Geometry}"Fill="{TemplateBinding Foreground}"Stretch="Fill"UseLayoutRounding="True" /></Grid><ControlTemplate.Triggers><Trigger Property="IsMouseOver" Value="True"><Setter TargetName="bg" Property="Background" Value="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=(local:Mouse.OverBackColor)}" /></Trigger><Trigger Property="IsPressed" Value="True"><Setter Property="Opacity" Value="0.8" /></Trigger></ControlTemplate.Triggers></ControlTemplate></Setter.Value></Setter></Style><!--#region 系统窗口--><Style x:Key="BorderlessWindowStyle" TargetType="{x:Type local:BorderlessWindow}"><Setter Property="Template"><Setter.Value><ControlTemplate TargetType="{x:Type local:BorderlessWindow}"><Border Background="{TemplateBinding Background}"BorderBrush="{TemplateBinding BorderBrush}"BorderThickness="{TemplateBinding BorderThickness}"SnapsToDevicePixels="True"><Grid Margin="{TemplateBinding Padding}"><Grid.RowDefinitions><RowDefinition Height="Auto" /><RowDefinition /></Grid.RowDefinitions><AdornerDecorator x:Name="content" Grid.Row="1"><ContentPresenter /></AdornerDecorator><ResizeGrip x:Name="ResizeGrip"Grid.Row="1"Margin="0,0,5,5"HorizontalAlignment="Right"VerticalAlignment="Bottom"IsTabStop="False"Visibility="Collapsed"WindowChrome.ResizeGripDirection="BottomRight" /><Grid Background="{TemplateBinding CaptionBackground}"><Grid.ColumnDefinitions><ColumnDefinition /><ColumnDefinition Width="Auto" /></Grid.ColumnDefinitions><ContentPresenter Content="{TemplateBinding TitleContent}" /><StackPanel Grid.Column="1" Orientation="Horizontal" WindowChrome.IsHitTestVisibleInChrome="True"><!--  最小化按钮  --><Button x:Name="ButtonMin"Width="{TemplateBinding SystemButtonSize}"Height="{TemplateBinding SystemButtonSize}"local:Icon.Geometry="F1M0,6L0,9 9,9 9,6 0,6z"local:Icon.Height="3"local:Mouse.OverBackColor="{TemplateBinding SystemButtonOverColor}"Background="{TemplateBinding SystemButtonColor}"Command="SystemCommands.MinimizeWindowCommand"Foreground="{TemplateBinding SystemButtonForeground}"IsTabStop="False"Style="{StaticResource BorderlessButton}" /><!--  最大化按钮  --><Button x:Name="ButtonMax"Width="{TemplateBinding SystemButtonSize}"Height="{TemplateBinding SystemButtonSize}"local:Icon.Geometry="F1M0,0L0,9 9,9 9,0 0,0 0,3 8,3 8,8 1,8 1,3z"local:Mouse.OverBackColor="{TemplateBinding SystemButtonOverColor}"Background="{TemplateBinding SystemButtonColor}"Command="SystemCommands.MaximizeWindowCommand"Foreground="{TemplateBinding SystemButtonForeground}"IsTabStop="False"Style="{StaticResource BorderlessButton}" /><!--  恢复按钮  --><Button x:Name="ButtonRestore"Width="{TemplateBinding SystemButtonSize}"Height="{TemplateBinding SystemButtonSize}"local:Icon.Geometry="F1M0,10L0,3 3,3 3,0 10,0 10,2 4,2 4,3 7,3 7,6 6,6 6,5 1,5 1,10z M1,10L7,10 7,7 10,7 10,2 9,2 9,6 6,6 6,9 1,9z"local:Mouse.OverBackColor="{TemplateBinding SystemButtonOverColor}"Background="{TemplateBinding SystemButtonColor}"Command="SystemCommands.RestoreWindowCommand"Foreground="{TemplateBinding SystemButtonForeground}"IsTabStop="False"Style="{StaticResource BorderlessButton}" /><!--  关闭窗口按钮  --><Button x:Name="ButtonClose"Width="{TemplateBinding SystemButtonSize}"Height="{TemplateBinding SystemButtonSize}"local:Icon.Geometry="M453.44 512L161.472 220.032a41.408 41.408 0 0 1 58.56-58.56L512 453.44 803.968 161.472a41.408 41.408 0 0 1 58.56 58.56L570.56 512l291.968 291.968a41.408 41.408 0 0 1-58.56 58.56L512 570.56 220.032 862.528a41.408 41.408 0 0 1-58.56-58.56L453.44 512z"local:Mouse.OverBackColor="{TemplateBinding SystemButtonCloseOverColor}"Background="{TemplateBinding SystemButtonColor}"Command="SystemCommands.CloseWindowCommand"Foreground="{TemplateBinding SystemButtonForeground}"IsTabStop="False"Style="{StaticResource BorderlessButton}" /></StackPanel></Grid></Grid></Border><ControlTemplate.Triggers><Trigger Property="FitSystemWindow" Value="True"><Setter TargetName="content" Property="Grid.Row" Value="0" /><Setter TargetName="content" Property="Grid.RowSpan" Value="2" /></Trigger><Trigger Property="WindowState" Value="Maximized"><Setter Property="Padding" Value="8" /><Setter TargetName="ButtonMax" Property="Visibility" Value="Collapsed" /><Setter TargetName="ButtonRestore" Property="Visibility" Value="Visible" /></Trigger><Trigger Property="WindowState" Value="Normal"><Setter TargetName="ButtonMax" Property="Visibility" Value="Visible" /><Setter TargetName="ButtonRestore" Property="Visibility" Value="Collapsed" /></Trigger><Trigger Property="ResizeMode" Value="NoResize"><Setter TargetName="ButtonMin" Property="Visibility" Value="Collapsed" /><Setter TargetName="ButtonMax" Property="Visibility" Value="Collapsed" /><Setter TargetName="ButtonRestore" Property="Visibility" Value="Collapsed" /></Trigger><Trigger Property="ResizeMode" Value="CanMinimize"><Setter TargetName="ButtonMax" Property="Visibility" Value=

相关文章:

最完美的WPF无边框设计!

常规的无边框方法设计 常规的WPF无边框设计方法都是通过AllowsTransparency="True"和WindowStyle=“None”,并且使用WindowChrome样式来实现,但是这样会有问题就是,窗体最大化的时候将底部任务栏给挡住了,另外最大化的时候不能拖动窗体。参考这个大佬的设计@ 若…...

无限使用Typora

下载 Typora https://www.typora.net/#home 安装 找到 /Applications/Typora.app/Contents/Resources/TypeMark/page-dist/static/js/LicenseIndex.180dd4c7.5b0f7af9.chunk.js 文件 打开文件 搜索 e.hasActivated"true"e.hasActivated,修改成 e.hasActivated&…...

工作记录 2017-01-12

序号 工作 相关人员 1 协助BPO进行Billing的工作。 处理Amazing Charts的数据查询。 修改BillingJobPoster&#xff0c;处理CCDA 的自动导入&#xff0c;预计还需一天才能完成。 修改录入Code的界面&#xff08;code 移动到指定位置&#xff09;&#xff0c;预计明天更新。…...

【Linux】从互斥原理到C++ RAII封装实践

&#x1f4e2;博客主页&#xff1a;https://blog.csdn.net/2301_779549673 &#x1f4e2;欢迎点赞 &#x1f44d; 收藏 ⭐留言 &#x1f4dd; 如有错误敬请指正&#xff01; &#x1f4e2;本文由 JohnKi 原创&#xff0c;首发于 CSDN&#x1f649; &#x1f4e2;未来很长&#…...

爬虫案例十三js逆向模拟登录中大网校

提示&#xff1a;文章写完后&#xff0c;目录可以自动生成&#xff0c;如何生成可参考右边的帮助文档 文章目录 前言一、网站分析二、代码 前言 提示&#xff1a;这里可以添加本文要记录的大概内容&#xff1a; js 逆向模拟登录中大网校 提示&#xff1a;以下是本篇文章正文内…...

WPF窗口读取、显示、修改、另存excel文件——CAD c#二次开发

效果如下&#xff1a; using System.Data; using System.IO; using System.Windows; using Microsoft.Win32; using ExcelDataReader; using System.Text; using ClosedXML.Excel;namespace IfoxDemo {public partial class SimpleWindow : Window{public SimpleWindow(){Initi…...

01 | Go 项目开发极速入门课介绍

提示&#xff1a; 所有体系课见专栏&#xff1a;Go 项目开发极速入门实战课。 你好&#xff0c;欢迎学习本课程。本课程是一个 Go 项目开发极速入门课程。旨在帮助刚学习完 Go 基础语法的 Go 开发者&#xff0c;快速掌握如何开发一个功能相对全面的 Go 项目。 根据课程设计目标…...

Spring Cloud LoadBalancer 原理与实践

背景 当前我们的微服务架构基于Spring Cloud Alibaba体系&#xff0c;通过定制NacosRule实现了跨集群访问和灰度发布功能。但随着Spring Cloud与Nacos版本升级&#xff0c;官方已弃用Ribbon转向LoadBalancer&#xff0c;这要求我们完成以下技术升级&#xff1a; 负载均衡机制…...

Vmware下的openEuler

1.下载openEuler操作系统镜像 https://repo.openeuler.org/openEuler-20.03-LTS/ISO/ 2.在VM新建虚拟机 3.虚拟机联网 我是出现了没有网络&#xff0c;ping不通的问题 参考&#xff1a;https://blog.csdn.net/FHY26828/article/details/140941234 修改文件&#xff1a; 在…...

spring security学习入门指引

学习 Spring Security 可以从以下几个方面逐步深入&#xff0c;结合理论与实践&#xff0c;以下是具体的学习路径建议&#xff1a; 1. 基础准备 • 熟悉 Spring 框架&#xff1a; 先掌握 Spring Core、Spring MVC 和 Spring Boot 的基础&#xff0c;理解依赖注入&#xff08;D…...

【瞎折腾/Dify】使用docker离线部署Dify

文章目录 说在前面安装Docker(外网)获取Dify源码(外网)拉取docker镜像(外网)导出镜像(内网)导入镜像(内网)运行问题 说在前面 外网操作系统&#xff1a;windows内网操作系统&#xff1a;ubuntu外网docker desktop版本&#xff1a;4.29.0外网docker版本&#xff1a;version 26.0…...

Java EE Web环境安装

Java EE Web环境安装 一、JDK安装与测试&#xff08;Windows环境&#xff09; 1. 安装JDK 官网下载&#xff1a;Oracle JDK&#xff08;选择Windows x64 Installer&#xff09;双击安装包&#xff0c;按向导完成安装 ​ 2. 环境变量配置 右键【此电脑】→【属性】→【高级…...

Node.js中HTTPS模块应用详解

1. HTTPS 模块的概念 HTTPS&#xff08;Hypertext Transfer Protocol Secure&#xff09;是 HTTP 的安全版本&#xff0c;通过 SSL/TLS 协议对数据进行加密&#xff0c;确保数据在传输过程中不被窃取或篡改。在 Node.js 中&#xff0c;https 模块提供了创建 HTTPS 服务器和客户…...

我测试了AI搜索:试图替代谷歌搜索

随着人工智能工具的不断进步,探讨它们是否能够取代传统搜索引擎如谷歌,已成为一个引人入胜的话题。 有一点是确定的:并非所有的人工智能都可用。它们需要的主要特性是能够访问互联网以获取最新信息,这就排除了Anthropic的Claude。 人工智能在某些方面可以增强或改进谷歌搜…...

大语言模型基础之‘显存优化‘

上一篇可扩展的训练技术(二)中&#xff0c;我们介绍了零冗余优化器&#xff08;Zero Redundancy Optimizer, Zero&#xff09;&#xff0c;该技术由DeepSpeed代码库提出&#xff0c;主要用于解决数据并行中的模型冗余技术&#xff0c;即在数据并行训练中&#xff0c;每个GPU上都…...

【Nexus】Maven 私服搭建以及上传自己的Jar包

Nexus 安装 docker run -d -uroot --name nexus3 --restartalways -p 8081:8081 -v /data/nexus-data/blobs:/nexus-data/blobs -v /etc/localtime:/etc/localtime sonatype/nexus3这里也提供一下docker-composer的方法 .env 文件 VERSIONlatest CONTAINER_NAMECONTAINER_N…...

css模拟雷达扫描动画

<div class"radar-scan"><div class"radar-container" /></div> 样式&#xff1a; .radar-scan {background-image: linear-gradient(0deg,transparent 24%,rgba(32, 255, 77, 0.15) 25%,rgba(32, 255, 77, 0.15) 26%,transparent 27%,…...

冠珠瓷砖×郭培“惟质致美”品质主题片上映,讲述高定艺术背后的致美品质故事

168年前&#xff0c;一位英国服装设计师&#xff0c;开创了「高级定制」的先河。时至今日&#xff0c;从服装到各行各业「高级定制」始终代表着对完美的极致追求&#xff0c;成为了行业至高境界的象征。 被誉为“中国高定第一人”&#xff0c;高级定制服装设计师郭培&#xff0…...

【Java 基础(人话版)】进制转换

进制的简单介绍 整数可以使用四种不同的进制表示方式&#xff1a; 二进制 (Binary)&#xff1a;由 0 和 1 组成&#xff0c;满 2 进 1&#xff0c;以 0b 或 0B 开头表示。十进制 (Decimal)&#xff1a;由 0-9 组成&#xff0c;满 10 进 1&#xff0c;是最常用的数值表示方式。…...

3DS模拟器使用(pc+安卓)+金手指+存档互传

1、引言 3ds模拟器已经能够在手机端近乎完美模拟了&#xff0c;那么多的3ds游戏&#xff0c;比玩手机游戏舒服多了。 本人是精灵宝可梦的老玩家&#xff0c;从第一世代就一直在玩&#xff0c;刚耍完NDS的第五世代&#xff0c;黑白系列。现在到宝可梦XY了&#xff0c;需要在3d…...

SpaceClaim二次开发(4)

目录 第五章 Storing Custom Data &#xff08;存储自定义数据&#xff09; 5.1 文档属性 5.2 自定义属性 5.3 属性传播 第六章 Identifying Objects in ACIS and Parasolid Files&#xff08;识别ACIS和Parasolid文件中的对象&#xff09; 6.1 导出期间的标识符 6.2 导入和…...

Leetcode3340:检查平衡字符串

题目描述&#xff1a; 给你一个仅由数字 0 - 9 组成的字符串 num。如果偶数下标处的数字之和等于奇数下标处的数字之和&#xff0c;则认为该数字字符串是一个 平衡字符串。 如果 num 是一个 平衡字符串&#xff0c;则返回 true&#xff1b;否则&#xff0c;返回 false。 代码…...

Java多线程基石—内存模型

Java Memory Model Java内存模型&#xff08;JMM&#xff09;&#xff0c;定义了线程如何与内存交互及线程间的可见性、有序性和原子性。 JMM屏蔽了各种硬件和操作系统的访问差异&#xff0c;保证Java程序在各种平台下对内存的访问都能保证一致效果。 1 JMM 可见性 一个线程…...

ArcGIS助力水文分析:数据处理、地图制作与流域特征提取

在水文水环境保护中&#xff0c;对于信息的采集、处理和分析是关键步骤。水文水环境及其相关数据均具有空间分布特征&#xff0c;传统的方法难以发挥作用。地理信息系统&#xff08;GIS&#xff09;强大的空间数据管理和分析功能&#xff0c;在空间信息处理上有独到的优势&…...

从以太网 II 到 VLAN 和 Jumbo Frame:数据帧格式解读

以太网数据帧是计算机网络通信的基本单位&#xff0c;在不同的应用场景中&#xff0c;它的格式有所不同。根据协议标准和用途&#xff0c;以太网数据帧主要包括以太网 II 帧、IEEE 802.3 帧、IEEE 802.1Q VLAN 帧等七种主要类型。为了更好地理解以太网的通信机制&#xff0c;我…...

X86 RouterOS 7.18 设置笔记六:端口映射(IPv4、IPv6)及回流问题

X86 j4125 4网口小主机折腾笔记五&#xff1a;PVE安装ROS RouterOS X86 RouterOS 7.18 设置笔记一&#xff1a;基础设置 X86 RouterOS 7.18 设置笔记二&#xff1a;网络基础设置(IPV4) X86 RouterOS 7.18 设置笔记三&#xff1a;防火墙设置(IPV4) X86 RouterOS 7.18 设置笔记四…...

将 IPoIB 驱动修改为仅使用 RC 模式

摘要 本文档详细介绍了将 Linux 内核中的 IPoIB(IP over InfiniBand)驱动修改为仅使用 RC(Reliable Connection,可靠连接)模式,并移除所有与 TCP/IP 和以太网相关部分的方法。通过这些修改,可以优化 IPoIB 驱动以适应特定的高性能计算场景,提高数据传输的可靠性和效率…...

热修复框架Tinker与Robust原理剖析

热修复框架Tinker与Robust原理剖析 一、热修复技术概述 1.1 什么是热修复 热修复&#xff08;Hot Fix&#xff09;是Android平台上的一种动态修复机制&#xff0c;它允许应用在不重新发布版本的情况下&#xff0c;动态修复线上bug。这种技术对于快速修复线上问题、降低用户流…...

69.Harmonyos NEXT图片预览组件应用实践(二):电商、内容与办公场景

温馨提示&#xff1a;本篇博客的详细代码已发布到 git : https://gitcode.com/nutpi/HarmonyosNext 可以下载运行哦&#xff01; Harmonyos NEXT图片预览组件应用实践&#xff08;二&#xff09;&#xff1a;电商、内容与办公场景 文章目录 Harmonyos NEXT图片预览组件应用实践…...

C题库-判断水仙花数

【数据判断】 问题1&#xff1a;判断水仙花数&#xff0c;水仙花数是指一个三位数&#xff0c;其各位数字的立方和等于该数本身。 方法一&#xff1a; #include<stdio.h>int main(void){int num,Bit,Ten,Hundred;printf("Input a number:");scanf("%d&q…...