How to make a window transparent?

I tried setting the Window.Background value to an argb value, but the opacity bits (a values) seem to be ignored

Background="#00000000" - white background

Background="#00FFFFFF" - black background

The a values are honored in all the other elements Grids, Canvases, etc. in the application




Answer this question

How to make a window transparent?

  • Susan Entwisle

    Wpf does not support Window Transparency out of the box. You have to create a hwndSource and set UsesPerPixelOpacity before creating the window.

  • Steve4125

    Use PerPixels Opacity.

    Example shown here:

    http://blogs.msdn.com/llobo/archive/2006/02/24/538757.aspx


  • memnoch

    edit:  Misunderstood, I think
  • gsylvest

    I'm not creating the Window in code, just using XAML. I tried setting the property of the Window in XAML, but receive the following error.

    Error 4 'UsesPerPixelOpacity' property tag does not exist in XML namespace 'http://schemas.microsoft.com/winfx/2006/xaml/presentation'.

    I don't see it exposed as a property via Intellisense either.

    Using MAY CTP. Please advise.



  • gpalmer43

    While Wpf uses hardware acceleration it is not possible to make the Wpf Windows transparent. The Windows Desktop is rendered by GDI+ which is not compatible with Wpf's render engine.

    When you enable UserPerPixelTransparency you lose wpf's hardware acceleration features and the ui is rendered in software mode. This enables you to make the window transparent to the desktop.



  • Arvind2004

    Hope you're wrong, but I think you're right.

    The Opacity property does effect the rendering of the window, but then there is nothing but black where the window used to be rather than a transparent view of the underlying screen elements.

    I'll have to look into your suggestion with hwndSource and UsesPerPixelOpacity.

    Thanks

    NIK



  • How to make a window transparent?