From c2e7cc1a3cd297a2928ae83e5a584e723a371fa7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Holger=20B=C3=B6rchers?= Date: Sun, 2 Apr 2023 22:44:52 +0200 Subject: [PATCH] Removed Reactive stuff and do code cleanup --- src/App.axaml | 39 ++++--- src/App.axaml.cs | 62 +++++------ src/ApplicationTheme.cs | 2 +- src/AvaloniaCoreRTDemo.csproj | 6 +- src/Controls/MainControl.axaml | 54 +++++++-- src/Controls/MainControl.axaml.cs | 6 +- .../ViewModels/MainControlViewModel.cs | 44 ++++---- src/Interfaces/IMainWindowState.cs | 3 +- src/Utilities.cs | 13 +-- src/Windows/AboutWindow.axaml | 68 ++++++++---- src/Windows/AboutWindow.axaml.cs | 10 +- src/Windows/MainWindow.axaml | 62 ++++++++--- src/Windows/MainWindow.axaml.cs | 31 +++--- src/Windows/ViewModels/AboutViewModel.cs | 58 +++++----- .../ViewModels/ApplicationModelBase.cs | 104 ++++++++---------- src/Windows/ViewModels/MainViewModel.cs | 23 ++-- 16 files changed, 337 insertions(+), 248 deletions(-) diff --git a/src/App.axaml b/src/App.axaml index bc3aa7a..6040b17 100644 --- a/src/App.axaml +++ b/src/App.axaml @@ -1,17 +1,22 @@ - - - - - - - - - - - \ No newline at end of file + + + + + + + + + + + \ No newline at end of file diff --git a/src/App.axaml.cs b/src/App.axaml.cs index 8cf244d..1434c89 100644 --- a/src/App.axaml.cs +++ b/src/App.axaml.cs @@ -25,81 +25,81 @@ namespace AvaloniaCoreRTDemo public override void Initialize() { AvaloniaXamlLoader.Load(this); - this.Name = "AvaloniaCoreRTDemo"; + Name = "AvaloniaCoreRTDemo"; } public override void OnFrameworkInitializationCompleted() { - this.InitializeThemes(); + InitializeThemes(); if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) { desktop.MainWindow = new MainWindow(); - this.DataContext = desktop.MainWindow.DataContext; + DataContext = desktop.MainWindow.DataContext; } base.OnFrameworkInitializationCompleted(); } private void InitializeThemes() { - this._simpleTheme = new SimpleTheme(); - this._fluentTheme = new FluentTheme(); + _simpleTheme = new SimpleTheme(); + _fluentTheme = new FluentTheme(); - this._fluentDataGrid = (IStyle)this.Resources["fluentDataGrid"]!; - this._simpleDataGrid = (IStyle)this.Resources["simpleDataGrid"]!; + _fluentDataGrid = (IStyle)Resources["fluentDataGrid"]!; + _simpleDataGrid = (IStyle)Resources["simpleDataGrid"]!; Styles.Add(_fluentTheme); Styles.Add(_fluentDataGrid); - this._currentTheme = ApplicationTheme.FluentLight; + _currentTheme = ApplicationTheme.FluentLight; } - ApplicationTheme IThemeSwitch.Current => this._currentTheme; + ApplicationTheme IThemeSwitch.Current => _currentTheme; void IThemeSwitch.ChangeTheme(ApplicationTheme theme) { - if (theme == this._currentTheme) + if (theme == _currentTheme) return; - Boolean themeChanged = theme switch + bool themeChanged = theme switch { - ApplicationTheme.SimpleLight => this._currentTheme is ApplicationTheme.FluentDark or ApplicationTheme.FluentLight, - ApplicationTheme.SimpleDark => this._currentTheme is ApplicationTheme.FluentDark or ApplicationTheme.FluentLight, - ApplicationTheme.FluentLight => this._currentTheme is ApplicationTheme.SimpleLight or ApplicationTheme.SimpleDark, - ApplicationTheme.FluentDark => this._currentTheme is ApplicationTheme.SimpleLight or ApplicationTheme.SimpleDark, + ApplicationTheme.SimpleLight => _currentTheme is ApplicationTheme.FluentDark or ApplicationTheme.FluentLight, + ApplicationTheme.SimpleDark => _currentTheme is ApplicationTheme.FluentDark or ApplicationTheme.FluentLight, + ApplicationTheme.FluentLight => _currentTheme is ApplicationTheme.SimpleLight or ApplicationTheme.SimpleDark, + ApplicationTheme.FluentDark => _currentTheme is ApplicationTheme.SimpleLight or ApplicationTheme.SimpleDark, _ => throw new ArgumentOutOfRangeException(nameof(theme), theme, null) }; - this._currentTheme = theme; + _currentTheme = theme; switch (theme) { case ApplicationTheme.SimpleLight: - this.SetValue(ThemeVariantScope.ActualThemeVariantProperty, ThemeVariant.Light); - this.Styles[0] = this._simpleTheme; - this.Styles[1] = this._simpleDataGrid; + SetValue(ThemeVariantScope.ActualThemeVariantProperty, ThemeVariant.Light); + Styles[0] = _simpleTheme; + Styles[1] = _simpleDataGrid; break; case ApplicationTheme.SimpleDark: - this.SetValue(ThemeVariantScope.ActualThemeVariantProperty, ThemeVariant.Dark); - this.Styles[0] = this._simpleTheme; - this.Styles[1] = this._simpleDataGrid; + SetValue(ThemeVariantScope.ActualThemeVariantProperty, ThemeVariant.Dark); + Styles[0] = _simpleTheme; + Styles[1] = _simpleDataGrid; break; case ApplicationTheme.FluentLight: - this.SetValue(ThemeVariantScope.ActualThemeVariantProperty, ThemeVariant.Light); - this.Styles[0] = this._fluentTheme; - this.Styles[1] = this._fluentDataGrid; + SetValue(ThemeVariantScope.ActualThemeVariantProperty, ThemeVariant.Light); + Styles[0] = _fluentTheme; + Styles[1] = _fluentDataGrid; break; case ApplicationTheme.FluentDark: - this.SetValue(ThemeVariantScope.ActualThemeVariantProperty, ThemeVariant.Dark); - this.Styles[0] = this._fluentTheme; - this.Styles[1] = this._fluentDataGrid; + SetValue(ThemeVariantScope.ActualThemeVariantProperty, ThemeVariant.Dark); + Styles[0] = _fluentTheme; + Styles[1] = _fluentDataGrid; break; } - if (themeChanged && this.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) + if (themeChanged && ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) { MainWindow oldWindow = (desktop.MainWindow as MainWindow)!; MainWindow newWindow = new MainWindow(oldWindow); desktop.MainWindow = newWindow; - this.DataContext = newWindow.DataContext; + DataContext = newWindow.DataContext; oldWindow.Hide(); newWindow.Show(); @@ -107,4 +107,4 @@ namespace AvaloniaCoreRTDemo } } } -} \ No newline at end of file +} diff --git a/src/ApplicationTheme.cs b/src/ApplicationTheme.cs index a7c55b0..cfe6db6 100644 --- a/src/ApplicationTheme.cs +++ b/src/ApplicationTheme.cs @@ -2,7 +2,7 @@ namespace AvaloniaCoreRTDemo { - public enum ApplicationTheme : Byte + public enum ApplicationTheme : byte { SimpleLight = 0, SimpleDark = 1, diff --git a/src/AvaloniaCoreRTDemo.csproj b/src/AvaloniaCoreRTDemo.csproj index 637fed2..a3512d3 100644 --- a/src/AvaloniaCoreRTDemo.csproj +++ b/src/AvaloniaCoreRTDemo.csproj @@ -11,6 +11,7 @@ true true true + enable @@ -50,13 +51,16 @@ - + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/src/Controls/MainControl.axaml b/src/Controls/MainControl.axaml index 13c2ab2..4d6647b 100644 --- a/src/Controls/MainControl.axaml +++ b/src/Controls/MainControl.axaml @@ -1,12 +1,44 @@ - - - Welcome to Avalonia UI + NativeAOT! - - - - + + + + Welcome to Avalonia UI + NativeAOT! + + + + + diff --git a/src/Controls/MainControl.axaml.cs b/src/Controls/MainControl.axaml.cs index 52aa012..b8b0417 100644 --- a/src/Controls/MainControl.axaml.cs +++ b/src/Controls/MainControl.axaml.cs @@ -9,18 +9,18 @@ namespace AvaloniaCoreRTDemo.Controls { public MainControl() { - this.InitializeComponent(); + InitializeComponent(); } private void InitializeComponent() { AvaloniaXamlLoader.Load(this); - this.DataContext = new MainControlViewModel(); + DataContext = new MainControlViewModel(); } public void Reload(IMainWindowState model) { - this.DataContext = new MainControlViewModel(model); + DataContext = new MainControlViewModel(model); } } } diff --git a/src/Controls/ViewModels/MainControlViewModel.cs b/src/Controls/ViewModels/MainControlViewModel.cs index 8abe745..63a7933 100644 --- a/src/Controls/ViewModels/MainControlViewModel.cs +++ b/src/Controls/ViewModels/MainControlViewModel.cs @@ -1,48 +1,46 @@ -using System; - -using Avalonia.Media.Imaging; - -using ReactiveUI; +using Avalonia.Media.Imaging; +using MvvmGen; namespace AvaloniaCoreRTDemo.Controls.ViewModels { - internal sealed class MainControlViewModel : ReactiveObject, IMainWindowState + [ViewModel] + internal sealed partial class MainControlViewModel : IMainWindowState { - private readonly IBitmap _dotNetImage; - private readonly IBitmap _avaloniaImage; + private IBitmap _dotNetImage; + private IBitmap _avaloniaImage; - private Boolean _unloadable = false; + private bool _unloadable = false; - public IBitmap DotNetImage => this._dotNetImage; - public IBitmap AvaloniaImage => this._avaloniaImage; - public String? Text { get; set; } + public IBitmap DotNetImage => _dotNetImage; + public IBitmap AvaloniaImage => _avaloniaImage; + public string? Text { get; set; } - public MainControlViewModel() + partial void OnInitialize() { - this._dotNetImage = Utilities.GetImageFromFile("dotnet.png"); - this._avaloniaImage = Utilities.GetImageFromFile("avalonia.png"); + _dotNetImage = Utilities.GetImageFromFile("dotnet.png"); + _avaloniaImage = Utilities.GetImageFromFile("avalonia.png"); } - public MainControlViewModel(IMainWindowState state) + public MainControlViewModel(IMainWindowState state) : this() { - this._avaloniaImage = state.AvaloniaImage; - this._dotNetImage = state.DotNetImage; - this.Text = state.Text; + _avaloniaImage = state.AvaloniaImage; + _dotNetImage = state.DotNetImage; + Text = state.Text; state.SetUnloadable(); } ~MainControlViewModel() { - if (!this._unloadable) + if (!_unloadable) { - this._dotNetImage.Dispose(); - this._avaloniaImage.Dispose(); + _dotNetImage.Dispose(); + _avaloniaImage.Dispose(); } } void IMainWindowState.SetUnloadable() { - this._unloadable = true; + _unloadable = true; } } } diff --git a/src/Interfaces/IMainWindowState.cs b/src/Interfaces/IMainWindowState.cs index ea25cce..af935c6 100644 --- a/src/Interfaces/IMainWindowState.cs +++ b/src/Interfaces/IMainWindowState.cs @@ -8,9 +8,8 @@ namespace AvaloniaCoreRTDemo { IBitmap DotNetImage { get; } IBitmap AvaloniaImage { get; } - String? Text { get; } + string? Text { get; } void SetUnloadable(); } } - diff --git a/src/Utilities.cs b/src/Utilities.cs index e51dcb7..aea748e 100644 --- a/src/Utilities.cs +++ b/src/Utilities.cs @@ -11,10 +11,10 @@ namespace AvaloniaCoreRTDemo { internal static class Utilities { - public static readonly Boolean IsWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows); - public static readonly Boolean IsOSX = RuntimeInformation.IsOSPlatform(OSPlatform.OSX); + public static readonly bool IsWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows); + public static readonly bool IsOSX = RuntimeInformation.IsOSPlatform(OSPlatform.OSX); - public static Bitmap GetImageFromResources(String fileName) + public static Bitmap GetImageFromResources(string fileName) { var assetLoader = AvaloniaLocator.Current.GetRequiredService(); using var assetStream = assetLoader.Open(new Uri($"avares://AvaloniaCoreRTDemo/Images/{fileName}")); @@ -27,12 +27,12 @@ namespace AvaloniaCoreRTDemo return window.Position; else { - Int32 yOffset = (Int32)(window.FrameSize.Value.Height - window.ClientSize.Height); + int yOffset = (int)(window.FrameSize.Value.Height - window.ClientSize.Height); return new(window.Position.X, window.Position.Y + yOffset); } } - public static Bitmap GetImageFromFile(String path) + public static Bitmap GetImageFromFile(string path) { try { @@ -44,7 +44,6 @@ namespace AvaloniaCoreRTDemo } } - private static String GetImageFullPath(String fileName) - => Path.Combine(AppDomain.CurrentDomain.BaseDirectory, fileName); + private static string GetImageFullPath(string fileName) => Path.Combine(AppDomain.CurrentDomain.BaseDirectory, fileName); } } diff --git a/src/Windows/AboutWindow.axaml b/src/Windows/AboutWindow.axaml index e1e5c51..fd54d3d 100644 --- a/src/Windows/AboutWindow.axaml +++ b/src/Windows/AboutWindow.axaml @@ -1,20 +1,50 @@ - - - - - - - - - - - + + + + + + + + + + diff --git a/src/Windows/AboutWindow.axaml.cs b/src/Windows/AboutWindow.axaml.cs index 2676011..be0891d 100644 --- a/src/Windows/AboutWindow.axaml.cs +++ b/src/Windows/AboutWindow.axaml.cs @@ -10,14 +10,14 @@ namespace AvaloniaCoreRTDemo.Windows { public sealed partial class AboutWindow : Window { - private readonly Boolean _darkTheme; + private readonly bool _darkTheme; public AboutWindow() : this(false) { } - public AboutWindow(Boolean darkTheme) + public AboutWindow(bool darkTheme) { - this._darkTheme = darkTheme; - this.InitializeComponent(); + _darkTheme = darkTheme; + InitializeComponent(); #if DEBUG this.AttachDevTools(); #endif @@ -26,7 +26,7 @@ namespace AvaloniaCoreRTDemo.Windows private void InitializeComponent() { AvaloniaXamlLoader.Load(this); - this.DataContext = new AboutViewModel(this._darkTheme); + DataContext = new AboutViewModel(_darkTheme); } } } diff --git a/src/Windows/MainWindow.axaml b/src/Windows/MainWindow.axaml index 3977e9b..5df61d6 100644 --- a/src/Windows/MainWindow.axaml +++ b/src/Windows/MainWindow.axaml @@ -1,34 +1,66 @@ - + - + - - + + - - - - + + + + - \ No newline at end of file + \ No newline at end of file diff --git a/src/Windows/MainWindow.axaml.cs b/src/Windows/MainWindow.axaml.cs index fd51056..2f02b04 100644 --- a/src/Windows/MainWindow.axaml.cs +++ b/src/Windows/MainWindow.axaml.cs @@ -10,38 +10,39 @@ namespace AvaloniaCoreRTDemo.Windows { public sealed partial class MainWindow : Window, IMainWindow { - private readonly Application? _app = App.Current; + private readonly Application? _app = Application.Current; - private MainControl MainControl => this.GetControl("MainControl"); + private MainControl MainController => this.GetControl("MainControl"); public MainWindow() : this(default) { } + public MainWindow(IMainWindow? window) { - this.InitializeComponent(window); + InitializeComponent(window); #if DEBUG this.AttachDevTools(); #endif } - IThemeSwitch IMainWindow.ThemeSwitch => (IThemeSwitch)this._app!; - IMainWindowState IMainWindow.Model => (IMainWindowState)this.MainControl.DataContext!; + IThemeSwitch IMainWindow.ThemeSwitch => (IThemeSwitch)_app!; + IMainWindowState IMainWindow.Model => (IMainWindowState)this.MainController.DataContext!; PixelPoint IMainWindow.Position => Utilities.GetWindowPosition(this); - Size IMainWindow.ClientSize => this.ClientSize; - Size? IMainWindow.FrameSize => this.FrameSize; - WindowState IMainWindow.State => this.WindowState; + Size IMainWindow.ClientSize => ClientSize; + Size? IMainWindow.FrameSize => FrameSize; + WindowState IMainWindow.State => WindowState; private void InitializeComponent(IMainWindow? window) { AvaloniaXamlLoader.Load(this); - this.DataContext = new MainViewModel(this); + DataContext = new MainViewModel(this); if (window is not null) { - this.MainControl.Reload(window.Model); - this.WindowStartupLocation = WindowStartupLocation.Manual; - this.WindowState = window.State; - this.Position = window.Position; - this.FrameSize = window.FrameSize; - this.ClientSize = window.ClientSize; + this.MainController.Reload(window.Model); + WindowStartupLocation = WindowStartupLocation.Manual; + WindowState = window.State; + Position = window.Position; + FrameSize = window.FrameSize; + ClientSize = window.ClientSize; } } } diff --git a/src/Windows/ViewModels/AboutViewModel.cs b/src/Windows/ViewModels/AboutViewModel.cs index 2e72d49..0f6feb2 100644 --- a/src/Windows/ViewModels/AboutViewModel.cs +++ b/src/Windows/ViewModels/AboutViewModel.cs @@ -3,60 +3,60 @@ using System.Collections.Generic; using System.Runtime.InteropServices; using Avalonia.Media.Imaging; - -using ReactiveUI; +using MvvmGen; namespace AvaloniaCoreRTDemo.Windows.ViewModels { internal record SystemDetail(string Key, string Value); - internal sealed class AboutViewModel : ReactiveObject + [ViewModel] + internal sealed partial class AboutViewModel { - private readonly IBitmap _computerImage; - private readonly Boolean _darkTheme; + private readonly bool _darkTheme; public IBitmap ComputerImage => _computerImage; - public IReadOnlyList SystemDetails { get; } = new[] - { - new SystemDetail("Number of Cores", Environment.ProcessorCount.ToString()), - new SystemDetail("OS", RuntimeInformation.OSDescription), - new SystemDetail("OS Arch", RuntimeInformation.OSArchitecture.ToString()), - new SystemDetail("OS Version", Environment.OSVersion.ToString()), - new SystemDetail("Computer", Environment.MachineName), - new SystemDetail("User", Environment.UserName), - new SystemDetail("System Path", Environment.SystemDirectory), - new SystemDetail("Current Path", Environment.CurrentDirectory), - new SystemDetail("Process Arch", RuntimeInformation.ProcessArchitecture.ToString()), - new SystemDetail("Runtime Name", RuntimeInformation.FrameworkDescription), - new SystemDetail("Runtime Path", RuntimeEnvironment.GetRuntimeDirectory()), - new SystemDetail("Runtime Version", RuntimeEnvironment.GetSystemVersion()), - new SystemDetail("Framework Version", Environment.Version.ToString()), - }; + public IReadOnlyList SystemDetails { get; } = + new[] + { + new SystemDetail("Number of Cores", Environment.ProcessorCount.ToString()), + new SystemDetail("OS", RuntimeInformation.OSDescription), + new SystemDetail("OS Arch", RuntimeInformation.OSArchitecture.ToString()), + new SystemDetail("OS Version", Environment.OSVersion.ToString()), + new SystemDetail("Computer", Environment.MachineName), + new SystemDetail("User", Environment.UserName), + new SystemDetail("System Path", Environment.SystemDirectory), + new SystemDetail("Current Path", Environment.CurrentDirectory), + new SystemDetail("Process Arch", RuntimeInformation.ProcessArchitecture.ToString()), + new SystemDetail("Runtime Name", RuntimeInformation.FrameworkDescription), + new SystemDetail("Runtime Path", RuntimeEnvironment.GetRuntimeDirectory()), + new SystemDetail("Runtime Version", RuntimeEnvironment.GetSystemVersion()), + new SystemDetail("Framework Version", Environment.Version.ToString()), + }; - private String ComputerImageName + private string ComputerImageName { get { if (Utilities.IsWindows) - return !this._darkTheme ? "windows.png" : "windows_d.png"; + return !_darkTheme ? "windows.png" : "windows_d.png"; else if (Utilities.IsOSX) - return !this._darkTheme ? "macos.png" : "macos_d.png"; + return !_darkTheme ? "macos.png" : "macos_d.png"; else - return !this._darkTheme ? "linux.png" : "linux_d.png"; + return !_darkTheme ? "linux.png" : "linux_d.png"; } } - public AboutViewModel(Boolean darkTheme) + public AboutViewModel(bool darkTheme) : this() { - this._darkTheme = darkTheme; - this._computerImage = Utilities.GetImageFromResources(this.ComputerImageName); + _darkTheme = darkTheme; + _computerImage = Utilities.GetImageFromResources(ComputerImageName); } ~AboutViewModel() { - this._computerImage.Dispose(); + _computerImage.Dispose(); } } } diff --git a/src/Windows/ViewModels/ApplicationModelBase.cs b/src/Windows/ViewModels/ApplicationModelBase.cs index 62c4ee6..86297f1 100644 --- a/src/Windows/ViewModels/ApplicationModelBase.cs +++ b/src/Windows/ViewModels/ApplicationModelBase.cs @@ -1,100 +1,86 @@ using System; -using System.Reactive; using Avalonia.Controls; using AvaloniaCoreRTDemo.Interfaces; - -using ReactiveUI; +using MvvmGen; namespace AvaloniaCoreRTDemo.Windows.ViewModels { - internal abstract class ApplicationModelBase : ReactiveObject + [ViewModel] + internal abstract partial class ApplicationModelBase { private readonly IThemeSwitch _themeSwitch; - private Boolean _aboutEnable = true; - private Boolean _defaultLightEnable = false; - private Boolean _defaultDarkEnable = false; - private Boolean _fluentLightEnable = false; - private Boolean _fluentDarkEnable = false; - public Boolean AboutEnabled + [Property] + private bool _aboutEnabled = true; + + [Property] + private bool _defaultLightEnabled = false; + + [Property] + private bool _defaultDarkEnabled = false; + + [Property] + private bool _fluentLightEnabled = false; + + [Property] + private bool _fluentDarkEnabled = false; + + public ApplicationModelBase(IThemeSwitch themeSwitch) : this() { - get => this._aboutEnable; - set => this.RaiseAndSetIfChanged(ref this._aboutEnable, value); + _themeSwitch = themeSwitch; + IntializeTheme(themeSwitch.Current); } - public Boolean DefaultLightEnabled - { - get => this._defaultLightEnable; - set => this.RaiseAndSetIfChanged(ref this._defaultLightEnable, value); - } + [Command] + protected abstract void HelpAbout(); - public Boolean DefaultDarkEnabled - { - get => this._defaultDarkEnable; - set => this.RaiseAndSetIfChanged(ref this._defaultDarkEnable, value); - } + [Command] + protected abstract void DefaultLight(); - public Boolean FluentLightEnabled - { - get => this._fluentLightEnable; - set => this.RaiseAndSetIfChanged(ref this._fluentLightEnable, value); - } + [Command] + protected abstract void DefaultDark(); - public Boolean FluentDarkEnabled - { - get => this._fluentDarkEnable; - set => this.RaiseAndSetIfChanged(ref this._fluentDarkEnable, value); - } + [Command] + protected abstract void FluentLight(); - public ReactiveCommand FileExitCommand { get; } - - public ApplicationModelBase(IThemeSwitch themeSwitch) - { - this._themeSwitch = themeSwitch; - this.IntializeTheme(themeSwitch.Current); - this.FileExitCommand = ReactiveCommand.Create(RunFileExit); - } - - public abstract void HelpAboutMethod(); - public abstract void DefaultLightMethod(); - public abstract void DefaultDarkMethod(); - public abstract void FluentLightMethod(); - public abstract void FluentDarkMethod(); + [Command] + protected abstract void FluentDark(); protected async void RunHelpAbout(Window currentWindow) { - if (this.AboutEnabled) + if (AboutEnabled) try { - this.AboutEnabled = false; - await new AboutWindow(IsDarkTheme(this._themeSwitch.Current)).ShowDialog(currentWindow); + AboutEnabled = false; + await new AboutWindow(IsDarkTheme(_themeSwitch.Current)).ShowDialog(currentWindow); } finally { - this.AboutEnabled = true; + AboutEnabled = true; } } protected void SetTheme(ApplicationTheme theme) { - this.IntializeTheme(theme); - this._themeSwitch.ChangeTheme(theme); + IntializeTheme(theme); + _themeSwitch.ChangeTheme(theme); } - private void RunFileExit() => Environment.Exit(0); + [Command] + private void FileExit() => Environment.Exit(0); private void IntializeTheme(ApplicationTheme theme) { - this.DefaultLightEnabled = theme != ApplicationTheme.SimpleLight; - this.DefaultDarkEnabled = theme != ApplicationTheme.SimpleDark; - this.FluentLightEnabled = theme != ApplicationTheme.FluentLight; - this.FluentDarkEnabled = theme != ApplicationTheme.FluentDark; + DefaultLightEnabled = theme != ApplicationTheme.SimpleLight; + DefaultDarkEnabled = theme != ApplicationTheme.SimpleDark; + FluentLightEnabled = theme != ApplicationTheme.FluentLight; + FluentDarkEnabled = theme != ApplicationTheme.FluentDark; } - private static Boolean IsDarkTheme(ApplicationTheme? theme) - => theme switch + private static bool IsDarkTheme(ApplicationTheme? theme) => + theme switch { ApplicationTheme.SimpleDark => true, ApplicationTheme.FluentDark => true, diff --git a/src/Windows/ViewModels/MainViewModel.cs b/src/Windows/ViewModels/MainViewModel.cs index b464ee2..aad16f2 100644 --- a/src/Windows/ViewModels/MainViewModel.cs +++ b/src/Windows/ViewModels/MainViewModel.cs @@ -1,24 +1,27 @@ using Avalonia.Controls; using AvaloniaCoreRTDemo.Interfaces; +using MvvmGen; namespace AvaloniaCoreRTDemo.Windows.ViewModels { - internal sealed class MainViewModel : ApplicationModelBase - where TWindow : Window, IMainWindow + internal sealed class MainViewModel : ApplicationModelBase where TWindow : Window, IMainWindow { private TWindow _window; - public MainViewModel(TWindow window) - : base(window.ThemeSwitch) + public MainViewModel(TWindow window) : base(window.ThemeSwitch) { - this._window = window; + _window = window; } - public override void HelpAboutMethod() => base.RunHelpAbout(this._window); - public override void DefaultLightMethod() => base.SetTheme(ApplicationTheme.SimpleLight); - public override void DefaultDarkMethod() => base.SetTheme(ApplicationTheme.SimpleDark); - public override void FluentLightMethod() => base.SetTheme(ApplicationTheme.FluentLight); - public override void FluentDarkMethod() => base.SetTheme(ApplicationTheme.FluentDark); + protected override void HelpAbout() => RunHelpAbout(_window); + + protected override void DefaultLight() => SetTheme(ApplicationTheme.SimpleLight); + + protected override void DefaultDark() => SetTheme(ApplicationTheme.SimpleDark); + + protected override void FluentLight() => SetTheme(ApplicationTheme.FluentLight); + + protected override void FluentDark() => SetTheme(ApplicationTheme.FluentDark); } }