transparent windows in WPF.. please make them small :)

Jaime Rodriguez
On Windows Phone, Windows Presentation Foundation, Silverlight and Windows 7

transparent windows in WPF.. please make them small :)

  • Comments 0

A feature that the WPF team added late to WPF was the ability to allow transparent windows ( property is Window.AllowsTransparency).
This feature was requested by customers because it allows you to create cool non-rectangular or semi transparent windows.. 
Lauren has sample for creating one here

When we first released the feature, it was not clear if we were going to hardware accelerate it or not...  (see Nick's post
After that, we found out that
1) Hardware Acceleration would not work in Windows XP [due to a DirectX issue] .. See Seema's post ...
2)  Seema also posted that layered windows were also sluggish in Vista..

The second one is the point that I missed and affects two of my projects who were targetting Vista...     

So, here is my high-level advise around transparent windows.
1) Make them small...    popups, menus, etc.. specially if using static content is likely appropriate..
2) Please no top level windows ....    every thing in your window's visual tree will be rendered in software.. that can add up quickly..
3) If on Vista, please don't use transparent windows for Video Players (yes, stinks because most video players are non-rectangular) .. playing video benefits  from hardware accelaration..  I tested it yesterday and doing pure software rendering I was getting 15fps in a non-too-beefy  laptop..  with hardware acceleration enabled I was getting 3 fps.. [yes that is right, hardware was a lot slower, that was the point of Seema's blog]...    with out transparency, I see 60 fps..  
The other tricky part with Vista, is that you run in perforator and it tells you "you are getting hardware accelaration".. because technically you are, and most people don't think about the WDDM/GDI bitblit that Seema explains...   

On a positive note, while discussing/researching this issue, I found this great msdn jewel Graphics Registry settings for rendering wpf..  which I booked marked cause it is useful for debugging ... :)

 "With great power comes great responsibility", use transparent (or layered) windows wisely..