views:

42

answers:

1

Why is it that I have to set the WindowStyle property to None on a WPF form to get transparency, but in Winforms I can do it on any form, and retain borders, standard buttons, etc? Clearly the API supports this, so I'm not clear on what's special about WPF that would make this an issue.

I'm guessing that WPF is jumping through some DirectX or OpenGL hoops, while Winforms is just setting the alpha for the window via the API, but I could be way off base.

+2  A: 

Agreed, this is heavy handed:

   private void VerifyConsistencyWithAllowsTransparency(WindowStyle style)
   {
       if (AllowsTransparency && style != WindowStyle.None)
       {
           throw new InvalidOperationException(SR.Get(SRID.MustUseWindowStyleNone));
       }
   }

WPF uses the exact same mechanism to implement this as Windows Forms, layered windows. There is no obvious reason it wouldn't work the same way in WPF. The code snippet, lifted from Window.cs, simply rules it out. There is however one hint from the UsesPerPixelOpacity property:

When you enable per-pixel opacity, the system no longer draws the non-client area. This is because the intended purpose of UsesPerPixelOpacity is to show non-rectangular top-level UI that works in interoperation scenarios, and showing the rectangular non-client area defeats that purpose.

"interoperation scenarios", I guess.

Hans Passant