1

I have been trying to use Commands with the WPF WebBrowser control (with DesignMode = "on"):

Xaml (oversimplified):

<Window>
    <Grid>
       <Button Command="ToggleBold"/>
       <WebBrowser />
    </Grid>
</Window>

...but despite the WebBrowser accepting keystrokes when I type (and formatting a word as bold when I hit Ctrl+B) nothing happens when I click the button. This indicates to me that the WebBrowser does not natively implement Commands like a RichTextBox.

Can anyone please confirm this?

Community
  • 1
  • 1
Scott Baker
  • 10,013
  • 17
  • 56
  • 102

2 Answers2

1

I can confirm that, WPF WebBrowser control doesn't support WPF commands out-of-the-box. You'd need to implement a layer which handles WPF commands and translates them to the corresponding IHTMLDocument2::execCommand commands. To do that, you could create a custon control (derived from UserControl) and embed the WebBrowser control inside it. You cannot derive from WebBrowser directly as it's sealed.

noseratio
  • 59,932
  • 34
  • 208
  • 486
  • 1
    Sounds like a good plan - although why this wasn't included in the WPF wrapper class is beyond me. – Scott Baker Mar 19 '15 at 17:48
  • @ScottSEA, the WPF wrapper is imperfect in many other ways, e.g. http://stackoverflow.com/questions/18256886/webbrowser-control-keyboard-and-focus-behavior – noseratio Mar 19 '15 at 17:57
0

I am not a WPF expert, but what I know that the Webbrowser control is the same as a real browser in your app, so it render just HTML, and can't understand WPF or asp.net code.

Amr Elgarhy
  • 66,568
  • 69
  • 184
  • 301
  • As I understand it, the `WebBrowser` control wraps the ActiveX IE control... and you'd think that if they were writing a wrapper, they'd add `Command` functionality - basically wrap calls to `execCommand()` with the appropriate .NET `Command`. Just sayin'. – Scott Baker Mar 18 '15 at 18:57
  • what I am sure from that there is nothing called RichTextBox in html – Amr Elgarhy Mar 18 '15 at 20:18
  • I was only saying that the `RichTextBox` natively supports Commands, not that it was an HTML control or related to HTML in any way. – Scott Baker Mar 18 '15 at 21:32