Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WebBrowser as Canvas Background

Tags:

c#

wpf

xaml

I like to add a WebBrowser control as a Canvas background in WPF using C#. How do I do this? I have the following code at the moment. But does not work.

<Canvas
  Name="canvas"
  Grid.ColumnSpan="4"
  Grid.Row="1"
  MouseDown="Canvas_MouseDown"
  MouseMove="Canvas_MouseMove"
  MouseUp="Canvas_MouseUp"
  Margin="0,0,0,16"
  Grid.RowSpan="3">
  <Canvas.Background>
    <VisualBrush>
      <VisualBrush.Visual>
        <WebBrowser
          x:Name="wbMain"
          Height="246"
          Width="592" />
      </VisualBrush.Visual>
    </VisualBrush>
  </Canvas.Background>
</Canvas>
like image 836
jiga Avatar asked Apr 28 '26 23:04

jiga


1 Answers

You cannot do this. The web browser control is an Internet Explorer ActiveX wrapper with the resulting airspace issues.

However, you can draw on top of it using the <Popup> control or if you don't mind losing the interactivity, try generating an image of the web page and use it as the Canvas background.

If you are thinking about using the WPF Chrome wrapper by Chris Cavanagh, bear in mind:

  • It does not yet support COM-Visible (so no window.external javascript methods back to your C# code)
  • It has a dependency on Awesomium which is only free for non-commercial use.
  • It will add over 10MB to your code size as it needs to embed Chromium
like image 174
Ed Andersen Avatar answered May 02 '26 03:05

Ed Andersen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!