Explorar o código

add a platform info page to control catalog that tells user where avalonia thinks its running,

Dan Walmsley %!s(int64=3) %!d(string=hai) anos
pai
achega
aa09803e58

+ 7 - 4
samples/ControlCatalog/MainView.xaml

@@ -12,8 +12,11 @@
         <Setter Property="HorizontalAlignment" Value="Left" />
       </Style>
     </Grid.Styles>
-    <controls:HamburgerMenu Name="Sidebar">
-      <TabItem Header="Composition">
+      <controls:HamburgerMenu Name="Sidebar">
+        <TabItem Header="Platform Information">
+          <pages:PlatformInfoPage />
+        </TabItem>
+        <TabItem Header="Composition">
         <pages:CompositionPage/>
       </TabItem>
       <TabItem Header="Acrylic">
@@ -118,7 +121,7 @@
       <TabItem Header="OpenGL">
         <pages:OpenGlPage />
       </TabItem>
-      <TabItem Header="Pointers">
+        <TabItem Header="Pointers">
         <pages:PointersPage />
       </TabItem>
       <TabItem Header="ProgressBar">
@@ -130,7 +133,7 @@
       <TabItem Header="RelativePanel">
         <pages:RelativePanelPage />
       </TabItem>
-      <TabItem Header="ScrollViewer">
+        <TabItem Header="ScrollViewer">
         <pages:ScrollViewerPage />
       </TabItem>
       <TabItem Header="Slider">

+ 12 - 0
samples/ControlCatalog/Pages/PlatformInfoPage.xaml

@@ -0,0 +1,12 @@
+<UserControl x:Class="ControlCatalog.Pages.PlatformInfoPage"
+             xmlns="https://github.com/avaloniaui"
+             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
+             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
+             d:DesignHeight="800"
+             d:DesignWidth="400"
+             mc:Ignorable="d">
+  <StackPanel>
+    <TextBlock Text="{Binding PlatformInfo}" />
+  </StackPanel>
+</UserControl>

+ 21 - 0
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);
+        }
+    }
+}

+ 54 - 0
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<IRuntimePlatform>()?.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; }
+}