wpf 使用编辑器kindeditor问题

ihefe 2013-08-20 11:17:06
在项目中使用了kindeditor编辑器。然后在从c#写入到kindeditor编辑器出错

xaml如下

<WebBrowser Name="webBrowser1" />

c#如下

private void Window_Loaded(object sender, RoutedEventArgs e)
{
webBrowser1.ObjectForScripting = sh;
webBrowser1.Source = new Uri(System.IO.Path.Combine(Environment.CurrentDirectory, "kindeditor-4.1.7/examples/simple.html"), UriKind.Absolute);
webBrowser1.InvokeScript("GetHtml", "cc");//调用html的js函数,这里是写入到编辑器里 到这里就会报错
}

#region 供从WebBrowser网页呼叫C#方法的沟通对象
[ComVisible(true)]
public class ScriptHelper
{
public void SendMessage(string msg)
{
MessageBox.Show(msg);//打印编辑内容
}
}

private ScriptHelper sh = new ScriptHelper();
#endregion

kindeditor如下

<!doctype html>
<html>
<!-- saved from url=(0014)about:internet -->
<head>
<meta charset="utf-8" />
<title>Simple Examples</title>
<style>
form {
margin: 0;
}
textarea {
display: block;
}
</style>
<link rel="stylesheet" href="../themes/default/default.css" />
<script charset="utf-8" src="../kindeditor-min.js"></script>
<script charset="utf-8" src="../lang/zh_CN.js"></script>
<script>

var editor;
KindEditor.ready(function(K) {

editor = K.create('textarea[name="content"]', {
resizeType : 1,
allowPreviewEmoticons : false,
allowImageUpload : false,
items : [
'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline',
'removeformat', '|', 'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist',
'insertunorderedlist', '|', 'emoticons', 'image', 'link']
});

K('body').click(function(e) {
//alert(editor.html());
window.external.SendMessage(editor.html());
});


});

function GetHtml(html) {
//var editors=document.getElementsByName("content");
editor.appendHtml(html);
}
</script>
</head>
<body>

<form>
<textarea name="content" style="width:700px;height:200px;visibility:hidden;"> </textarea>
</form>

</body>
</html>


...全文
185 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
Bonjour-你好 2013-08-20
  • 打赏
  • 举报
回复
mark!
ihefe 2013-08-20
  • 打赏
  • 举报
回复
解决~ http://social.msdn.microsoft.com/Forums/zh-CN/60ef78a0-de9b-4f5b-97f2-4de00bcf5e23/webbrowser-controls-loadcompleted-event-is-not-firing-wpf 加个回调LoadCompleted 加载完成后执行该函数即可

<WebBrowser Name="webBrowser1"  LoadCompleted="eventHandler"/>

        private void eventHandler(Object sender, NavigationEventArgs e)
        {
            MessageBox.Show("LoadCompleted Event");
            webBrowser1.InvokeScript("GetHtml", "cc");
        }

散分
ihefe 2013-08-20
  • 打赏
  • 举报
回复
如果通过按钮来触发是可以的

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            webBrowser1.InvokeScript("GetHtml", "C#传值到html");
        }

8,735

社区成员

发帖
与我相关
我的任务
社区描述
WPF/Silverlight相关讨论
社区管理员
  • WPF/Silverlight社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧