diff --git a/SightKeeper.Avalonia/Extensions/ControlExtensions.cs b/SightKeeper.Avalonia/Extensions/ControlExtensions.cs index af54d114..f5848d3e 100644 --- a/SightKeeper.Avalonia/Extensions/ControlExtensions.cs +++ b/SightKeeper.Avalonia/Extensions/ControlExtensions.cs @@ -1,5 +1,7 @@ -using Avalonia; +using System.Linq; +using Avalonia; using Avalonia.Controls; +using Avalonia.Controls.ApplicationLifetimes; using CommunityToolkit.Diagnostics; namespace SightKeeper.Avalonia.Extensions; @@ -9,4 +11,23 @@ public static class ControlExtensions public static TopLevel GetTopLevel(this Visual visual) => TopLevel.GetTopLevel(visual) ?? ThrowHelper.ThrowArgumentException(nameof(visual), "Could`t find TopLevel of the visual"); + + public static void ReopenWindow() where TWindow : Window, new() + { + var application = global::Avalonia.Application.Current; + Guard.IsNotNull(application); + Guard.IsNotNull(application.ApplicationLifetime); + var lifetime = (IClassicDesktopStyleApplicationLifetime)application.ApplicationLifetime; + var window = lifetime.Windows.OfType().Single(); + TWindow replacement = new() + { + Position = window.Position, + DataContext = window.DataContext, + WindowState = window.WindowState, + Width = window.Width, + Height = window.Height + }; + replacement.Show(); + window.Close(); + } } \ No newline at end of file diff --git a/SightKeeper.Avalonia/MainViewModel.cs b/SightKeeper.Avalonia/MainViewModel.cs index c845bdc1..13e2e659 100644 --- a/SightKeeper.Avalonia/MainViewModel.cs +++ b/SightKeeper.Avalonia/MainViewModel.cs @@ -4,6 +4,7 @@ using CommunityToolkit.Mvvm.ComponentModel; using Material.Icons; using SightKeeper.Avalonia.Dialogs; +using SightKeeper.Avalonia.Settings.Appearance; using SightKeeper.Avalonia.ViewModels; using SightKeeper.Avalonia.ViewModels.Elements; using SettingsViewModel = SightKeeper.Avalonia.Settings.SettingsViewModel; @@ -13,11 +14,16 @@ namespace SightKeeper.Avalonia; internal sealed partial class MainViewModel : ViewModel, DialogHost { public DialogManager DialogManager { get; } + public AppearanceSettingsViewModel AppearanceSettings { get; } public IReadOnlyCollection Tabs { get; } - public MainViewModel(IComponentContext context, DialogManager dialogManager) + public MainViewModel( + IComponentContext context, + DialogManager dialogManager, + AppearanceSettingsViewModel appearanceSettings) { DialogManager = dialogManager; + AppearanceSettings = appearanceSettings; Tabs = [ CreateTab(context, MaterialIconKind.Cog, "Settings"), diff --git a/SightKeeper.Avalonia/MainWindow.axaml b/SightKeeper.Avalonia/MainWindow.axaml index cd85b2bb..e92f554f 100644 --- a/SightKeeper.Avalonia/MainWindow.axaml +++ b/SightKeeper.Avalonia/MainWindow.axaml @@ -12,7 +12,8 @@ Title="Sight Keeper" MinWidth="480" MinHeight="320" - x:DataType="local:MainViewModel"> + x:DataType="local:MainViewModel" + ExtendClientAreaToDecorationsHint="{Binding AppearanceSettings.CustomDecorations}"> diff --git a/SightKeeper.Avalonia/Settings/Appearance/AppearanceSettingsViewModel.cs b/SightKeeper.Avalonia/Settings/Appearance/AppearanceSettingsViewModel.cs index 3eee2c1f..d1b0506d 100644 --- a/SightKeeper.Avalonia/Settings/Appearance/AppearanceSettingsViewModel.cs +++ b/SightKeeper.Avalonia/Settings/Appearance/AppearanceSettingsViewModel.cs @@ -1,4 +1,5 @@ using System.ComponentModel; +using SightKeeper.Avalonia.Extensions; using SightKeeper.Avalonia.ViewModels; namespace SightKeeper.Avalonia.Settings.Appearance; @@ -18,7 +19,8 @@ public bool CustomDecorations return; _customDecorations = value; OnPropertyChanged(); - + // ISSUE Should not directly reference window + ControlExtensions.ReopenWindow(); } } diff --git a/SightKeeper.Avalonia/Setup/ViewModelsBootstrapper.cs b/SightKeeper.Avalonia/Setup/ViewModelsBootstrapper.cs index d22b12e1..662e9d0e 100644 --- a/SightKeeper.Avalonia/Setup/ViewModelsBootstrapper.cs +++ b/SightKeeper.Avalonia/Setup/ViewModelsBootstrapper.cs @@ -12,7 +12,7 @@ public static void Setup(ContainerBuilder builder) { builder.RegisterType(); builder.RegisterType(); - builder.RegisterType().As(); + builder.RegisterType().AsSelf().As().SingleInstance(); builder.RegisterType().As(); builder.RegisterType(); builder.RegisterType();