当前位置: 首页 > 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.lryc.cn/news/602718.html

相关文章:

  • opencv 模块裁剪 按需安装指定模块
  • 火线、零线、地线
  • ICPC 2024 网络赛(I)
  • 网络与信息安全有哪些岗位:(3)安全运维工程师
  • C++算法实例精讲
  • Solidity基础(教程④-ERC-4626收益金库)
  • nvim编辑器
  • unisS5800XP-G交换机配置命令之登录篇
  • Parasoft Virtualize用服务虚拟化加速银行系统的软件测试
  • uni-app switch(开关选择器) BUG
  • [免费]【NLP舆情分析】基于python微博舆情分析可视化系统(flask+pandas+echarts)【论文+源码+SQL脚本】
  • 从像素到频率:OpenCV傅里叶变换
  • Java面试宝典:MySQL事务和事务的隔离级别
  • map循环遍历
  • 学习 字节UI TARS GUI Agent
  • 为什么bert是双向transformer
  • 无人机气动设计模块解析
  • html转word下载
  • NVDB-CAVD 杯汽车信息安全系列赛事
  • 基于Java的汽车商城系统设计与实现
  • 汽车膨胀水箱(副水箱)液位传感器的作用
  • 小鹏汽车AI测试
  • stm32开发 -- TFTLCD相关
  • API产品升级丨全知科技发布「知影-API风险监测平台」:以AI重构企业数据接口安全治理新范式
  • JavaWeb 入门:HTML 基础与实战详解(Java 开发者视角)
  • 分数函数的实用性及与数据密度的关系解析
  • ffmpeg-7.1.1 下载安装 windows 版,MP4 转 m3u8 切片,遇到报错 Unrecognized option ‘vbsf‘的解决办法
  • SD卡简介与驱动开发
  • 优测推出HarmonyOS全场景测试服务,解锁分布式场景应用卓越品质!
  • Makefile if语句用法