最完美的WPF无边框设计!

news2025/3/15 17:51:20

常规的无边框方法设计

常规的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=

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2315581.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

工作记录 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; 在…

【瞎折腾/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. 环境变量配置 右键【此电脑】→【属性】→【高级…

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

上一篇可扩展的训练技术(二)中&#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…

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

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

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

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

从以太网 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 设置笔记四…

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

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

31.Harmonyos Next仿uv-ui 组件NumberBox 步进器组件异步操作处理

Harmonyos Next仿uv-ui 组件NumberBox 步进器组件异步操作处理 文章目录 Harmonyos Next仿uv-ui 组件NumberBox 步进器组件异步操作处理1. 组件介绍2. 效果展示3. 异步操作处理3.1 异步初始化3.2 异步值更新 4. 完整示例代码5. 知识点讲解5.1 异步操作基础5.2 异步操作中的状态…

mac安装python没有环境变量怎么办?zsh: command not found: python

在mac电脑上,下载Python安装包进行安装之后,在终端中,输入python提示: zsh: command not found: python 一、原因分析 首先,这个问题不是因为python没有安装成功的原因,是因为python安装的时候,没有为我们添加环境变量导致的,所以我们只需要,在.zshrc配置文件中加上环…

使用DeepSeek制作可视化图表和流程图

用DeepSeek来制作可视化图表&#xff0c;搭配python、mermaid、html来实现可视化&#xff0c;我已经测试过好几种场景&#xff0c;都能实现自动化的代码生成&#xff0c;效果还是不错的&#xff0c;流程如下。 统计图表 &#xff08;搭配Matplotlib来做&#xff09; Python中的…

jmeter-sample

jmeter-sample http request:接口测试常用请求参数ParametersBody DataFiles Upload jdbc request配置JDBC Connection Configuration创建JDBC Requst请求 http request:接口测试常用 请求参数 Parameters 常见于get请求&#xff0c;与拼在接口后面是一样的效果&#xff1a;如…