Solve the spatial domain problem in WPF of Airspace issuse

  • 2021-09-20 19:49:03
  • OfStack

The spatial domain problem is caused by the difference in the underlying rendering mechanism between Winform and WPF. In most cases, developers encounter this kind of problem when they want 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 be displayed. In order to avoid this problem, many UI frameworks use Win32 API to realize some special effects of irregular forms, such as transparency and rounded corners, so that the AllowsTransparency attribute of WPF window can be set to FALSE, thus bypassing the spatial domain problem. However, for students who have not been exposed to the underlying development of Window, the development cost will be relatively high, and under some special circumstances, when AllowsTransparency must be set as True, how to solve it?

The first method, which is also the most common method on the network, is simply to put it in the form, so this method will not be explained again. The second is also my way to solve this problem, using the third party library to solve the airspace problem

Solving airspace problems by using the third square library

Microsoft.DwayneNeed(
https://microsoftdwayneneed.codeplex.com/
), which is also written in its project introduction


Mitigating "airspace" issues in WPF applications.

It may be seen that this library can't solve the airspace problem perfectly, and it can only wait for Microsoft to improve this problem.

Take the powerful WebBrower in Winform as an example, and simply say how to use it:

Create a new WPF form project and add references to Microsoft. DwayneNeed. dll and Microsoft. DwayneNeed. Win32.dll Add xmlns: airspace= "clr-namespace: Microsoft. DwayneNeed. Interop; Statement of "assembly = Microsoft. DwayneNeed"

<airspace:AirspaceDecorator AirspaceMode="Redirect" IsInputRedirectionEnabled="True" IsOutputRedirectionEnabled="True">
    <WindowsFormsHost Name="FormsHost">
      <winform:WebBrowser/>
    </WindowsFormsHost>
</airspace:AirspaceDecorator>

Related articles: