WPF 通过使用Frame 加载kindeditor文本编辑器

4 篇文章 0 订阅

 最近在做WPF 客户端发送信息的功能 想要实现发送的信息包含超链接 图片等等,由于以前WEB做过文本编辑器 所以打算通过Frame 加载html页面来实现文本的编辑 然后调用C#代码取得文本编辑器里面的html。

 

  1. XAML代码
<Window x:Class="WpfApplication3.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="244*" />
            <RowDefinition Height="67*" />
        </Grid.RowDefinitions>
        
        <Frame x:Name="frame" />
        <WrapPanel Grid.Row="1" >
            <Button Content="html" Width="100" Height="30" Click="Button_Click_1"/>
            <Button Content="GO" Width="100" Height="30" Click="Button_Click"/>
        </WrapPanel>
       
    </Grid>
</Window>

   2. 后台代码

 

      private void Button_Click(object sender, RoutedEventArgs e)
        {
            WebBrowser wb = (WebBrowser)frame.Content;
            mshtml.HTMLDocumentClass htmldocument = (mshtml.HTMLDocumentClass)wb.Document;
            string html = wb.InvokeScript("getHtml").ToString();  //调用html页面函数 取得文本编辑器的html
            
        }

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            this.frame.Source = new Uri(Directory.GetCurrentDirectory() + "/HtmlEdit.html", UriKind.Absolute);
        }


   3.html 页面


 

<!doctype html>
<html>
	<head>
		<meta charset="utf-8" />
		<title>Simple Examples</title>
		<style>
			form {
				margin: 0;
			}
			textarea {
				display: block;
			}
		</style>
			<link rel="stylesheet" href="kindeditor-4.1.10/themes/default/default.css" />
	    	<script charset="utf-8" src="kindeditor-4.1.10/kindeditor-min.js"></script>
       
		<script type="text/javascript">
            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']
                    });
                });
                function getHtml() {                 
                    return editor.html();
                }
	
		</script>
	</head>
<body scroll="no">    
   
    <form>
        <textarea name="content" style="width:700px;height:120px;visibility:hidden;"></textarea>
    </form>
</body>
</html>


通过这样就能实现wpf 使用html页面的文本编辑器 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值