Skip to content
Amrykid edited this page Mar 3, 2014 · 17 revisions

Frequently Asked Questions

Use CTRL+F (Command+F on OS X) to find what you're looking for!

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>

2. Why is my WebBrowser positioned incorrectly?

img thanks to @myCollections for providing this screenshot from #1038

Chances are, your WebBrowser is being moved by the MetroWindow's built-in TransitioningContentControl.

Solution

The solution to the issue is to set the WindowTransitionsEnabled property on your MetroWindow to false.

3. Why is my error template rectangle appearing above another control?

img While we don't exactly have an explaination as to why this happens, we DO have a solution for it.

Solution

Simply wrap your TextBox (or insert control with the validation template) in an AdornerDecorator.

4. How do I use Dialogs synchronously?

The short answer is you can't, unless you use ShowModalDialogExternally (nudoq).

The long answer is because internal dialogs (dialogs shown inside of a MetroWindow) are not real dialogs. They are controls shown on top of your MetroWindow's content. That means that it requires that the UI thread/dispatcher be available to work, just like your controls do.

internal dialog

We use internal dialogs asynchronously so that you can wait for a response from the dialog and keep the UI available for other potential user interactions.

External dialogs

external dialog The reason that external dialogs can be used synchronously is because since the dialog has it's own "window", it has its own UI thread that can wait for user input.