2

我使用 windows 窗体控件创建了一个所见即所得编辑器作为标准 C# 程序。除了WPF,我想做同样的事情。

在我的旧应用程序中,我做了这样的事情。

using mshtml;
private IHTMLDocument2 doc;

...

HTMLeditor.DocumentText =

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

doc = HTMLeditor.Document.DomDocument as IHTMLDocument2; 

doc.designMode = "On";

这允许在编辑器上使用 Document.ExecCommand。

这在 WPF 中是如何实现的?它看起来不像 WPF 中的 WebBrowser 控件允许设计模式。

谢谢!

4

1 回答 1

6

尝试这个:

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";
}

编辑:其中编辑器是一个 WebBrowser 控件。

于 2009-05-04T18:10:01.747 回答