C# – WPF WebBrowser-Control does not display content

cc#-4.0wpfwpf-controls

in my WPF-Application, I use a WebBrowser-Control to display Web contents. I test it with the Google search. In the following, first some source code:

<Canvas x:Name="LayoutRoot" Background="White">
       <WebBrowser x:Name="browser"
                            Width="494"
                            Height="293"
                            Canvas.Left="3"
                            Canvas.Top="162"/>

</Canvas>

public EventSide()
{
    InitializeComponent();
    browser.Navigate(new Uri("http://www.google.de/"));
}

Now it depends on the following issues:
The contents of the WebBrowser control is completely empty. I'm going with the mouse over the WebBrowser Control, changes at the top and the mouse-cursor to the text cursor and I get a Tooltip called search. This is the search field from the google page. This means that the information is available from the Web via my webbrowser control, but apparently can not be displayed.

In my main window, I set the AllowsTransparency-property to "True". If I reset it to "False", the contents are displayed in my web browser element. Since I need a separate window design, I am dependent on the AllowsTransparency property.

Had anyone ever had the same problem and has a proposed solution?

Best Answer

I guess WebBrowser control is not loaded when you call navigate, try this

public EventSide()
{
    InitializeComponent();
    browser.Loaded += delegate
    {
        browser.Navigate(new Uri("http://www.google.de/"));
    }
}

EDIT

Note that WebBrowser is old style(COM I guess) control and doesn't support styling, animating and AllowTransparency...

See here for more details

I think the only solution is to use 3rd part browsers like WPF 3D Chromium Browser if you really need it

Hope this helps

Related Topic