开发者

Window transparency in WPF vs Winforms

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? Cle开发者_JAVA技巧arly 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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜