Glass effects in WPF

I was playing with Glass effects in WPF and found following strange effect.

If I make a Window complete transparent (Glass) elements such as Label, TextBox, CheckBox show black text on black background (see picture in archive).

Am I doing something wrong, or is it a bug in WPF or maybe it's a grafik card I have nVidia GeForce FX 5600 265Mb. I use drivers from NVIDIA: Date 19.05.2006, Version 8.8.6.1

In archive is sample project and picture with strange effects taken on my computer.

http://rapidshare.de/files/22269698/GlassWPF.zip.html



Answer this question

Glass effects in WPF

  • Develop3r

    I don't think I'm setting UIElements background to transparent. Only window background

    here is the code:

    public static bool ExtendGlassFrame(Window window, Thickness margin)
    {
    if(!DwmIsCompositionEnabled())
    return false;

    IntPtr hwnd = new WindowInteropHelper(window).Handle;
    if (hwnd == IntPtr.Zero)
    throw new InvalidOperationException("The Window must be shown efore extending gflass.");

    window.Background = Brushes.Transparent;
    HwndSource.FromHwnd(hwnd).CompositionTarget.BackgroundColor = Colors.Transparent;

    MARGINS margins = new MARGINS(margin);
    DwmExtendFrameIntoClientArea(hwnd, ref margins);
    return true;
    }

    struct MARGINS
    {
    public int Left;
    public int Right;
    public int Top;
    public int Bottom;

    public MARGINS(Thickness t)
    {
    Left = (int) t.Left;
    Right = (int) t.Right;
    Top = (int) t.Top;
    Bottom = (int) t.Bottom;
    }
    }

    [DllImport("dwmapi.dll", PreserveSig = false)]
    static extern void DwmExtendFrameIntoClientArea(IntPtr hwnd, ref MARGINS margins);

    [DllImport("dwmapi.dll", PreserveSig = false)]
    static extern bool DwmIsCompositionEnabled();


  • Tolga Erdogus

    Will this only work for Vista
  • Andreas_

    I downloaded, compiled and ran your sample on my machine and I don't see the issue pictured in the included image. I'm running a post-Beta 2 build, so that doesn't necessarily help you right away, but it means there are two pieces of good news:

    1. Your code is right; and
    2. Whatever problem you are seeing now has been fixed, so you can look forward to it working well in a future build.


  • SturnaR

    The Desktop Window Manager (DWM) is a Vista feature.

  • Nibu Thomas

    couldnt access the zip. So i am just guessing here.

    Looks like you are setting the window bvackground to transparent and the UIElements background to transparent which might explain the results you are getting.

    HTH


  • Glass effects in WPF