From 612ef6f51778f7f157c6a88124b2f5decd9f60fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wies=C5=82aw=20S=CC=8Colte=CC=81s?= Date: Sun, 21 Aug 2022 23:15:21 +0200 Subject: [PATCH] Enable switching themes --- SvgToXaml.sln | 1 + build/Avalonia.ThemeManager.props | 6 + src/SvgToXaml.Base/App.axaml | 1 - src/SvgToXaml.Base/App.axaml.cs | 11 ++ src/SvgToXaml.Base/SvgToXaml.Base.csproj | 1 + src/SvgToXaml.Base/Views/MainView.axaml | 152 ++++++++++++--------- src/SvgToXaml.Base/Views/MainView.axaml.cs | 17 ++- 7 files changed, 122 insertions(+), 67 deletions(-) create mode 100644 build/Avalonia.ThemeManager.props diff --git a/SvgToXaml.sln b/SvgToXaml.sln index 3d21cbf..8260994 100644 --- a/SvgToXaml.sln +++ b/SvgToXaml.sln @@ -63,6 +63,7 @@ ProjectSection(SolutionItems) = preProject build\Avalonia.Themes.Fluent.props = build\Avalonia.Themes.Fluent.props build\CommunityToolkit.Mvvm.props = build\CommunityToolkit.Mvvm.props build\ReactiveMarbles.PropertyChanged.props = build\ReactiveMarbles.PropertyChanged.props + build\Avalonia.ThemeManager.props = build\Avalonia.ThemeManager.props EndProjectSection EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "_build", "build\build\_build.csproj", "{E9A88CB0-B853-44C3-8A7E-F67DAD2A7F9B}" diff --git a/build/Avalonia.ThemeManager.props b/build/Avalonia.ThemeManager.props new file mode 100644 index 0000000..24f8211 --- /dev/null +++ b/build/Avalonia.ThemeManager.props @@ -0,0 +1,6 @@ + + + + + + diff --git a/src/SvgToXaml.Base/App.axaml b/src/SvgToXaml.Base/App.axaml index 98006e0..fd1fb94 100644 --- a/src/SvgToXaml.Base/App.axaml +++ b/src/SvgToXaml.Base/App.axaml @@ -7,7 +7,6 @@ - diff --git a/src/SvgToXaml.Base/App.axaml.cs b/src/SvgToXaml.Base/App.axaml.cs index 600adc3..037b974 100644 --- a/src/SvgToXaml.Base/App.axaml.cs +++ b/src/SvgToXaml.Base/App.axaml.cs @@ -4,6 +4,7 @@ using System.Text.Json; using Avalonia; using Avalonia.Controls.ApplicationLifetimes; using Avalonia.Markup.Xaml; +using Avalonia.ThemeManager; using SvgToXaml.ViewModels; using SvgToXaml.Views; @@ -11,10 +12,20 @@ namespace SvgToXaml; public class App : Application { + public static IThemeManager? ThemeManager; + private const string ProjectFileName = "project.json"; public override void Initialize() { +#if true + ThemeManager = new FluentThemeManager(); +#else + ThemeManager = new SimpleThemeManager(); +#endif + ThemeManager.Initialize(this); + ThemeManager?.Switch(1); + AvaloniaXamlLoader.Load(this); } diff --git a/src/SvgToXaml.Base/SvgToXaml.Base.csproj b/src/SvgToXaml.Base/SvgToXaml.Base.csproj index 8fa18b4..891c275 100644 --- a/src/SvgToXaml.Base/SvgToXaml.Base.csproj +++ b/src/SvgToXaml.Base/SvgToXaml.Base.csproj @@ -29,6 +29,7 @@ + diff --git a/src/SvgToXaml.Base/Views/MainView.axaml b/src/SvgToXaml.Base/Views/MainView.axaml index e3b70e5..b439fcc 100644 --- a/src/SvgToXaml.Base/Views/MainView.axaml +++ b/src/SvgToXaml.Base/Views/MainView.axaml @@ -13,6 +13,7 @@ + M12 22c5.523 0 10-4.477 10-10S17.523 2 12 2 2 6.477 2 12s4.477 10 10 10Zm0-2V4a8 8 0 1 1 0 16Z M13.4219 0L22 8.57813L22 10L12 10L12 0L13.4219 0ZM14 8L18.5781 8L14 3.42188L14 8ZM20 14L20 12L22 12L22 14L20 14ZM20 18L20 16L22 16L22 18L20 18ZM20 22L20 20L22 20L22 22L20 22ZM20 26L20 24L22 24L22 26L20 26ZM20 30L20 28L22 28L22 30L20 30ZM16 30L16 28L18 28L18 30L16 30ZM12 30L12 28L14 28L14 30L12 30ZM8 30L8 28L10 28L10 30L8 30ZM4 30L4 28L6 28L6 30L4 30ZM0 30L0 28L2 28L2 30L0 30ZM0 14L0 12L2 12L2 14L0 14ZM0 10L0 8L2 8L2 10L0 10ZM0 6L0 4L2 4L2 6L0 6ZM0 2L0 0L2 0L2 2L0 2ZM4 2L4 0L6 0L6 2L4 2ZM8 2L8 0L10 0L10 2L8 2ZM0 18L0 16L2 16L2 18L0 18ZM0 22L0 20L2 20L2 22L0 22ZM0 26L0 24L2 24L2 26L0 26Z M26 6L24 6L24 29Q24 29.625 23.7656 30.1719Q23.5313 30.7188 23.125 31.125Q22.7188 31.5313 22.1719 31.7656Q21.625 32 21 32L5 32Q4.375 32 3.82813 31.7656Q3.28125 31.5313 2.875 31.125Q2.46875 30.7188 2.23438 30.1719Q2 29.625 2 29L2 6L0 6L0 4L8 4L8 2Q8 1.57813 8.15625 1.21875Q8.3125 0.859377 8.58594 0.585938Q8.85937 0.312504 9.21875 0.15625Q9.57813 0 10 0L16 0Q16.4219 0 16.7813 0.15625Q17.1406 0.312502 17.4141 0.585938Q17.6875 0.859377 17.8438 1.21875Q18 1.57813 18 2L18 4L26 4L26 6ZM10 4L16 4L16 2L10 2L10 4ZM22 6L4 6L4 29Q4 29.4063 4.29688 29.7031Q4.59375 30 5 30L21 30Q21.4062 30 21.7031 29.7031Q22 29.4063 22 29L22 6ZM10 26L8 26L8 10L10 10L10 26ZM14 26L12 26L12 10L14 10L14 26ZM18 26L16 26L16 10L18 10L18 26Z M32 15L32 17L17 17L17 32L15 32L15 17L0 17L0 15L15 15L15 0L17 0L17 15L32 15Z @@ -241,84 +242,30 @@ ClipToBounds="False"> - - - - - - - - - - + + + + + + + + + + + diff --git a/src/SvgToXaml.Base/Views/MainView.axaml.cs b/src/SvgToXaml.Base/Views/MainView.axaml.cs index b0e863c..23b2950 100644 --- a/src/SvgToXaml.Base/Views/MainView.axaml.cs +++ b/src/SvgToXaml.Base/Views/MainView.axaml.cs @@ -8,10 +8,25 @@ public class MainView : UserControl public MainView() { InitializeComponent(); + InitializeThemes(); } private void InitializeComponent() { AvaloniaXamlLoader.Load(this); } -} \ No newline at end of file + + private void InitializeThemes() + { + var dark = true; + var theme = this.Find