SoFunction
Updated on 2025-04-11

Solve the Airspace issue in WPF

The airspace problem is caused by the difference between Winform and WPF in the underlying rendering mechanism. In most cases, developers encounter such problems in order to implement irregular forms and host Winform controls. When the WPF form is set to allow transparency (that is, AllowsTransparency=True), Winform Control will not display. In order to avoid this problem, many UI frameworks use Win32 API to implement some special effects of irregular forms, such as transparency, rounded corners, etc., so that the AllowsTransparency property of the WPF window can be set to FALSE, thereby bypassing the airspace problem. However, for students who have not been exposed to the underlying Window development, the development cost will be relatively high. In some special cases, when AllowsTransparency must be set to True, how to solve it?

  • The first and most common method on the Internet, simply put, is embedded form, so this method will not be explained.
  • The second method is also my solution to this problem, using a third-party library to solve the problem of airspace

Use third-party libraries to solve airspace problems

(
/
), this library is also written in its project introduction

Mitigating "airspace" issues in WPF applications.

It may be seen that this library cannot perfectly solve the problem of airspace, and we can only wait for Microsoft to improve this problem.

Taking the powerful WebBrower in Winform as an example, let’s briefly talk about how to use it:

  • Create a new WPF form project and add a reference with .
  • Add statement to xmlns:airspace="clr-namespace:;assembly="
<airspace:AirspaceDecorator AirspaceMode="Redirect" IsInputRedirectionEnabled="True" IsOutputRedirectionEnabled="True">
    <WindowsFormsHost Name="FormsHost">
      <winform:WebBrowser/>
    </WindowsFormsHost>
</airspace:AirspaceDecorator>

The above is the solution to the WPF airspace issue introduced by the editor. I hope it will be helpful to everyone. If you have any questions, please leave me a message and the editor will reply to everyone in time. Thank you very much for your support for my website!