Huskui.Avalonia.Code
0.14.0
dotnet add package Huskui.Avalonia.Code --version 0.14.0
NuGet\Install-Package Huskui.Avalonia.Code -Version 0.14.0
<PackageReference Include="Huskui.Avalonia.Code" Version="0.14.0" />
<PackageVersion Include="Huskui.Avalonia.Code" Version="0.14.0" />
<PackageReference Include="Huskui.Avalonia.Code" />
paket add Huskui.Avalonia.Code --version 0.14.0
#r "nuget: Huskui.Avalonia.Code, 0.14.0"
#:package Huskui.Avalonia.Code@0.14.0
#addin nuget:?package=Huskui.Avalonia.Code&version=0.14.0
#tool nuget:?package=Huskui.Avalonia.Code&version=0.14.0
Huskui.Avalonia.Code
A syntax-highlighted code viewer extension for Huskui.Avalonia, powered by ColorCode.Core.
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 ColorCode.Core for syntax highlighting. Languages are resolved in the following order:
Languages.FindById()— direct ColorCode language ID lookupLanguages.All→HasAlias()— alias-based lookup- Built-in convenience aliases (see table below)
Supported Languages
| Language | Identifiers |
|---|---|
| C# | csharp, cs |
| C++ | cpp |
| CSS | css |
| F# | fsharp, fs |
| HTML | html |
| Java | java |
| JavaScript | javascript, js |
| Markdown | markdown, md |
| PHP | php |
| PowerShell | powershell, ps1 |
| Python | python, py |
| SQL | sql |
| TypeScript | typescript, ts, tsx |
| XML | xml, xaml, axaml |
| ASP.NET | aspx |
| CoffeeScript | coffeescript |
| Ruby | ruby |
Note: The full list of supported languages depends on
ColorCode.Core. If a language is not recognized, the code is rendered as plain text without syntax highlighting.
Features
- Syntax Highlighting — ColorCode-based tokenization with dark theme styling
- Line Numbers(WIP) — Optional line number gutter
- Copy to Clipboard — Header bar with language label and copy button
- Selectable Text — Code content is rendered in a
SelectableTextBlockfor easy text selection - 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)
- ColorCode.Core — Syntax highlighting engine
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
- ColorCode.Core (>= 2.0.15)
- Huskui.Avalonia (>= 0.14.0)
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 |
|---|---|---|
| 0.14.0 | 30 | 4/2/2026 |