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; } +}