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

Webrowser not showing up when using MahApps.Metro within' a C# WPF project. #488

Closed
ghost opened this issue May 28, 2013 · 8 comments
Closed

Comments

@ghost
Copy link

ghost commented May 28, 2013

I think I've discovered some crazy glitch within MahApps.Metro, everything seemed fine until I decided to implement one of the Microsoft Controls in Visual Studio.

I added the MahApps.Metro theme via NuGet, and everything worked fine, but when I added the Webrowser Control (I used C# to tell it to navigate to Google) & debugged the program...
Nothing shows up, as if the webrowser was set to transparent.

It might have something to do with:
http://blogs.msdn.com/b/changov/archive/2009/01/19/webbrowser-control-on-transparent-wpf-window.asp (Webrowser controls not working with allowTransperancy set to true).. Maybe MahApps.Metro overiddes the control & sets the property to true... Anybody having the same issue...?!?!

Any ideas on a possible work around or fix?

@punker76
Copy link
Member

@SomeoneAmazinglyAwesome you're right, that's a dilemma with microsoft webbrowser!
have you tried this toolkit? https://awesomium.codeplex.com

@bitterskittles
Copy link
Contributor

AirspaceDecorator from https://microsoftdwayneneed.codeplex.com/ seems to work fine in MetroWindow with AllowTransparency set to true.
More info about it here: http://blogs.msdn.com/b/dwayneneed/archive/2013/02/26/mitigating-airspace-issues-in-wpf-applications.aspx

But I'd prefer Awesomium over IE like punker76 mentioned.

<controls:MetroWindow x:Class="MetroBrowserInterop.MainWindow"
                      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                      xmlns:controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
                      xmlns:interop="clr-namespace:Microsoft.DwayneNeed.Interop;assembly=Microsoft.DwayneNeed"
                      Title="MainWindow"
                      AllowsTransparency="True">
    <Window.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Colours.xaml" />
                <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml" />
                <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" />
                <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/Blue.xaml" />
                <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseLight.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Window.Resources>
    <Grid>
        <interop:AirspaceDecorator AirspaceMode="Redirect"
                                   Background="White"
                                   IsInputRedirectionEnabled="True"
                                   IsOutputRedirectionEnabled="True">
            <WebBrowser Source="http://www.google.com" />
        </interop:AirspaceDecorator>
        <Border HorizontalAlignment="Center"
                VerticalAlignment="Center"
                Background="SkyBlue"
                BorderBrush="DeepSkyBlue"
                BorderThickness="1"
                Opacity="0.5">
            <TextBlock Margin="50"
                       FontSize="24"
                       Text="Hello Airspace" />
        </Border>
    </Grid>
</controls:MetroWindow>

Screenie

@AzureKitsune
Copy link
Member

I can confirm that @bitterskittles idea works on one of my other projects.

@spiritdead
Copy link
Contributor

this DLL broken my designer after restart the VS

@spiritdead
Copy link
Contributor

well debugging the DLL i find the bug (crasher designer :P)

if you need use this library fix this lines

in the File
Microsoft.DwayneNeed\Microsoft.DwayneNeed\Interop\RedirectedHwndHost.cs

in the Void

private void UpdateOutputRedirection()

REPLACE ALL FOR THIS

 private void UpdateOutputRedirection()
        {

            try
            {
                if (_redirectedWindow != null) 
                {
                    BitmapSource bitmap = _redirectedWindow.UpdateRedirectedBitmap();
                    if (bitmap != _bitmap)
                    {
                        _bitmap = bitmap;
                        InvalidateVisual();
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + "\n\n" + ex.StackTrace + "\n\n" + ex.InnerException);
            }
        }

@bitterskittles
Copy link
Contributor

Alternatively you can set AirspaceDecorator.AirspaceMode="None" in XAML and change it to redirect in runtime to avoid offscreen redirection inside the designer.

@ghost
Copy link
Author

ghost commented May 29, 2013

@punker76 Thankz for the quick reply on this issue, I tried Awesomium and it worked perfectly. 👍
@bitterskittles Thankz for replying on this issue, Airspace Decoder also works! (With setting AirspaceDecoder.AirspaceMode="None")

@AzureKitsune
Copy link
Member

Hi @SomeoneAmazinglyAwesome ! I guess I can mark this as closed.

shiftkey pushed a commit that referenced this issue Jun 2, 2013
… DWM non-client rendering directly.

Added http://archive.msdn.microsoft.com/WPFShell for MA.M .NET 4 client profile.
Fixes #481, #488, #496.
shiftkey pushed a commit that referenced this issue Jun 5, 2013
… DWM non-client rendering directly.

Added http://archive.msdn.microsoft.com/WPFShell for MA.M .NET 4 client profile.
Fixes #481, #488, #496.
@ghost ghost changed the title Webrowser Not Showing Up When Using MahApps.Metro Within' A C# WPF Project. Webrowser not showing up when using MahApps.Metro within' a C# WPF project. May 25, 2014
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

4 participants