diff --git a/src/AboutWindow.xaml b/src/AboutWindow.xaml new file mode 100644 index 0000000..14a606e --- /dev/null +++ b/src/AboutWindow.xaml @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/AboutWindow.xaml.cs b/src/AboutWindow.xaml.cs new file mode 100644 index 0000000..e749cf2 --- /dev/null +++ b/src/AboutWindow.xaml.cs @@ -0,0 +1,20 @@ +using Avalonia; +using Avalonia.Controls; +using Avalonia.Markup.Xaml; + +namespace AvaloniaCoreRTDemo +{ + public class AboutWindow : Window + { + public AboutWindow() + { + this.InitializeComponent(); + this.DataContext = new AboutWindowViewModel(); + } + + private void InitializeComponent() + { + AvaloniaXamlLoader.Load(this); + } + } +} diff --git a/src/AboutWindowViewModel.cs b/src/AboutWindowViewModel.cs new file mode 100644 index 0000000..9b443b3 --- /dev/null +++ b/src/AboutWindowViewModel.cs @@ -0,0 +1,63 @@ +using System; +using System.IO; +using System.Linq; +using System.Reflection; +using System.Runtime.InteropServices; +using Avalonia.Media.Imaging; +using ReactiveUI; +namespace AvaloniaCoreRTDemo +{ + public class AboutWindowViewModel : ReactiveObject + { + private readonly IBitmap computerImage; + + public IBitmap ComputerImage => computerImage; + public String NCores => Environment.ProcessorCount.ToString(); + public String OS => RuntimeInformation.OSDescription; + public String OSArch => RuntimeInformation.OSArchitecture.ToString(); + public String OSVersion => Environment.OSVersion.ToString(); + public String ComputerName => Environment.MachineName; + public String UserName => Environment.UserName; + public String SystemPath => Environment.SystemDirectory; + public String CurrentPath => Environment.CurrentDirectory; + public String ProcessArch => RuntimeInformation.ProcessArchitecture.ToString(); + public String RuntimeName => RuntimeInformation.FrameworkDescription; + public String RuntimePath => RuntimeEnvironment.GetRuntimeDirectory(); + public String RuntimeVersion => RuntimeEnvironment.GetSystemVersion(); + public String FrameworkVersion => Environment.Version.ToString(); + + private String ComputerImageName + { + get + { + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + return "windows.png"; + else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) + return "macos.png"; + else + return "linux.png"; + } + } + + public AboutWindowViewModel() + { + this.computerImage = GetImageFromResources(this.ComputerImageName); + } + + ~AboutWindowViewModel() + { + 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 a = asm.GetManifestResourceStream(resourceName)) + return new Bitmap(a); + else + return null; + } + } +} diff --git a/src/AvaloniaCoreRTDemo.csproj b/src/AvaloniaCoreRTDemo.csproj index f969a99..14802fc 100644 --- a/src/AvaloniaCoreRTDemo.csproj +++ b/src/AvaloniaCoreRTDemo.csproj @@ -28,6 +28,10 @@ Designer + + + + diff --git a/src/MainWindow.xaml b/src/MainWindow.xaml index de08c48..915b90a 100644 --- a/src/MainWindow.xaml +++ b/src/MainWindow.xaml @@ -6,14 +6,16 @@ x:Class="AvaloniaCoreRTDemo.MainWindow" Width="640" Height="480" WindowStartupLocation="CenterScreen" - Title="AvaloniaCoreRTDemo"> + Title="AvaloniaCoreRTDemo" + Icon="avares://AvaloniaCoreRTDemo/app.ico" + MinWidth="400" MinHeight="350"> - + diff --git a/src/MainWindow.xaml.cs b/src/MainWindow.xaml.cs index 0be15b3..d170c3e 100644 --- a/src/MainWindow.xaml.cs +++ b/src/MainWindow.xaml.cs @@ -10,7 +10,7 @@ namespace AvaloniaCoreRTDemo public MainWindow() { InitializeComponent(); - this.DataContext = new MainWindowViewModel(); + this.DataContext = new MainWindowViewModel(this); } private void InitializeComponent() diff --git a/src/MainWindowViewModel.cs b/src/MainWindowViewModel.cs index 37b96d0..e61fb39 100644 --- a/src/MainWindowViewModel.cs +++ b/src/MainWindowViewModel.cs @@ -9,13 +9,14 @@ namespace AvaloniaCoreRTDemo { public class MainWindowViewModel: ReactiveObject { - public MainWindowViewModel() + 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); - HelpAboutCommand = ReactiveCommand.Create(RunHelpAbout); } public IBitmap DotNetImage @@ -31,7 +32,7 @@ namespace AvaloniaCoreRTDemo } public ReactiveCommand FileExitCommand { get; } - public ReactiveCommand HelpAboutCommand { get; } + public void HelpAboutMethod() => RunHelpAbout(); void RunFileExit() { @@ -40,10 +41,11 @@ namespace AvaloniaCoreRTDemo void RunHelpAbout() { - // Code for executing the command here. + new AboutWindow().ShowDialog(_window); } private IBitmap dotNetImage; private IBitmap avaloniaImage; + private readonly MainWindow _window; } } \ No newline at end of file diff --git a/src/app.ico b/src/app.ico new file mode 100644 index 0000000..7efe7fb Binary files /dev/null and b/src/app.ico differ diff --git a/src/linux.png b/src/linux.png new file mode 100644 index 0000000..52ec65e Binary files /dev/null and b/src/linux.png differ diff --git a/src/macos.png b/src/macos.png new file mode 100644 index 0000000..0544e48 Binary files /dev/null and b/src/macos.png differ diff --git a/src/windows.png b/src/windows.png new file mode 100644 index 0000000..5f70a19 Binary files /dev/null and b/src/windows.png differ