机器翻译正文由机器翻译自项目原始文档(英文),排版经程序统一处理,可能存在偏差,请以原项目仓库为准。
AvaloniaEdit
这个项目是AvalonEdit的移植版本,AvalonEdit 是一个基于 WPF 的 Avalonia 文本编辑器。
AvaloniaEdit 支持的功能包括:
- 使用 TextMate 语法和主题的语法高亮。
- 代码折叠。
- 代码补全。
- 完全可定制和可扩展。
- 行号显示。
- 显示空格、行尾和制表符。
- 行虚拟化。
- 多光标编辑。
- 列内装饰。
- 自动换行。
- 文档下方滚动。
-
超链接。
以及更多更多功能!
AvaloniaEdit 目前由 2 个包组成
- Avalonia.AvaloniaEdit 广为人知的包,其中包含文本编辑器本身。
- AvaloniaEdit.TextMate 包,为 AvaloniaEdit 添加 TextMate 集成。
入门
如何设置一个显示 AvaloniaEdit 编辑器的新项目?
- Create an empty Avalonia application.
- 将 nuget 引用 添加到最新版本:
<PackageReference Include="Avalonia.AvaloniaEdit" Version="x.y.z.t" /> -
在你的
App.xaml中,将 所需样式 包含到你的<Application.Styles>中:<Application xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:Class="MyAvaloniaApplication.App" RequestedThemeVariant="Default"> <Application.Styles> <FluentTheme /> <!-- AvaloniaEdit styles (required!) --> <StyleInclude Source="avares://AvaloniaEdit/Themes/Fluent/AvaloniaEdit.xaml" /> </Application.Styles> </Application> - 最后,将 AvaloniaEdit 编辑器添加到你的窗口中:
<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>
您可以将 演示应用程序 作为参考。
如何为我的项目设置 TextMate 主题和语法高亮?
首先,如果您想使用 TextMateSharp 支持的语法,应安装以下软件包:
或者,如果您想支持自己的语法,只需安装 AvaloniaEdit.TextMate 软件包,并实现 IRegistryOptions 接口,这是目前在您想使用与内置 TextMateSharp.Grammars 不同的语法集时使用 AvaloniaEdit 最简单的方法。
//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 😀, you are ready to use AvaloniaEdit with syntax highlighting!
_textMateInstallation.SetGrammar(_registryOptions.GetScopeByLanguageId(_registryOptions.GetLanguageByExtension(".cs").Id));
建筑
使用子模块克隆(克隆后为 git clone --recursive 或 git submodule update --init),然后像往常一样使用 dotnet build / dotnet test。
打包由 build/ 中的 NUKE 构建驱动:
# Run tests, build and pack every library into artifacts/packages, then install
# them into the local NuGet cache as 9999.0.0-localbuild for testing in other apps
dotnet run --project build/_build.csproj
# Only create the packages (and their SBOMs)
dotnet run --project build/_build.csproj -- --target CreateNugetPackages本站来源与版权声明
- 本文标题:AvaloniaEdit - 基于 Avalonia 的文本编辑器(AvalonE
- 本文链接:https://www.cn121.com/editor/avaloniaui-avaloniaedit.html
- 原项目:AvaloniaUI/AvaloniaEdit 版权归原作者 AvaloniaUI 及贡献者所有
- 收录信息:本站于 2026-10-27 收录本项目,本页所列协议与仓库指标均为收录当时的状态;该日期之后原项目的版本更新与协议变更,本页不作同步。
- 开源协议:收录时本项目采用 MIT(查看 LICENSE 原文),本站译文为其衍生内容;使用、修改、分发请以该仓库 LICENSE 原文为准。
- 站点出处:本文首发于 OneTwoOne,收录自 GitHub 开源项目 AvaloniaUI/AvaloniaEdit。
- 翻译说明:本页正文为人工智能生成内容——由机器翻译对原项目 README 初译、经程序校验排版,可能存在错漏,请以原项目文档为准。
- 引用声明:商业转载、第三方聚合或 AI 检索训练引用时,请务必保留以上来源出处、本文永久链接,以及原项目的版权声明与许可信息。
- 下架通道:若原项目此后变更或收紧了许可协议、或作者/权利人认为本站的收录方式(译文、排版适配、简介翻译等)超出其授权范围,请通过 xyd3302001@163.com 发送下架通知,并附上项目地址与本页链接。本站核实后将第一时间删除本页内容,或改为不复制原文的目录性收录;署名更正等其他要求可一并提出。