Search code examples
wpfwindowsaero-glass

Enable Vista glass effect on a borderless WPF window


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"

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.

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.

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

So my questions are :

  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 ?

Any advice is welcome


Solution

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