安装3个包:
Install-Package Avalonia.AvaloniaEdit
Install-Package AvaloniaEdit.TextMate
Install-Package TextMateSharp.Grammars
在App.xaml的<Application.Styles>下增加:
<StyleInclude Source="avares://AvaloniaEdit/Themes/Fluent/AvaloniaEdit.xaml" />
前台代码:
<Window xmlns="https://github.com/avaloniaui"
...
xmlns:AvaloniaEdit="clr-namespace:AvaloniaEdit;assembly=AvaloniaEdit"
...>
...
<AvaloniaEdit:TextEditor Text="Hello AvaloniaEdit!"
ShowLineNumbers="True"
FontFamily="Cascadia Code,Consolas,Menlo,Monospace"/>
...
</Window>
后台代码:
//First of all you need to have a reference for your TextEditor for it to be used inside AvaloniaEdit.TextMate project.
var _textEditor = this.FindControl<TextEditor>("Editor");
//Here we initialize RegistryOptions with the theme we want to use.
var _registryOptions = new RegistryOptions(ThemeName.DarkPlus);
//Initial setup of TextMate.
var _textMateInstallation = _textEditor.InstallTextMate(_registryOptions);
//Here we are getting the language by the extension and right after that we are initializing grammar with this language.
//And that's all
标签:Install,Package,AvaloniaEdit,registryOptions,TextMate,使用,var,Avalona
From: https://www.cnblogs.com/wzwyc/p/18069005