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

Avalonia的自定义边框窗口

Avalonia的无边框窗口

  • 取消系统自带边框
    • 方式1:SystemDecorations
    • 方式2:ExtendClientAreaChromeHints
  • 实现窗口拖拽

在做桌面软件时,我们大部分情况都不会使用系统自带的边框,基本上都是自己定制的。本文在Avalonia中实现自定义边框窗口。

取消系统自带边框

取消系统自带边框,通过设置 Window 的几个属性值即可。主要有以下两种方式:

  1. 方式1:SystemDecorations
  2. 方式2:ExtendClientAreaChromeHints

方式1:SystemDecorations

将Window的SystemDecorations设置为None,即可取消系统自带的Window的所有样式。此时,Window的无法显示关闭、最小化等按钮,无法通过边框拉伸窗口,也无法拖拽窗。

<Window ......SystemDecorations="None">
</Window>

SystemDecorations是个枚举值,可以设置以下3个值:

// 系统边框的样子
// Determines system decorations (title bar, border, etc) for a Avalonia.Controls.Window
public enum SystemDecorations
{// 没有边框// No decorationsNone = 0,// 没有标题栏// Window border without titlebarBorderOnly = 1,// 全部都有// Fully decorated (default)Full = 2
}

方式2:ExtendClientAreaChromeHints

Window的ExtendClientAreaChromeHints是一个枚举值,通过设置它的值来选择系统边框样式。可以设置以下三个值:

// 对于边框样式的类型的描述
// Hint for Window Chrome when ClientArea is Extended.
[Flags]
public enum ExtendClientAreaChromeHints
{// 没有边框// The will be no chrome at all.NoChrome = 0,// 使用系统边框// Use SystemChromeSystemChrome = 1,// 平台默认// The default for the platform.Default = 2,// 优先尝试使用系统边框,在 OSX 中使用 OSX 的边框样式,在 Windows 中使用 Windows 的边框样式。// Use system chrome where possible. OSX system chrome is used, Windows managed// chrome is used. This is because Windows Chrome can not be shown on top of user// content.PreferSystemChrome = 2,// 在 OSX 上,标题框将会是一个更细的工具栏标题框,// 标题栏三色的按钮的位置会比普通样式的要肉眼可见的低一点。// On OSX the titlebar is the thicker toolbar kind. // Causes traffic lights to be positioned slightly lower than normal.OSXThickTitleBar = 8
}

单独使用Window的ExtendClientAreaChromeHints是无效的,需要结合 ExtendClientAreaToDecorationsHint 一起使用。ExtendClientAreaToDecorationsHint为bool值,表示是否将用户内容扩展到系统标题栏里面。

<Window ......ExtendClientAreaToDecorationsHint="True"ExtendClientAreaChromeHints="NoChrome">
</Window>

如上设置这两个值时,窗口的边框和标题栏都不显示了,但窗口还是可以在边缘进行拉伸。如果要取消这个这个拉伸效果,则需要使用到另外一个值:

ExtendClientAreaTitleBarHeightHint="0"

ExtendClientAreaTitleBarHeightHint是描述标题栏的高度属性,标题栏的高度决定标题栏可拖动的地方。如果不希望窗口进行拖动拉伸,将其设置为0即可。

实现窗口拖拽

一般取消了系统自带的边框后,我们还需要自己实现窗口的拖拽的功能。
重新Window的OnPointerPressed方法即可

/// <summary>
/// 拖拽
/// </summary>
/// <param name="e"></param>
protected override void OnPointerPressed(PointerPressedEventArgs e)
{base.OnPointerPressed(e);if (e.GetCurrentPoint(this).Properties.IsLeftButtonPressed){this.BeginMoveDrag(e);}
}
http://www.dtcms.com/a/302467.html

相关文章:

  • React中为甚么强调props的不可变性
  • TMS320F2812PGFA TI:150MHz工业级DSP控制芯片,电机控制专用
  • 腾讯AI IDE
  • 天学网面试 —— 中级前端开发岗位
  • 动/静态库的原理及制作
  • 测试用例设计常用方法
  • MR-link-2:多效性顺式孟德尔随机化分析!
  • Windows 系统分辨率切换** 与 **Qt4 无边框窗口管理机制** 的交互
  • 2025年7月21–28日AI开发周报:新模型、新战略与开源亮点
  • 全新AI工具小程序源码 全开源
  • 北京-4年功能测试2年空窗-报培训班学测开-第六十二天-模拟未通过,继续准备自我介绍项目介绍面试题中
  • java中一些数据结构的转换
  • C++模板元编程从入门到精通
  • 从“PPT动画”到“丝滑如德芙”——uni-app x 动画性能的“终极奥义”
  • 能源智跃:大模型破壁数据孤岛,铸就智能转型新范式
  • ofd文件转pdf
  • 打通视频到AI的第一公里:轻量RTSP服务如何重塑边缘感知入口?
  • InsightFace(RetinaFace + ArcFace)人脸识别项目(预训练模型,鲁棒性很好)
  • 端到端的核心区别点
  • Ubuntu24安装MariaDB/MySQL后不知道root密码如何解决
  • 如何实现任务附件管理功能:ONLYOFFICE协作空间文件选择器集成指南
  • (LeetCode 面试经典 150 题 ) 155. 最小栈 (栈)
  • 【Oracle】数据泵
  • Rk3568-芯片内看门狗
  • Laravel 分页方案整理
  • Apache Kafka实时数据流处理实战指南
  • 稳定币催化下,Web3 支付赛道将迎来哪些爆发?
  • 在 Linux 上进行 Apache Bench 测试
  • Item18:让接口容易被正确使用,不易被误用
  • 修改gitlab默认的语言