Winforms(Windows 应用程序)中的 Tinymce 使用 C# - SetContent 不工作

问题描述 投票:0回答:1

我在使用 C# 的 Winforms(Windows 应用程序)中使用 TinyMce。其他一切正常。即我能够获取 TinyMce 的内容并存储在数据库中。但是当我从数据库中提取内容并尝试在 TinyMce 中显示时,内容没有加载。事实上,根本没有调用 SetContent 函数。我什至尝试调用不带参数的 SetContent 但它没有被调用。同时 GetContent 被成功调用。 这是这两个函数(JavaScript 函数存在于 tinymce.htm 文件中)

<script type="text/javascript">
function GetContent() {
    alert('GetContent is called');
    console.log('GetContent is called');
    return tinyMCE.get('editorcontent').getContent();
}

function SetContent(htmlContent) { //This is not called. Even if I remove the htmlContent parameter
    alert('SetContent is called');
    console.log('SetContent is called');
    tinyMCE.get('editorcontent').setContent(htmlContent);
}
</script>

这是我调用这些函数的 C# 代码(它是一个属性)。

public string HtmlContent
{
    get
    {
        string content = string.Empty;
        if (webBrowserControl != null && webBrowserControl.Document != null)
        {
            object html = webBrowserControl.Document.InvokeScript("GetContent");
            content = html as string;
        }
        return content;
    }
    set
    {
        if (webBrowserControl != null && webBrowserControl.Document != null)
        {
            //Code reaches here. I confirmed through breakpoint. I even tried 
            //removing the parameter but it didn't worked. SetContent was never 
            //called. 
            webBrowserControl.Document.InvokeScript("SetContent", new object[] { value });
        }
    }
}

可能是什么问题?如何使用 C# 在 winforms(Windows 应用程序)中动态设置 tinyMCE 的内容?

c# winforms tinymce
1个回答
0
投票

我的问题已经解决了。为任何未来访问此链接的人发布相同问题的答案。 在初始化(创建)TinyMCE 的同一事件 (Form_Load) 中未调用 SetContent。因此,我使用 Timer Tick 事件(1 秒)延迟来使用 SetContent 加载 Html。 请注意,Thread.Sleep(在 Form_Load 中)也不起作用。

© www.soinside.com 2019 - 2024. All rights reserved.