tags:

views:

1205

answers:

1

Hello.. I have created a wysiwyg editor as a standard C# program using the windows form control. I would like to do the same thing except with WPF.

In my old application I did something like this.

using mshtml;
private IHTMLDocument2 doc;

...

HTMLeditor.DocumentText =

"<html><body></body></html>"; 

doc = HTMLeditor.Document.DomDocument as IHTMLDocument2; 

doc.designMode = "On";

Which allowed the the use of Document.ExecCommand on the editor.

How is this accomplished in WPF? It doesn't look like the WebBrowser control in WPF allows for designmode.

Thanks!

+2  A: 

Try this:

public MyControl()
{
    InitializeComponent();

    editor.Navigated += new NavigatedEventHandler(editor_Navigated);
    editor.NavigateToString("<html><body></body></html>");
}

void editor_Navigated(object sender, NavigationEventArgs e)
{
    var doc = editor.Document as IHTMLDocument2;

    if (doc != null)
        doc.designMode = "On";
}

Edit: where editor is a WebBrowser control.

dustyburwell
Thank you so much.. Just a pointer to anyone who is also trying this, don't forget to add the Microsoft HTML Object Reference to your project and include mshtml!
puttputt
Alternatively, you can also set contentEditable = true on the body tag and/or use InvokeScript to execute javascript on the document. This will get you away from the mshtml requirement.
dustyburwell