Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/wieslawsoltes/avalonia.thememanager
Theme manager for Avalonia applications.
https://github.com/wieslawsoltes/avalonia.thememanager
avalonia avaloniaui c-sharp gui manager multi-platform theme themes xaml
Last synced: 2 days ago
JSON representation
Theme manager for Avalonia applications.
- Host: GitHub
- URL: https://github.com/wieslawsoltes/avalonia.thememanager
- Owner: wieslawsoltes
- License: mit
- Created: 2019-04-04T11:05:09.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2024-07-22T20:35:24.000Z (4 months ago)
- Last Synced: 2024-09-29T20:38:56.720Z (about 2 months ago)
- Topics: avalonia, avaloniaui, c-sharp, gui, manager, multi-platform, theme, themes, xaml
- Language: C#
- Size: 124 KB
- Stars: 125
- Watchers: 5
- Forks: 10
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE.TXT
Awesome Lists containing this project
README
# Avalonia Theme Manager
[![Build Status](https://dev.azure.com/wieslawsoltes/GitHub/_apis/build/status/wieslawsoltes.Avalonia.ThemeManager?branchName=master)](https://dev.azure.com/wieslawsoltes/GitHub/_build/latest?definitionId=97&branchName=master)
[![CI](https://github.com/wieslawsoltes/Avalonia.ThemeManager/actions/workflows/build.yml/badge.svg)](https://github.com/wieslawsoltes/Avalonia.ThemeManager/actions/workflows/build.yml)[![NuGet](https://img.shields.io/nuget/v/Avalonia.ThemeManager.svg)](https://www.nuget.org/packages/Avalonia.ThemeManager)
[![NuGet](https://img.shields.io/nuget/dt/Avalonia.ThemeManager.svg)](https://www.nuget.org/packages/Avalonia.ThemeManager)
[![MyGet](https://img.shields.io/myget/avaloniathememanager-nightly/vpre/Avalonia.ThemeManager.svg?label=myget)](https://www.myget.org/gallery/avaloniathememanager-nightly)[![Github All Releases](https://img.shields.io/github/downloads/wieslawsoltes/avalonia.thememanager/total.svg)](https://github.com/wieslawsoltes/avalonia.thememanager)
[![GitHub release](https://img.shields.io/github/release/wieslawsoltes/avalonia.thememanager.svg)](https://github.com/wieslawsoltes/avalonia.thememanager)
[![Github Releases](https://img.shields.io/github/downloads/wieslawsoltes/avalonia.thememanager/latest/total.svg)](https://github.com/wieslawsoltes/avalonia.thememanager)## About
Theme manager for [Avalonia](https://github.com/AvaloniaUI/Avalonia) applications.
## Usage
Theme manager searches user provided themes directory for `*.xaml` theme files otherwise built-in `Light` and `Dark` theme are used.
The `ThemeSelector` is created and initalized by calling static `Create` method.
The `ThemeSelector` uses `Styles[0]` property of `Window` to insert selected theme `Style`.
`App.xaml`
```XAML
```
`App.xaml.cs`
```C#
using System;
using Avalonia;
using Avalonia.Logging.Serilog;
using Avalonia.Markup.Xaml;
using Avalonia.ThemeManager;namespace AvaloniaApp
{
public class App : Application
{
public static ThemeSelector Selector;[STAThread]
static void Main(string[] args)
{
BuildAvaloniaApp().Start(AppMain, args);
}static void AppMain(Application app, string[] args)
{
Selector = ThemeSelector.Create("Themes");
Selector.LoadSelectedTheme("AvaloniaApp.theme");app.Run(new MainWindow());
Selector.SaveSelectedTheme("AvaloniaApp.theme");
}public static AppBuilder BuildAvaloniaApp()
=> AppBuilder.Configure()
.UsePlatformDetect()
.UseReactiveUI()
.LogToDebug();public override void Initialize()
{
AvaloniaXamlLoader.Load(this);
}
}
}
````MainWindow.xaml`
```XAML
<Setter Property="Header" Value="{Binding Name}"/>
<Setter Property="Command" Value="{Binding Selector.ApplyTheme}"/>
<Setter Property="CommandParameter" Value="{Binding}"/>
<Setter Property="Icon">
<Template>
<CheckBox>
<CheckBox.IsChecked>
<MultiBinding Mode="OneWay" Converter="{StaticResource ObjectEqualityMultiConverter}">
<Binding Path="DataContext" RelativeSource="{RelativeSource Self}"/>
<Binding Path="Selector.SelectedTheme"/>
</MultiBinding>
</CheckBox.IsChecked>
</CheckBox>
</Template>
</Setter>
```
`MainWindow.xaml.xs`
```C#
using Avalonia;
using Avalonia.Controls;
using Avalonia.Markup.Xaml;
using Avalonia.ThemeManager;namespace AvaloniaApp
{
public partial class MainWindow : Window
{
public MainWindow()
{
this.InitializeComponent();
this.AttachDevTools();
App.Selector.EnableThemes(this);
}private void InitializeComponent()
{
AvaloniaXamlLoader.Load(this);
}
}
}
```The `EnableThemes(...);` can be used to enable themes for multiple windows.
## NuGet
Avalonia theme manager is delivered as a NuGet package.
You can find the packages here [NuGet](https://www.nuget.org/packages/Avalonia.ThemeManager/) and install the package like this:
`Install-Package Avalonia.ThemeManager`
or by using nightly build feed:
* Add `https://www.myget.org/F/avaloniathememanager-nightly/api/v2` to your package sources
* Alternative nightly build feed `https://pkgs.dev.azure.com/wieslawsoltes/GitHub/_packaging/Nightly/nuget/v3/index.json`
* Update your package using `Avalonia.ThemeManager` feedand install the package like this:
`Install-Package Avalonia.ThemeManager -Pre`
## License
Avalonia.ThemeManager is licensed under the [MIT license](LICENSE.TXT).