Zeke Xiao

Zeke Xiao

github

Windows 11 Snap Layouts WPF 支持进展

Init 2022/1/13
update 2023/8/11

WPF 使用 WindowChrome 后需要自己处理最大最小化但是无法触发 Windows 11 的 Snap Layouts 功能,现在主要的解决方案就是劫持 WM_NCHITTEST 事件,返回 HTMAXBUTTON = 9,目前我在 .net framework 4.5.2 上是无法完美解决,只有在全屏的时候才会调出 Snap Layouts,可能和另一个 Windows 的 Size 事件有关暂时原因未知

鼠标 HitTest 事件 WM_NCHITTEST 消息 (Winuser.h) - Win32 apps | Microsoft Docs

1. Should WPF add the new theme for Windows11 style? · Issue #4749 · dotnet/wpf (github.com)

2. Add support for Windows 11 "Snap Layout" to the custom title bar (WindowChrome) · Issue #4825 · dotnet/wpf (github.com)

  1. MahApps Windows 11 integration · Issue #4140 · MahApps/MahApps.Metro (github.com)

  2. ControlzEx 已经添加支持 https://github.com/ControlzEx/ControlzEx/pull/151
    重写了 NCHITTEST 这个应该就是最终解决方案了:https://github.com/ControlzEx/ControlzEx/blob/bd307541058cd21abed7b3d4553d24dfd05ad52f/src/ControlzEx/Behaviors/WindowChrome/WindowChromeBehavior.MessageHandling.cs#L442C33-L442C33


其它项目,electorn 最新版本已经支持,Firefox 看起来没打算做 Firefox 在 stable 94 中增加了支持,UWP 原生就可以。

Electorn feat: enable windows control overlay on Windows by mlaurencin · Pull Request #29600 · electron/electron (github.com)

VSCode VS Code's maximize button doesn't trigger Snap Layouts in Windows 11 · Issue #127449 · microsoft/vscode (github.com)

Firefox 1718629 - Windows 11 Snap Layouts menu doesn't appear while hovering (mozilla.org)

Windows Terminal Snap Layouts Support: WM_NCHITTEST should return HTMAXBUTTON, HTMINBUTTON, ... for caption buttons · Issue #9443 · microsoft/terminal (github.com)

UWP 自定义标题栏 Window.SetTitleBar(UIElement) Method (Windows.UI.Xaml) - Windows UWP applications | Microsoft Docs

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.