项目处于早期开发阶段,尚不适合生产环境,API 很可能发生破坏性变更;WinUI 3 与 UWP 需分别安装不同的 NuGet 包;C++/WinRT 项目需在 pch.h 中加入 #include <winrt/WinUIEditor.h>
安装 NuGet 包 WinUIEdit(WinUI 3)或 WinUIEdit.Uwp(UWP);在页面中加入 xmlns:editor="using:WinUIEditor" 与 <editor:CodeEditorControl x:Name="MyEditor" HighlightingLanguage="csharp" />README 未说明硬件要求;仅说明 WinUI 3 版支持 Windows 10 1809 及以上、ARM64/x64/x86,UWP 版支持 Windows 10 1703 及以上、ARM64/ARM32/x64/x86
基于 Scintilla 的 UWP 与 WinUI 3 代码编辑器控件,用 C++ 编写,支持 C# 等 WinRT 语言
基于 Scintilla 的代码编辑器控件,给 UWP 和 WinUI 3 应用直接嵌入带语法高亮和编辑能力的代码编辑区域。
核心能力
- 移植 Scintilla 编辑器组件,通过 WinRT 包装暴露 API
- 提供 CodeEditorControl 控件,可设置 HighlightingLanguage 实现语法高亮
- 通过 Editor 属性调用 Scintilla 方法,如 SetText 设置文本
- 保留 SendMessage 方式访问原始窗口消息 API
- 可改用 EditorBaseControl 获得原生 Scintilla 行为
容易踩的坑
暂无 release 数据(可能没有发版,或尚未同步)。
用户点评
登录用户的真实使用记录,可按版本和硬件筛选还没有人点评。第一个说出真实体验的人最有价值。
WinUIEdit
This is an early work-in-progress code editor control for both UWP and WinUI 3. It is a port of the Scintilla editor component. It is written in C++ and works with C#, C++, and any other WinRT-compatible language.
[!NOTE] This control is currently not production ready. Breaking API changes are very likely at this stage.
Quick start
Install either the WinUIEdit NuGet package if using WinUI 3 or the WinUIEdit.Uwp NuGet package if using UWP (WinUI 2).
Add the namespace and code editor control to your page as shown below:
<Page
xmlns:editor="using:WinUIEditor">
<editor:CodeEditorControl x:Name="MyEditor" HighlightingLanguage="csharp" />
</Page>
Syntax highlighting is available through the HighlightingLanguage property. To control the editor, use the Editor property. For example, to set the editor text:
MyEditor.Editor.SetText("Vintage tee, brand new phone");
See the Scintilla documentation for complete remarks on all methods.
If using C++/WinRT, add #include <winrt/WinUIEditor.h> to your pch.h file.
Demo
You can download a demo from Microsoft Store here. Expect some occasional glitches and incomplete features.
Advanced usage
CodeEditorControl wraps EditorBaseControl and includes additional features and changes default settings and styles. EditorBaseControl can be used directly if only the original Scintilla control is desired. The Scintilla API is available through a WinRT wrapper exposed by the Editor property, as well as the original window message-based API via the SendMessage method.
Windows version support
The WinUI 3 version of this control should work on Windows 10, version 1809 and later and support ARM64, x64, and x86. The UWP version of this control should work on Windows 10, version 1703 and later. It will run on ARM64, ARM32, x64, and x86.
Development
How to build this project
To switch the build between WinUI 3 and UWP, you will need to modify UseWinUI3.txt to true or false. To do this quickly, use the WinUI3 and Uwp tools.
Open WinUIEditor.sln in Visual Studio 2022. Then, set CsDemoUWP or CppDemoUWP as the startup project for UWP or CsDemoWinUI3 or CppDemoWinUI3 for WinUI 3. Now you can build and run the project.
Project file structure
| Folder | Description |
|---|---|
| WinUIEditor | XAML control that hosts the Scintilla port (the C++ project in this folder is also responsible for compiling the scintilla folder code) |
| scintilla\winui | Scintilla platform code for UWP/WinUI 3 |
| scintilla | Unmodified Scintilla source code with new winui subfolder |
| lexilla | Lexilla source code (patches noted in WinUIModified.txt) |
| Tools | Tools to keep the Scintilla code up-to-date and aid in development (see Tools\README) |