Huskui.Avalonia.Code
1.0.1
See the version list below for details.
dotnet add package Huskui.Avalonia.Code --version 1.0.1
NuGet\Install-Package Huskui.Avalonia.Code -Version 1.0.1
<PackageReference Include="Huskui.Avalonia.Code" Version="1.0.1" />
<PackageVersion Include="Huskui.Avalonia.Code" Version="1.0.1" />
<PackageReference Include="Huskui.Avalonia.Code" />
paket add Huskui.Avalonia.Code --version 1.0.1
#r "nuget: Huskui.Avalonia.Code, 1.0.1"
#:package Huskui.Avalonia.Code@1.0.1
#addin nuget:?package=Huskui.Avalonia.Code&version=1.0.1
#tool nuget:?package=Huskui.Avalonia.Code&version=1.0.1
Huskui.Avalonia.Code
A syntax-highlighted code viewer extension for Huskui.Avalonia, powered by TextMate grammars with a lightweight inline renderer.
Relationship to Huskui.Avalonia
Huskui.Avalonia.Code is an extension library for Huskui.Avalonia — it cannot be used standalone.
- Prerequisite: You must install
Huskui.Avaloniaand useHuskuiThemein your application - Auto-loading: Once the assembly is loaded,
HuskuiThemeautomatically merges the extension's theme resources via the[HuskuiExtension]mechanism — no manual style includes needed - Shared namespace: Controls are mapped to
https://github.com/d3ara1n/Huskui.Avalonia, using the samehusk:XAML prefix as the core library
Installation
dotnet add package Huskui.Avalonia
dotnet add package Huskui.Avalonia.Code
Usage
Basic
<husk:CodeViewer Code="{Binding SourceCode}" Language="csharp" />
Properties
| Property | Type | Default | Description |
|---|---|---|---|
Code |
string |
"" |
Source code text to display |
Language |
string |
"xml" |
Language identifier for syntax highlighting |
IsLineNumbersVisible |
bool |
true |
Show line numbers column |
IsCopyButtonVisible |
bool |
true |
Show copy button in the header bar |
Inlines |
InlineCollection? |
null |
Custom inline collection; overrides Code-based rendering when set |
XAML Example
<UserControl xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:husk="https://github.com/d3ara1n/Huskui.Avalonia"
x:Class="YourApp.CodePage">
<StackPanel Spacing="16">
<husk:CodeViewer
Language="csharp"
Code='public class Hello
{
 public void Greet() => Console.WriteLine("Hello!");
}' />
<husk:CodeViewer
Language="xml"
IsLineNumbersVisible="False"
Code="<Button Content="Click me" />" />
<husk:CodeViewer
Language="js"
IsCopyButtonVisible="False"
Code="console.log("Hello");" />
</StackPanel>
</UserControl>
C# Example
var viewer = new CodeViewer
{
Language = "csharp",
Code = """
public class Hello
{
public void Greet() => Console.WriteLine("Hello!");
}
"""
};
Language Support
CodeViewer uses TextMate grammars through TextMateSharp.Grammars. Languages are resolved through built-in aliases and file-extension-style mappings, then fall back to plain text if no grammar is available.
Supported Languages
| Language | Identifiers |
|---|---|
| Bash | bash, sh, shell, zsh |
| C# | csharp, cs |
| C++ | cpp |
| C | c |
| CSS | css |
| F# | fsharp, fs |
| HTML | html |
| Java | java |
| JavaScript | javascript, js |
| JSON | json |
| Markdown | markdown, md |
| Less | less |
| Lua | lua |
| PHP | php |
| PowerShell | powershell, ps1 |
| Python | python, py |
| Rust | rust, rs |
| SCSS | scss |
| SQL | sql |
| TypeScript | typescript, ts, tsx |
| XML | xml, xaml, axaml |
| YAML | yaml, yml |
| Visual Basic | visualbasic, vb |
| ASP.NET | aspx |
| CoffeeScript | coffeescript |
| Ruby | ruby |
Note: The full list of supported languages depends on the bundled TextMate grammars. If a language is not recognized, the code is rendered as plain text without syntax highlighting.
Features
- Syntax Highlighting — TextMate-based tokenization with Huskui Radix light/dark token themes
- Line Numbers — Optional lightweight line number gutter
- Copy to Clipboard — Header bar with language label and copy button
- Lightweight Rendering — Code content is rendered as Avalonia inlines without embedding an editor control
- Custom Inlines — Override rendering by providing your own
InlineCollection - Monospace Font — Defaults to
Cascadia Code, Consolas, Courier New, monospace
Dependencies
- Huskui.Avalonia — Core control library (required)
- TextMateSharp.Grammars — Bundled grammars and themes
License
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Huskui.Avalonia (>= 1.0.1)
- TextMateSharp.Grammars (>= 2.0.3)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Huskui.Avalonia.Code:
| Package | Downloads |
|---|---|
|
Huskui.Avalonia.Markdown
Markdown rendering extension for Huskui.Avalonia, converting Markdown text to native Avalonia controls using Markdig. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.2.0 | 82 | 5/26/2026 |
| 1.1.3 | 85 | 5/21/2026 |
| 1.1.2 | 161 | 5/7/2026 |
| 1.1.1 | 118 | 5/5/2026 |
| 1.1.0 | 129 | 5/3/2026 |
| 1.0.1 | 114 | 4/22/2026 |
| 1.0.0 | 118 | 4/22/2026 |
| 0.17.0 | 110 | 4/21/2026 |
| 0.16.1 | 110 | 4/17/2026 |
| 0.16.0 | 105 | 4/16/2026 |
| 0.15.0 | 114 | 4/13/2026 |
| 0.14.2 | 116 | 4/9/2026 |
| 0.14.1 | 110 | 4/8/2026 |
| 0.14.0 | 118 | 4/2/2026 |
# Changelog
All notable changes to this project will be documented in this file.
## [1.0.1] - 2026-04-22
### 🚀 Features
- *(Mvvm)* 添加了新的 Mvvm 库用于解耦原先主库的 IPageModel 设施
- *(Mvvm)* 添加导航传参、页面状态机制
- *(Gallery)* Add mvvm page
<!-- generated by git-cliff -->