在无边框 WPF 窗口上启用 Vista 玻璃效果 [英] Enable Vista glass effect on a borderless WPF window

查看:30
本文介绍了在无边框 WPF 窗口上启用 Vista 玻璃效果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了一个附加属性,我可以在窗口上设置它以将玻璃框架扩展到客户区(使用 DwmExtendFrameIntoClientArea API).在大多数情况下它工作正常.现在我希望我的窗口是无边框的,所以我在我的窗口上设置了以下属性:

I wrote an attached property that I can set on a window to extend the glass frame into the client area (using the DwmExtendFrameIntoClientArea API). It works fine in most cases. Now I want my window to be borderless, so I set the following attributes on my window :

    WindowStyle="None"
    ResizeMode="NoResize"
    Background="Transparent"
    u:WinUtil.EnableGlass="True"
    ShowInTaskbar="False"

但是有了这些属性,玻璃根本不显示:我的窗口只有透明背景.如果我将 ResizeMode 设置为 CanResize,则会显示玻璃,但我不希望窗口可以调整大小.

But with these attributes, the glass doesn't show up at all : my window just has a transparent background. If I set ResizeMode to CanResize, the glass is shown, but I don't want the window to be resizable.

我怀疑是因为玻璃效果是通过将非客户端框架扩展到客户端区域获得的:使用 WindowStyle = NoneResizeMode = NoResize,没有非客户端框架,所以没有什么可扩展的.当我启用调整大小时,它会在窗口周围创建一个框架,因此可以扩展该框架.

I suspect it is due to the fact that the glass effect is obtained by extending the non-client frame into the client area : with WindowStyle = None and ResizeMode = NoResize, there is no non-client frame, so there's nothing to extend. When I enable resizing, it creates a frame around the window, so the frame can be extended.

我想应该可以通过设置适当的 WS_* 位来创建一个具有细边框、没有标题栏且无法调整大小的窗口,但我不知道究竟是哪一个

I guess it should be possible to create a window that has a thin border, no title bar, and can't be resized, by setting the appropriate WS_* bits, but I don't know which ones exactly

所以我的问题是:

  1. 应该设置或取消设置哪些样式位以获得所需的外观和行为?
  2. 如何初始化窗口的样式位?Window 类似乎没有 Windows Forms CreateParams 属性之类的东西......在创建句柄后设置这些位是否可以?
  3. 我发现 HwndSource 类可能是问题 2 的答案,但如果您不是 Win32 专家,使用它似乎有点复杂......这会是一个明智的解决方案吗?我的问题?
  1. Which style bits should be set or unset to have the desired appearance and behavior ?
  2. How can I initialize the window's style bits ? The Window class doesn't seem to have anything like Windows Forms CreateParams property... Is it OK to set these bits after the handle has been created ?
  3. I found the HwndSource class that could be an answer to question 2, but it seems a bit complex to use if you're not a Win32 expert... Would it be a sensible solution to my problem ?

欢迎任何建议

推荐答案

您是否尝试过使用 DwmEnableBlurBehindWindow?这使您能够使窗口客户区的特定部分透明.

Have you tried using DwmEnableBlurBehindWindow? This enables you to make a specific part of a window's client area transparent.

这篇关于在无边框 WPF 窗口上启用 Vista 玻璃效果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆