Iuiuv3gZ~eN|J9y@V>zQSzQ_pL?yZ16)KDqn{Czle@@)KJQmmQjWAYQ$&
zvv-gFOf}D)y*s77ueQDP;^~HwlhqUA8fD-6?43slq?X~f<4-@T0;eBG4<~Ww%#!wH
zaM~1hwV_w+8t_U7jhGq|w`t7e+bl_rY+B3?J5Vyvrtap~(wj{>ky$tO9-ok9Pk5DzLOTebkzzVS{
zaCN2(vw^ay@NuM)f=Y>D27stB8rt%mHgQcdlEIi~`;^pRvto4s_J`TFbvA+N{{@RN
BtNs80
literal 0
HcmV?d00001
diff --git a/src/Interfaces/IMainWindow.cs b/src/Interfaces/IMainWindow.cs
new file mode 100644
index 0000000..2f8b2a8
--- /dev/null
+++ b/src/Interfaces/IMainWindow.cs
@@ -0,0 +1,9 @@
+using AvaloniaCoreRTDemo.Interfaces;
+
+namespace AvaloniaCoreRTDemo
+{
+ public interface IMainWindow
+ {
+ IThemeSwitch ThemeSwitch { get; }
+ }
+}
diff --git a/src/Interfaces/IThemeSwitch.cs b/src/Interfaces/IThemeSwitch.cs
new file mode 100644
index 0000000..45815dc
--- /dev/null
+++ b/src/Interfaces/IThemeSwitch.cs
@@ -0,0 +1,8 @@
+namespace AvaloniaCoreRTDemo.Interfaces
+{
+ public interface IThemeSwitch
+ {
+ ApplicationTheme Current { get; }
+ void ChangeTheme(ApplicationTheme theme);
+ }
+}
diff --git a/src/MainWindow.xaml b/src/MainWindow.xaml
deleted file mode 100644
index 915b90a..0000000
--- a/src/MainWindow.xaml
+++ /dev/null
@@ -1,29 +0,0 @@
-
-
-
-
- Welcome to Avalonia UI + CoreRT!
-
-
-
-
-
-
-
diff --git a/src/MainWindowViewModel.cs b/src/MainWindowViewModel.cs
deleted file mode 100644
index fad3eb4..0000000
--- a/src/MainWindowViewModel.cs
+++ /dev/null
@@ -1,50 +0,0 @@
-using Avalonia.Media.Imaging;
-using ReactiveUI;
-using System;
-using System.Reactive;
-using Path = System.IO.Path;
-
-namespace AvaloniaCoreRTDemo
-{
- public class MainWindowViewModel: ReactiveObject
- {
- public MainWindowViewModel(MainWindow window)
- {
- _window = window;
-
- DotNetImage = new Bitmap(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "dotnet.png"));
- AvaloniaImage = new Bitmap(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "avalonia.png"));
-
- FileExitCommand = ReactiveCommand.Create(RunFileExit);
- }
-
- public IBitmap DotNetImage
- {
- get { return dotNetImage; }
- set { this.RaiseAndSetIfChanged(ref this.dotNetImage, value); }
- }
-
- public IBitmap AvaloniaImage
- {
- get { return avaloniaImage; }
- set { this.RaiseAndSetIfChanged(ref this.avaloniaImage, value); }
- }
-
- public ReactiveCommand FileExitCommand { get; }
- public void HelpAboutMethod() => RunHelpAbout();
-
- void RunFileExit()
- {
- Environment.Exit(0);
- }
-
- void RunHelpAbout()
- {
- new AboutWindow().ShowDialog(_window);
- }
-
- private IBitmap dotNetImage;
- private IBitmap avaloniaImage;
- private readonly MainWindow _window;
- }
-}
\ No newline at end of file
diff --git a/src/Program.cs b/src/Program.cs
index a90b6af..0bde694 100644
--- a/src/Program.cs
+++ b/src/Program.cs
@@ -1,4 +1,5 @@
-using Avalonia;
+
+using Avalonia;
namespace AvaloniaCoreRTDemo
{
@@ -7,13 +8,14 @@ namespace AvaloniaCoreRTDemo
// Initialization code. Don't use any Avalonia, third-party APIs or any
// SynchronizationContext-reliant code before AppMain is called: things aren't initialized
// yet and stuff might break.
- public static void Main(string[] args) => BuildAvaloniaApp()
- .StartWithClassicDesktopLifetime(args);
+ public static void Main(string[] args) => BuildAvaloniaApp().StartWithClassicDesktopLifetime(args);
// Avalonia configuration, don't remove; also used by visual designer.
public static AppBuilder BuildAvaloniaApp()
- => AppBuilder.Configure()
- .UsePlatformDetect()
- .LogToTrace();
+ => AppBuilder.Configure().UsePlatformDetect()
+#if OSX
+ .UseAvaloniaNative()
+#endif
+ .LogToTrace();
}
}
diff --git a/src/Windows/AboutWindow.axaml b/src/Windows/AboutWindow.axaml
new file mode 100644
index 0000000..8ef32d8
--- /dev/null
+++ b/src/Windows/AboutWindow.axaml
@@ -0,0 +1,64 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/Windows/AboutWindow.axaml.cs b/src/Windows/AboutWindow.axaml.cs
new file mode 100644
index 0000000..4b9ca92
--- /dev/null
+++ b/src/Windows/AboutWindow.axaml.cs
@@ -0,0 +1,28 @@
+using System;
+
+using Avalonia.Controls;
+using Avalonia.Markup.Xaml;
+
+using AvaloniaCoreRTDemo.Windows.ViewModels;
+
+namespace AvaloniaCoreRTDemo.Windows
+{
+ public sealed partial class AboutWindow : Window
+ {
+ public AboutWindow()
+ {
+ this.InitializeComponent();
+ }
+
+ public AboutWindow(Boolean darkTheme)
+ {
+ this.InitializeComponent(darkTheme);
+ }
+
+ private void InitializeComponent(Boolean darkTheme = default)
+ {
+ AvaloniaXamlLoader.Load(this);
+ this.DataContext = new AboutViewModel(darkTheme);
+ }
+ }
+}
diff --git a/src/Windows/MainWindow.axaml b/src/Windows/MainWindow.axaml
new file mode 100644
index 0000000..f912199
--- /dev/null
+++ b/src/Windows/MainWindow.axaml
@@ -0,0 +1,21 @@
+
+
+
+
+
+
diff --git a/src/Windows/MainWindow.axaml.cs b/src/Windows/MainWindow.axaml.cs
new file mode 100644
index 0000000..a846014
--- /dev/null
+++ b/src/Windows/MainWindow.axaml.cs
@@ -0,0 +1,28 @@
+using Avalonia;
+using Avalonia.Controls;
+using Avalonia.Markup.Xaml;
+
+using AvaloniaCoreRTDemo.Interfaces;
+using AvaloniaCoreRTDemo.Windows.ViewModels;
+
+namespace AvaloniaCoreRTDemo.Windows
+{
+ public sealed partial class MainWindow : Window, IMainWindow
+ {
+ public MainWindow()
+ {
+ 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/MainWindowMacOS.axaml b/src/Windows/MainWindowMacOS.axaml
new file mode 100644
index 0000000..4ea0793
--- /dev/null
+++ b/src/Windows/MainWindowMacOS.axaml
@@ -0,0 +1,26 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/Windows/MainWindowMacOS.axaml.cs b/src/Windows/MainWindowMacOS.axaml.cs
new file mode 100644
index 0000000..9c25bcc
--- /dev/null
+++ b/src/Windows/MainWindowMacOS.axaml.cs
@@ -0,0 +1,28 @@
+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/AboutViewModel.cs b/src/Windows/ViewModels/AboutViewModel.cs
new file mode 100644
index 0000000..ee4b0a9
--- /dev/null
+++ b/src/Windows/ViewModels/AboutViewModel.cs
@@ -0,0 +1,68 @@
+using System;
+using System.IO;
+using System.Linq;
+using System.Reflection;
+using System.Runtime.InteropServices;
+
+using Avalonia.Media.Imaging;
+
+using ReactiveUI;
+
+namespace AvaloniaCoreRTDemo.Windows.ViewModels
+{
+ internal sealed class AboutViewModel : ReactiveObject
+ {
+ private readonly IBitmap _computerImage;
+ private readonly Boolean _darkTheme;
+
+ public IBitmap ComputerImage => _computerImage;
+ public static String NCores => Environment.ProcessorCount.ToString();
+ public static String OS => RuntimeInformation.OSDescription;
+ public static String OSArch => RuntimeInformation.OSArchitecture.ToString();
+ public static String OSVersion => Environment.OSVersion.ToString();
+ public static String ComputerName => Environment.MachineName;
+ public static String UserName => Environment.UserName;
+ public static String SystemPath => Environment.SystemDirectory;
+ public static String CurrentPath => Environment.CurrentDirectory;
+ public static String ProcessArch => RuntimeInformation.ProcessArchitecture.ToString();
+ public static String RuntimeName => RuntimeInformation.FrameworkDescription;
+ public static String RuntimePath => RuntimeEnvironment.GetRuntimeDirectory();
+ public static String RuntimeVersion => RuntimeEnvironment.GetSystemVersion();
+ public static String FrameworkVersion => Environment.Version.ToString();
+
+ private String ComputerImageName
+ {
+ get
+ {
+ if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
+ return !_darkTheme ? "windows.png" : "windows_d.png";
+ else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
+ return !_darkTheme ? "macos.png" : "macos_d.png";
+ else
+ return !_darkTheme ? "linux.png" : "linux_d.png";
+ }
+ }
+
+ public AboutViewModel(Boolean darkTheme)
+ {
+ this._darkTheme = darkTheme;
+ this._computerImage = GetImageFromResources(this.ComputerImageName);
+ }
+
+ ~AboutViewModel()
+ {
+ this._computerImage.Dispose();
+ }
+
+ private 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;
+ }
+ }
+}
diff --git a/src/Windows/ViewModels/MainViewModel.cs b/src/Windows/ViewModels/MainViewModel.cs
new file mode 100644
index 0000000..1a72964
--- /dev/null
+++ b/src/Windows/ViewModels/MainViewModel.cs
@@ -0,0 +1,72 @@
+using System;
+using System.Reactive;
+
+using Avalonia.Controls;
+
+using ReactiveUI;
+
+namespace AvaloniaCoreRTDemo.Windows.ViewModels
+{
+ internal sealed class MainViewModel : MainViewModelBase
+ where TWindow : Window, IMainWindow
+ {
+ private readonly TWindow _window;
+
+ private Boolean _defaultLightEnable = true;
+ private Boolean _defaultDarkEnable = true;
+ private Boolean _fluentLightEnable = true;
+ private Boolean _fluentDarkEnable = true;
+
+ public Boolean DefaultLightEnabled
+ {
+ get => this._defaultLightEnable;
+ set => this.RaiseAndSetIfChanged(ref this._defaultLightEnable, value);
+ }
+
+ public Boolean DefaultDarkEnabled
+ {
+ get => this._defaultDarkEnable;
+ set => this.RaiseAndSetIfChanged(ref this._defaultDarkEnable, value);
+ }
+
+ public Boolean FluentLightEnabled
+ {
+ get => this._fluentLightEnable;
+ set => this.RaiseAndSetIfChanged(ref this._fluentLightEnable, value);
+ }
+
+ public Boolean FluentDarkEnabled
+ {
+ get => this._fluentDarkEnable;
+ set => this.RaiseAndSetIfChanged(ref this._fluentDarkEnable, value);
+ }
+
+ public ReactiveCommand FileExitCommand { get; }
+
+ public MainViewModel(TWindow window)
+ : base(window.ThemeSwitch)
+ {
+ this._window = window;
+ this.FileExitCommand = ReactiveCommand.Create(RunFileExit);
+ this.ChangeTheme(window.ThemeSwitch.Current);
+ }
+
+ public void DefaultLightMethod() => this.ChangeTheme(ApplicationTheme.DefaultLight);
+ public void DefaultDarkMethod() => this.ChangeTheme(ApplicationTheme.DefaultDark);
+ public void FluentLightMethod() => this.ChangeTheme(ApplicationTheme.FluentLight);
+ public void FluentDarkMethod() => this.ChangeTheme(ApplicationTheme.FluentDark);
+ public void HelpAboutMethod() => base.RunHelpAbout(this._window);
+
+ private void RunFileExit()
+ => Environment.Exit(0);
+
+ private void ChangeTheme(ApplicationTheme theme)
+ {
+ this.DefaultLightEnabled = theme != ApplicationTheme.DefaultLight && theme != ApplicationTheme.FluentLight;
+ this.DefaultDarkEnabled = theme != ApplicationTheme.DefaultDark && 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
new file mode 100644
index 0000000..9c9f2c6
--- /dev/null
+++ b/src/Windows/ViewModels/MainViewModelBase.cs
@@ -0,0 +1,51 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+using Avalonia.Controls;
+
+using AvaloniaCoreRTDemo.Interfaces;
+
+using ReactiveUI;
+
+namespace AvaloniaCoreRTDemo.Windows.ViewModels
+{
+ internal abstract class MainViewModelBase : ReactiveObject
+ {
+ private readonly IThemeSwitch _themeSwitch;
+ private Boolean _aboutEnable = true;
+
+ public Boolean AboutEnabled
+ {
+ get => this._aboutEnable;
+ set => this.RaiseAndSetIfChanged(ref this._aboutEnable, value);
+ }
+
+ public MainViewModelBase(IThemeSwitch window)
+ => this._themeSwitch = window;
+
+ protected async void RunHelpAbout(Window currentWindow)
+ {
+ if (this.AboutEnabled)
+ try
+ {
+ this.AboutEnabled = false;
+ await new AboutWindow(IsDarkTheme(this._themeSwitch.Current)).ShowDialog(currentWindow);
+ }
+ finally
+ {
+ this.AboutEnabled = true;
+ }
+ }
+
+ private static Boolean IsDarkTheme(ApplicationTheme? theme)
+ => theme switch
+ {
+ ApplicationTheme.DefaultDark => true,
+ ApplicationTheme.FluentDark => true,
+ _ => false,
+ };
+ }
+}
diff --git a/src/nuget.config b/src/nuget.config
index 8afae99..1dfbeae 100644
--- a/src/nuget.config
+++ b/src/nuget.config
@@ -1,11 +1,7 @@
-
-
-
-
-
+
diff --git a/src/rd.xml b/src/rd.xml
index fa7ccfe..8e5aae8 100644
--- a/src/rd.xml
+++ b/src/rd.xml
@@ -9,6 +9,9 @@
+
+
+