Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WindowsFormsHost on MetroWindow #1093

Closed
ghiboz opened this issue Feb 26, 2014 · 5 comments
Closed

WindowsFormsHost on MetroWindow #1093

ghiboz opened this issue Feb 26, 2014 · 5 comments

Comments

@ghiboz
Copy link

ghiboz commented Feb 26, 2014

Hi again,
I have in my MetroWindow a WindowsFormsHost where inside I add a System.Windows.Forms.Panel, this due I need to render a thing inside and I need a handle.
i'm upgrading MahApps, in the 0.10.1.1 everything works fine, now with 0.12.1.0 the panel is not shown... where may be the issue?
thanks

@AzureKitsune
Copy link
Member

We covered this issue on our FAQ page:

  1. Why is so-and-so WinForms control invisible or not rendering? Why the WebBrowser (or other control) covering my flyout (or another control)? [AIRSPACE]

What you are facing is an issue colloquially called the Airspace issue. Due to the different underlying graphical engines used in WinForms (GDI) and WPF (DirectX and such), there are some interop issues. Sometimes, your controls appear will be invisible. Sometimes, your WinForms control may overlap your WPF controls.

It is important to know that this is an WPF issue, not a MahApps.Metro one. The bug is caused by the Window's AllowsTransparency property.

By default, the vanilla Window class has AllowsTransparency set to false. MahApps.Metro's MetroWindow has it set to true.

Solution 1

One solution to the Airspace issue is to simply set AllowsTransparency to false.

<i:Interaction.Behaviors>
        <Behaviours:BorderlessWindowBehavior AllowsTransparency="False"/>
</i:Interaction.Behaviors>

Solution 2

The second solution, should for some reason that you need AllowsTransparency to be set to true is:

  • Go to https://microsoftdwayneneed.codeplex.com/
  • Get the lib and add it as a reference to your project.
  • Add xmlns:interop="clr-namespace:Microsoft.DwayneNeed.Interop;assembly=Microsoft.DwayneNeed" to your XAML.
    Place your Control in the decorator:
    <interop:AirspaceDecorator AirspaceMode="Redirect" Background="White" IsInputRedirectionEnabled="True" IsOutputRedirectionEnabled="True"> <!--your winforms control or webbrowser here here--> </interop:AirspaceDecorator>

@ghiboz
Copy link
Author

ghiboz commented Feb 26, 2014

thanks, but for the solution #1, where I put the code listed?

@AzureKitsune
Copy link
Member

@ghiboz Anywhere on the top level of your MetroWindow.

<MetroWindow>
    <!--this is the top level-->
    <Grid>
        <!--this is NOT the top level-->
    </Grid>
</MetroWindow>

@ghiboz
Copy link
Author

ghiboz commented Feb 27, 2014

thanks @Amrykid ! now works ;)

@AzureKitsune
Copy link
Member

Excellent! :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants