From aa09803e58a04ffa85c082b9a2705c729ca100f7 Mon Sep 17 00:00:00 2001 From: Dan Walmsley Date: Wed, 19 Oct 2022 15:10:00 +0100 Subject: [PATCH] add a platform info page to control catalog that tells user where avalonia thinks its running, --- samples/ControlCatalog/MainView.xaml | 11 ++-- .../Pages/PlatformInfoPage.xaml | 12 +++++ .../Pages/PlatformInfoPage.xaml.cs | 21 ++++++++ .../PlatformInformationViewModel.cs | 54 +++++++++++++++++++ 4 files changed, 94 insertions(+), 4 deletions(-) create mode 100644 samples/ControlCatalog/Pages/PlatformInfoPage.xaml create mode 100644 samples/ControlCatalog/Pages/PlatformInfoPage.xaml.cs create mode 100644 samples/ControlCatalog/ViewModels/PlatformInformationViewModel.cs diff --git a/samples/ControlCatalog/MainView.xaml b/samples/ControlCatalog/MainView.xaml index ec198c6bba..d3b834d55e 100644 --- a/samples/ControlCatalog/MainView.xaml +++ b/samples/ControlCatalog/MainView.xaml @@ -12,8 +12,11 @@ - - + + + + + @@ -118,7 +121,7 @@ - + @@ -130,7 +133,7 @@ - + diff --git a/samples/ControlCatalog/Pages/PlatformInfoPage.xaml b/samples/ControlCatalog/Pages/PlatformInfoPage.xaml new file mode 100644 index 0000000000..a8dd24971d --- /dev/null +++ b/samples/ControlCatalog/Pages/PlatformInfoPage.xaml @@ -0,0 +1,12 @@ + + + + + diff --git a/samples/ControlCatalog/Pages/PlatformInfoPage.xaml.cs b/samples/ControlCatalog/Pages/PlatformInfoPage.xaml.cs new file mode 100644 index 0000000000..fdd3c6f771 --- /dev/null +++ b/samples/ControlCatalog/Pages/PlatformInfoPage.xaml.cs @@ -0,0 +1,21 @@ +using Avalonia; +using Avalonia.Controls; +using Avalonia.Markup.Xaml; +using ControlCatalog.ViewModels; + +namespace ControlCatalog.Pages +{ + public class PlatformInfoPage : UserControl + { + public PlatformInfoPage() + { + this.InitializeComponent(); + DataContext = new PlatformInformationViewModel(); + } + + private void InitializeComponent() + { + AvaloniaXamlLoader.Load(this); + } + } +} diff --git a/samples/ControlCatalog/ViewModels/PlatformInformationViewModel.cs b/samples/ControlCatalog/ViewModels/PlatformInformationViewModel.cs new file mode 100644 index 0000000000..e4f6c3ac73 --- /dev/null +++ b/samples/ControlCatalog/ViewModels/PlatformInformationViewModel.cs @@ -0,0 +1,54 @@ +using Avalonia; +using Avalonia.Platform; +using MiniMvvm; + +namespace ControlCatalog.ViewModels; +#nullable enable + +public class PlatformInformationViewModel : ViewModelBase +{ + public PlatformInformationViewModel() + { + var runtimeInfo = AvaloniaLocator.Current.GetService()?.GetRuntimeInfo(); + + if (runtimeInfo is { } info) + { + if (info.IsBrowser) + { + if (info.IsDesktop) + { + PlatformInfo = "Platform: Desktop (browser)"; + } + else if (info.IsMobile) + { + PlatformInfo = "Platform: Mobile (browser)"; + } + else + { + PlatformInfo = "Platform: Unknown (browser) - please report"; + } + } + else + { + if (info.IsDesktop) + { + PlatformInfo = "Platform: Desktop (native)"; + } + else if (info.IsMobile) + { + PlatformInfo = "Platform: Mobile (native)"; + } + else + { + PlatformInfo = "Platform: Unknown (native) - please report"; + } + } + } + else + { + + } + } + + public string PlatformInfo { get; } +}