From 1fc0f0f4658c8509a39d68cecef8078cceae5655 Mon Sep 17 00:00:00 2001 From: wieslawsoltes Date: Fri, 5 Apr 2019 12:19:41 +0200 Subject: [PATCH] Refactored initialization --- README.md | 23 +++++++------ samples/AvaloniaApp/App.xaml.cs | 8 +++-- samples/AvaloniaApp/MainWindow.xaml | 7 ++-- samples/AvaloniaApp/MainWindow.xaml.cs | 2 +- src/Avalonia.ThemeManager/Theme.cs | 8 ++--- src/Avalonia.ThemeManager/ThemeSelector.cs | 40 ++++++++++++++-------- 6 files changed, 53 insertions(+), 35 deletions(-) diff --git a/README.md b/README.md index ec6f0b6..9b52894 100644 --- a/README.md +++ b/README.md @@ -16,9 +16,9 @@ Theme manager for [Avalonia](https://github.com/AvaloniaUI/Avalonia) application Theme manager searches user provided themes directory for `*.xaml` theme files otherwise built-in `Light` and `Dark` theme are used. -The `ThemeSelector` static `Instance` property neeeds to be initalized before using `ThemeSelector` class. +The `ThemeSelector` is created and initalized by calling static `Create` method. -The `ThemeSelector` uses `Styles[0]` property of `Windows` to insert selected theme `Style`. +The `ThemeSelector` uses `Styles[0]` property of `Window` to insert selected theme `Style`. `App.xaml` ```XAML @@ -44,6 +44,8 @@ namespace AvaloniaApp { public class App : Application { + public static IThemeSelector Selector; + [STAThread] static void Main(string[] args) { @@ -52,12 +54,12 @@ namespace AvaloniaApp static void AppMain(Application app, string[] args) { - ThemeSelector.Instance = new ThemeSelector("Themes"); - ThemeSelector.Instance.LoadSelectedTheme("AvaloniaApp.theme"); + Selector = ThemeSelector.Create("Themes"); + Selector.LoadSelectedTheme("AvaloniaApp.theme"); app.Run(new MainWindow()); - ThemeSelector.Instance.SaveSelectedTheme("AvaloniaApp.theme"); + Selector.SaveSelectedTheme("AvaloniaApp.theme"); } public static AppBuilder BuildAvaloniaApp() @@ -79,16 +81,17 @@ namespace AvaloniaApp - + - +