WPF语法高亮控件AvalonEdit



AvalonEdit is a WPF-based extensible text editor.

AvalonEdit是基于WPF的可扩展的文本编辑器。


While the WPF RichTextBox is quite powerful, you quickly run into its limits when trying to use it as a code editor: it's hard to write efficient syntax highlighting for it, and you cannot really implement features like code folding with the standard RichTextBox.

虽然WPF的RichTextBox功能很强,使用它当代码编辑器时运行迅速。但用它写有效的语法高亮文本还是比较困难,并且不能真正实现像代码折叠之类的特性。


The problem is: the RichTextBox edits a rich document. In contrast, AvalonEdit simply edits text.

问题有:RichTextBox是一个富文档编辑器,与此不同的是,AvalonEdit是一个简单文本编辑器。


However, AvalonEdit offers lots of possibilities on how the text document is displayed - so it is much more suitable for a code editor where things like the text color are not controlled by the user, but instead depend on the text (syntax highlighting).

然而,AvalonEdit为如何显示文档提供了多种可能性,比如文本颜色不是由用户控制,而是依赖于文本(语法高亮)的情况,所以它作为代码编辑器是非常合适的。


AvalonEdit was written for the SharpDevelop IDE. It replaces our old Windows Forms-based text editor (ICSharpCode.TextEditor).

AvalonEdit 是为SharpDevelop IDE而开发的编辑器,它代替了传统windows 面向表单文本的编辑器(ICSharpCode.TextEditor)。



用法:

The main class of the editor is ICSharpCode.AvalonEdit.TextEditor. You can use it similar to a normal WPF TextBox:

编辑器的主要类是ICSharpCode.AvalonEdit.TextEditor,可以用它来写一个简单的WPF文本框控件。

 
<avalonEdit:TextEditor
    xmlns:avalonEdit="http://icsharpcode.net/sharpdevelop/avalonedit"
    Name="textEditor"
    SyntaxHighlighting="C#"
    FontFamily="Consolas"
    FontSize="10pt"/>


系统环境:

There are two versions of AvalonEdit - the normal one requires .NET Framework 4.0 or higher; but we also offer a modified version for .NET 3.5 SP1. For compiling AvalonEdit, you will need a C# 4.0 compiler (SharpDevelop 4.x or Visual Studio 2010).

AvalonEdit有两个版本,普通版需要.Net Framework 4.0或更高版本的支持,另外也提供了基于.Net 3.5 SP1的改良版。编译AvalonEdit时,需要C#4.0的编辑器。(SharpDevelop 4.x  或 Visual Studio 2010).



        private static FoldingManager foldingManager = null;
        private static XmlFoldingStrategy foldingStrategy = new XmlFoldingStrategy();




            //快速搜索
            txtTemplateContent.TextArea.DefaultInputHandler.NestedInputHandlers.Add(new SearchInputHandler(txtTemplateContent.TextArea));

            //显示行号            
            txtTemplateContent.ShowLineNumbers = true;
            //默认语法高亮规则
            txtTemplateContent.SyntaxHighlighting = HighlightingManager.Instance.GetDefinitionByExtension(".xml");
            //折叠
            foldingManager = FoldingManager.Install(txtTemplateContent.TextArea);




            txtTemplateContent.Text = DispContentValue;
            foldingStrategy.UpdateFoldings(foldingManager, txtTemplateContent.Document);


应用语法高亮读取xslt文档效果如下:




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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值