WPF WebBrowser control does not enter design mode when a document property changes

I have an unpleasant problem. Here is a simplified version of what I'm doing:

The UserControl user in C # contains a toolbar and a built-in WebBrowser object. The toolbar contains a “Change” button, which, when clicked, installs a web browser control in design mode. Another “Cancel” button disables development mode.

Pseudocode (very simplified):

public void SetDesignMode(bool dm) {
  IHTMLDocument2 doc = webBrowser.Document as IHTMLDocument2;
  if (dm) doc.designMode = "On";
  else doc.designMode = "Off";
  _designMode = dm;
  ReloadDocument(); // setting designmode clears the document element, so it must be reloaded
}

public void OnLoadCompleted() {
  IHTMLDocument2 doc = webBrowser.Document as IHTMLDocument2;
  if (!_documentLoaded) {
    if (_designMode) doc.designMode = "On";
    else doc.designMode = "Off";
    ReloadDocument();
    _documentLoaded = true;
  }
}

public void ReloadDocument() {
  _documentLoaded = false;
  // code that navigates to the document
}

: -, "" , WebBrowser . / , . , .

, designMode "On", , ".".

-, "" , .

: "", , () , .

"" , "", "" .., , ( , ).

, , , designMode, . MSDN . designMode, , .

: , , usercontrol. , - , . : .

- ?

Update: , - SetDesignMode(). , . , . , MSHTML.

+5
2

, , , .

, x64 reset designMode, . "On" -, DocumentCompleted "Inherit". "On" DocumentCompleted , . DocumentText doom.

, , , DocumentText, , ( null) InnerHtml :

doc.designMode = "On"; // enable editing

// designMode change resets the document, create it anew
webBrowser1.Document.Write("<html><body></body></html>")
webBrowser1.Document.Body.InnerHtml = "myDocumentText"

, , , URL-. , , . LaughingJohn. , , IHTMLDocument webBrowser1.Document.

doc = webBrowser1.Document.DomDocument as IHTMLDocument2;
if (doc != null && doc.body != null)
    ((HtmlBody)doc.body).contentEditable = "true";
+8

, WebBrowser , - . : WebBrowser, Tab ( WebBrowser), , .

, Button.MouseEnter ((Button)sender).Foucs() , .

0

All Articles