diff --git a/src/App.axaml b/src/App.axaml
index e058919..e5fccaf 100644
--- a/src/App.axaml
+++ b/src/App.axaml
@@ -1,18 +1,8 @@
-
-
-
-
-
-
-
-
-
-
-
-
+
+
\ No newline at end of file
diff --git a/src/App.axaml.cs b/src/App.axaml.cs
index e05cb41..f760a54 100644
--- a/src/App.axaml.cs
+++ b/src/App.axaml.cs
@@ -4,7 +4,7 @@ using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Markup.Xaml;
using Avalonia.Styling;
using Avalonia.Themes.Fluent;
-
+using Avalonia.Themes.Simple;
using AvaloniaCoreRTDemo.Interfaces;
using AvaloniaCoreRTDemo.Windows;
@@ -12,11 +12,8 @@ namespace AvaloniaCoreRTDemo
{
public sealed class App : Application, IThemeSwitch
{
- private IStyle _baseLight;
- private IStyle _baseDark;
-
- private IStyle _fluentLight;
- private IStyle _fluentDark;
+ private FluentTheme _fluentTheme;
+ private SimpleTheme _simpleTheme;
private ApplicationTheme _currentTheme;
@@ -31,7 +28,7 @@ namespace AvaloniaCoreRTDemo
this.InitializeThemes();
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
{
- desktop.MainWindow = !Utilities.IsOSX ? new MainWindow() : new MainWindowMacOS();
+ desktop.MainWindow = new MainWindow();
this.DataContext = desktop.MainWindow.DataContext;
}
base.OnFrameworkInitializationCompleted();
@@ -39,15 +36,11 @@ namespace AvaloniaCoreRTDemo
private void InitializeThemes()
{
- this._baseDark = this.Styles[0];
- this._baseLight = this.Styles[1];
+ this._fluentTheme = (FluentTheme)this.Resources["fluentTheme"]!;
+ this._simpleTheme = (SimpleTheme)this.Resources["simpleTheme"]!;
+ Styles.Add(_fluentTheme);
- this.Styles.Remove(this._baseDark);
-
- this._fluentLight = (FluentTheme)this.Resources["fluentLight"]!;
- this._fluentDark = (FluentTheme)this.Resources["fluentDark"]!;
-
- this._currentTheme = ApplicationTheme.DefaultLight;
+ this._currentTheme = ApplicationTheme.FluentLight;
}
ApplicationTheme IThemeSwitch.Current => this._currentTheme;
@@ -57,25 +50,21 @@ namespace AvaloniaCoreRTDemo
this._currentTheme = theme;
switch (theme)
{
- case ApplicationTheme.DefaultLight:
- this.Styles[0] = this._baseLight;
- this.Styles.Remove(this._baseDark);
+ case ApplicationTheme.SimpleLight:
+ this._simpleTheme.Mode = SimpleThemeMode.Light;
+ this.Styles[0] = this._simpleTheme;
break;
- case ApplicationTheme.DefaultDark:
- this.Styles[0] = this._baseDark;
- this.Styles.Remove(this._baseLight);
+ case ApplicationTheme.SimpleDark:
+ this._simpleTheme.Mode = SimpleThemeMode.Dark;
+ this.Styles[0] = this._simpleTheme;
break;
case ApplicationTheme.FluentLight:
- this.Styles[0] = this._fluentLight;
- this.Styles.Remove(this._fluentDark);
- if (!this.Styles.Contains(this._baseLight))
- this.Styles.Add(this._baseLight);
+ this._fluentTheme.Mode = FluentThemeMode.Light;
+ this.Styles[0] = this._fluentTheme;
break;
case ApplicationTheme.FluentDark:
- this.Styles[0] = this._fluentDark;
- this.Styles.Remove(this._baseLight);
- if (!this.Styles.Contains(this._baseDark))
- this.Styles.Add(this._baseDark);
+ this._fluentTheme.Mode = FluentThemeMode.Dark;
+ this.Styles[0] = this._fluentTheme;
break;
}
}
diff --git a/src/ApplicationTheme.cs b/src/ApplicationTheme.cs
index 2323998..a7c55b0 100644
--- a/src/ApplicationTheme.cs
+++ b/src/ApplicationTheme.cs
@@ -4,8 +4,8 @@ namespace AvaloniaCoreRTDemo
{
public enum ApplicationTheme : Byte
{
- DefaultLight = 0,
- DefaultDark = 1,
+ SimpleLight = 0,
+ SimpleDark = 1,
FluentLight = 2,
FluentDark = 3,
}
diff --git a/src/AvaloniaCoreRTDemo.csproj b/src/AvaloniaCoreRTDemo.csproj
index 49ecbdf..274ea79 100644
--- a/src/AvaloniaCoreRTDemo.csproj
+++ b/src/AvaloniaCoreRTDemo.csproj
@@ -9,10 +9,10 @@
true
link
+
true
true
true
- OSX
@@ -30,31 +30,34 @@
-
-
- PreserveNewest
-
-
+
+
PreserveNewest
-
+
+ PreserveNewest
+ PreserveNewest
+
+
+ PreserveNewest
PreserveNewest
-
-
-
-
+
+
+
+
+
-
+
-
+
$(AssemblyName)
$(AssemblyName)
com.$(username).$(AssemblyName)
@@ -76,33 +79,5 @@
-
-
-
-
- App.axaml
-
-
-
-
-
- MainControl.axaml
-
-
- AboutWindow.axaml
-
-
-
-
-
- MainWindow.axaml
-
-
-
-
-
- MainWindowMacOS.axaml
-
-
diff --git a/src/Controls/ViewModels/MainViewModel.cs b/src/Controls/ViewModels/MainViewModel.cs
index 29fc9f4..f1cea96 100644
--- a/src/Controls/ViewModels/MainViewModel.cs
+++ b/src/Controls/ViewModels/MainViewModel.cs
@@ -18,13 +18,10 @@ namespace AvaloniaCoreRTDemo.Controls.ViewModels
public MainViewModel()
{
- this._dotNetImage = Utilities.GetImageFromFile(GetImageFullPath("dotnet.png"));
- this._avaloniaImage = Utilities.GetImageFromFile(GetImageFullPath("avalonia.png"));
+ this._dotNetImage = Utilities.GetImageFromFile("dotnet.png");
+ this._avaloniaImage = Utilities.GetImageFromFile("avalonia.png");
}
- private static String GetImageFullPath(String fileName)
- => Path.Combine(AppDomain.CurrentDomain.BaseDirectory, fileName);
-
~MainViewModel()
{
this._dotNetImage.Dispose();
diff --git a/src/Program.cs b/src/Program.cs
index 8478e3c..c689c49 100644
--- a/src/Program.cs
+++ b/src/Program.cs
@@ -12,10 +12,6 @@ namespace AvaloniaCoreRTDemo
// Avalonia configuration, don't remove; also used by visual designer.
public static AppBuilder BuildAvaloniaApp()
=> AppBuilder.Configure().UsePlatformDetect()
- .UseAvaloniaNativeOSX()
.LogToTrace();
-
- private static AppBuilder UseAvaloniaNativeOSX(this AppBuilder appBuilder)
- => Utilities.IsOSX ? appBuilder.UseAvaloniaNative() : appBuilder;
}
}
diff --git a/src/Utilities.cs b/src/Utilities.cs
index 4296e91..3b740ec 100644
--- a/src/Utilities.cs
+++ b/src/Utilities.cs
@@ -1,10 +1,9 @@
using System;
using System.IO;
-using System.Linq;
-using System.Reflection;
using System.Runtime.InteropServices;
-
+using Avalonia;
using Avalonia.Media.Imaging;
+using Avalonia.Platform;
namespace AvaloniaCoreRTDemo
{
@@ -15,25 +14,24 @@ namespace AvaloniaCoreRTDemo
public static Bitmap GetImageFromResources(String fileName)
{
- Assembly asm = Assembly.GetExecutingAssembly();
- String resourceName = asm.GetManifestResourceNames().FirstOrDefault(str => str.EndsWith(fileName));
- if (resourceName != null)
- using (Stream bitmapStream = asm.GetManifestResourceStream(resourceName))
- return new Bitmap(bitmapStream);
- else
- return default;
+ var assetLoader = AvaloniaLocator.Current.GetRequiredService();
+ using var assetStream = assetLoader.Open(new Uri($"avares://AvaloniaCoreRTDemo/Images/{fileName}"));
+ return new Bitmap(assetStream);
}
public static Bitmap GetImageFromFile(String path)
{
try
{
- return new Bitmap(path);
+ return new Bitmap(GetImageFullPath(path));
}
catch (Exception)
{
return GetImageFromResources("broken-link.png");
}
}
+
+ private static String GetImageFullPath(String fileName)
+ => Path.Combine(AppDomain.CurrentDomain.BaseDirectory, fileName);
}
}
diff --git a/src/Windows/MainWindow.axaml b/src/Windows/MainWindow.axaml
index f912199..29db8e0 100644
--- a/src/Windows/MainWindow.axaml
+++ b/src/Windows/MainWindow.axaml
@@ -1,21 +1,29 @@
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/Windows/MainWindowMacOS.axaml b/src/Windows/MainWindowMacOS.axaml
deleted file mode 100644
index 4ea0793..0000000
--- a/src/Windows/MainWindowMacOS.axaml
+++ /dev/null
@@ -1,26 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/src/Windows/MainWindowMacOS.axaml.cs b/src/Windows/MainWindowMacOS.axaml.cs
deleted file mode 100644
index 9c25bcc..0000000
--- a/src/Windows/MainWindowMacOS.axaml.cs
+++ /dev/null
@@ -1,28 +0,0 @@
-using Avalonia;
-using Avalonia.Controls;
-using Avalonia.Markup.Xaml;
-
-using AvaloniaCoreRTDemo.Interfaces;
-using AvaloniaCoreRTDemo.Windows.ViewModels;
-
-namespace AvaloniaCoreRTDemo.Windows
-{
- public partial class MainWindowMacOS : Window, IMainWindow
- {
- public MainWindowMacOS()
- {
- InitializeComponent();
-#if DEBUG
- this.AttachDevTools();
-#endif
- }
-
- private void InitializeComponent()
- {
- AvaloniaXamlLoader.Load(this);
- this.DataContext = new MainViewModel(this);
- }
-
- IThemeSwitch IMainWindow.ThemeSwitch => App.Current as IThemeSwitch;
- }
-}
diff --git a/src/Windows/ViewModels/MainViewModel.cs b/src/Windows/ViewModels/MainViewModel.cs
index a0acc74..b1b295e 100644
--- a/src/Windows/ViewModels/MainViewModel.cs
+++ b/src/Windows/ViewModels/MainViewModel.cs
@@ -51,8 +51,8 @@ namespace AvaloniaCoreRTDemo.Windows.ViewModels
this.ChangeTheme(window.ThemeSwitch.Current);
}
- public void DefaultLightMethod() => this.ChangeTheme(ApplicationTheme.DefaultLight);
- public void DefaultDarkMethod() => this.ChangeTheme(ApplicationTheme.DefaultDark);
+ public void DefaultLightMethod() => this.ChangeTheme(ApplicationTheme.SimpleLight);
+ public void DefaultDarkMethod() => this.ChangeTheme(ApplicationTheme.SimpleDark);
public void FluentLightMethod() => this.ChangeTheme(ApplicationTheme.FluentLight);
public void FluentDarkMethod() => this.ChangeTheme(ApplicationTheme.FluentDark);
public override void HelpAboutMethod() => base.RunHelpAbout(this._window);
@@ -62,8 +62,8 @@ namespace AvaloniaCoreRTDemo.Windows.ViewModels
private void ChangeTheme(ApplicationTheme theme)
{
- this.DefaultLightEnabled = theme != ApplicationTheme.DefaultLight && theme != ApplicationTheme.FluentLight;
- this.DefaultDarkEnabled = theme != ApplicationTheme.DefaultDark && theme != ApplicationTheme.FluentDark;
+ this.DefaultLightEnabled = theme != ApplicationTheme.SimpleLight && theme != ApplicationTheme.FluentLight;
+ this.DefaultDarkEnabled = theme != ApplicationTheme.SimpleDark && theme != ApplicationTheme.FluentDark;
this.FluentLightEnabled = theme != ApplicationTheme.FluentLight;
this.FluentDarkEnabled = theme != ApplicationTheme.FluentDark;
this._window.ThemeSwitch?.ChangeTheme(theme);
diff --git a/src/Windows/ViewModels/MainViewModelBase.cs b/src/Windows/ViewModels/MainViewModelBase.cs
index c7faffd..d2b0b53 100644
--- a/src/Windows/ViewModels/MainViewModelBase.cs
+++ b/src/Windows/ViewModels/MainViewModelBase.cs
@@ -41,7 +41,7 @@ namespace AvaloniaCoreRTDemo.Windows.ViewModels
private static Boolean IsDarkTheme(ApplicationTheme? theme)
=> theme switch
{
- ApplicationTheme.DefaultDark => true,
+ ApplicationTheme.SimpleDark => true,
ApplicationTheme.FluentDark => true,
_ => false,
};