NativeTheme.Avalonia
1.0.1
dotnet add package NativeTheme.Avalonia --version 1.0.1
NuGet\Install-Package NativeTheme.Avalonia -Version 1.0.1
<PackageReference Include="NativeTheme.Avalonia" Version="1.0.1" />
<PackageVersion Include="NativeTheme.Avalonia" Version="1.0.1" />
<PackageReference Include="NativeTheme.Avalonia" />
paket add NativeTheme.Avalonia --version 1.0.1
#r "nuget: NativeTheme.Avalonia, 1.0.1"
#:package NativeTheme.Avalonia@1.0.1
#addin nuget:?package=NativeTheme.Avalonia&version=1.0.1
#tool nuget:?package=NativeTheme.Avalonia&version=1.0.1
NativeTheme.Avalonia
Avalonia styles that paint common controls with the current Windows UxTheme visual style. Uncovered controls fall through to Avalonia's SimpleTheme.
Constructing the theme also installs a DirectWrite/GDI compatibility patch so text metrics and hinting match the native Windows rendering used by the controls.
Originally built for Skymu.
The GDI patch modifies COM v-tables at runtime. It is applied automatically when
NativeThemeis constructed, before the theme reads system fonts and metrics.
Install
dotnet add package NativeTheme.Avalonia
Apply the theme in XAML
NativeTheme derives from Avalonia.Styling.Styles and has a parameterless constructor, so it can be used like any other Avalonia theme:
<Application
x:Class="MyApp.App"
xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:native="clr-namespace:NativeTheme.Avalonia;assembly=NativeTheme.Avalonia">
<Application.Styles>
<native:NativeTheme />
</Application.Styles>
</Application>
By default, NativeTheme adds SimpleTheme underneath itself as a fallback for controls it does not paint natively. If the application already has a base theme, disable the fallback:
<native:NativeTheme IncludeSimpleTheme="False" />
Colors, metrics, fonts, and control sizes are read from Windows when the theme is constructed. For that reason there is no static .axaml file to load with StyleInclude.
Code usage
If you build styles in code, instantiate the theme directly:
using NativeTheme.Avalonia;
Styles styles = new NativeTheme();
To omit the SimpleTheme fallback:
Styles styles = new NativeTheme(includeSimpleTheme: false);
GDI font patch
The patch is installed by the NativeTheme constructor, so no extra call in Main is required:
var theme = new NativeTheme();
Explicit entry points remain available if you want the patch without creating the theme:
using NativeTheme.Avalonia;
NativeTheme.InstallGdiPatch(); // same as GdiPatch.Install()
Both are idempotent, best-effort, and no-ops on non-Windows platforms. Installation failures are written to Debug rather than preventing the theme from loading. GdiPatch.KeepKerning is reserved for an optional shaped-buffer adjustment that is not installed by this package.
Reacting to system theme changes
When the Windows visual style or DPI changes, clear the native bitmap cache and repaint:
NativeTheme.Invalidate();
ThemePart controls subscribe to NativeTheme.Changed and repaint themselves automatically.
Platform notes
The native control rendering requires Windows with an active visual style. On other platforms, the theme has no native styles to apply and the SimpleTheme fallback remains available.
Build and pack
dotnet build NativeTheme.Avalonia.sln
dotnet pack src/NativeTheme.Avalonia/NativeTheme.Avalonia.csproj -c Release
The NuGet package is written to src/NativeTheme.Avalonia/bin/Release.
License
MIT. See LICENSE.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. 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. |
-
net8.0
- Avalonia (>= 11.3.23)
- Avalonia.Markup.Xaml.Loader (>= 11.3.23)
- Avalonia.Themes.Simple (>= 11.3.23)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.