LazyApiPack.Wpf.Theme 0.0.2

There is a newer version of this package available.
See the version list below for details.
dotnet add package LazyApiPack.Wpf.Theme --version 0.0.2                
NuGet\Install-Package LazyApiPack.Wpf.Theme -Version 0.0.2                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="LazyApiPack.Wpf.Theme" Version="0.0.2" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add LazyApiPack.Wpf.Theme --version 0.0.2                
#r "nuget: LazyApiPack.Wpf.Theme, 0.0.2"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install LazyApiPack.Wpf.Theme as a Cake Addin
#addin nuget:?package=LazyApiPack.Wpf.Theme&version=0.0.2

// Install LazyApiPack.Wpf.Theme as a Cake Tool
#tool nuget:?package=LazyApiPack.Wpf.Theme&version=0.0.2                

About this project

This project enables you to theme your WPF Application.

How to use the ThemeManager

First, you need to initialize the ThemeManager.

  public partial class App : Application
    {
        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);
            /// Initialize the theme Skeumorph Dark Theme
            var a = SkeumorphDarkTheme.CreateSkeumorphNightTheme(null, null, null,
                new[] { "SkeuTest1", "SkeuTest2" },
                new Uri("pack://application:,,,/LazyApiPack.Wpf.Theme.UITest;component/Themes/CustomSkeumorphTheme.xaml", UriKind.Absolute));

            /// Initialize the theme Skeumorop Bright Theme
            var b = SkeumorphBrightTheme.CreateSkeumorphBrightBlueTheme(null, null, null,
                  new[] { "SkeuTest3", "SkeuTest4" },
                  new Uri("pack://application:,,,/LazyApiPack.Wpf.Theme.UITest;component/Themes/CustomSkeumorphTheme.xaml", UriKind.Absolute));
            /// Initialize the theme Skeumorph Bright THEME
            var c = SkeumorphBrightTheme.CreateSkeumorphBrightGreenTheme(null, null, null,
                      new[] { "SkeuTest5", "SkeuTest6" },
                      new Uri("pack://application:,,,/LazyApiPack.Wpf.Theme.UITest;component/Themes/CustomSkeumorphTheme.xaml", UriKind.Absolute));
            /// Set theme a as the current theme.
            ThemeService.CurrentTheme = a;
        }
    }

How to switch a theme

You can set the theme in code with

ThemeService.CurrentTheme = themeObject;

or you can bind the Theme Manager in the UI

<ComboBox 
    SelectedItem="{Binding CurrentTheme, Source={x:Static local:App.ThemeService}}" 
    ItemsSource="{Binding AvailableThemes, Source={x:Static local:App.ThemeService}}" />

It might be easier to use the theme manager in an MVVM application and instantiate the theme service as a singleton service.

How to add predefined themes

To add predefined themes, simply install a packed from the LazyApiPack.Wpf.Theme.* namespace and use the Theme-Classes eg:

var theme = SkeumorphDarkTheme.CreateSkeumorphNightTheme("Title to override", "Description to override", 
    new BitmapImage(/*Screenshot for the user*/),
    new[] { "Search Tag", "Another Search Tag" },
    new Uri("Additional Resource", UriKind.Absolute));

How to include custom control themes to a theme

To add custom themes to a theme, simply call the Create*Theme function or the Theme constructor with additional resources

SkeumorphDarkTheme.CreateSkeumorphNightTheme("Title to override", "Description to override", 
    new BitmapImage(/*Screenshot for the user*/),
    new[] { "Search Tag", "Another Search Tag" },
    // This line adds the CustomSkeumorphTheme to this theme.
    new Uri("pack://application:,,,/LazyApiPack.Wpf.Theme.UITest;component/Themes/CustomSkeumorphTheme.xaml", UriKind.Absolute));

the XAML of CustomSkeumorphTheme could look like this;

<ControlTemplate x:Key="SpecialControlTemplate" TargetType="{x:Type local:SpecialControl}" >
    <Border BorderBrush="{DynamicResource PrimaryForegroundColorBrush}" Background="{DynamicResource PrimaryBackgroundColorBrush}" BorderThickness="5">
        <Grid>
            <TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" Text="{TemplateBinding Title}"/>
        </Grid>
    </Border>
</ControlTemplate>

<Style TargetType="{x:Type local:SpecialControl}">
    <Setter Property="Template" Value="{StaticResource SpecialControlTemplate}"/>
</Style>

Ensure you have a Generic.xaml in your project with the default theme and it is mapped to the Application.Resources.MergedResourceDictionaries

Please consider the LazyApiPack.Wpf.Theme.UITest solution as a reference on how to implement this pack.

Product Compatible and additional computed target framework versions.
.NET net6.0-windows7.0 is compatible.  net7.0-windows was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.0.3.1 247 11/19/2023
0.0.3 138 9/8/2023
0.0.2 135 9/8/2023

Support to implement this manager as a service in mvvm applications.