WPF语法高亮控件AvalonEdit

来源:互联网 发布:linux不保存退出vi 编辑:程序博客网 时间:2024/06/07 08:06


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 0
原创粉丝点击