Jelajahi Sumber

Merge pull request #11124 from AvaloniaUI/add-scaling-properties

Adds RenderScaling and DesktopScaling back to the public API together with ScalingChanged
Steven Kirk 2 tahun lalu
induk
melakukan
c8f3237b87
2 mengubah file dengan 12 tambahan dan 1 penghapusan
  1. 7 1
      src/Avalonia.Controls/TopLevel.cs
  2. 5 0
      src/Avalonia.Controls/WindowBase.cs

+ 7 - 1
src/Avalonia.Controls/TopLevel.cs

@@ -285,6 +285,11 @@ namespace Avalonia.Controls
         /// </summary>
         public event EventHandler? Closed;
 
+        /// <summary>
+        /// Gets or sets a method called when the TopLevel's scaling changes.
+        /// </summary>
+        public event EventHandler? ScalingChanged;
+        
         /// <summary>
         /// Gets or sets the client size of the window.
         /// </summary>
@@ -428,7 +433,7 @@ namespace Avalonia.Controls
         double ILayoutRoot.LayoutScaling => PlatformImpl?.RenderScaling ?? 1;
 
         /// <inheritdoc/>
-        double IRenderRoot.RenderScaling => PlatformImpl?.RenderScaling ?? 1;
+        public double RenderScaling => PlatformImpl?.RenderScaling ?? 1;
 
         IStyleHost IStyleHost.StylingParent => _globalStyles!;
         
@@ -590,6 +595,7 @@ namespace Avalonia.Controls
         protected virtual void HandleScalingChanged(double scaling)
         {
             LayoutHelper.InvalidateSelfAndChildrenMeasure(this);
+            ScalingChanged?.Invoke(this, EventArgs.Empty);
         }
 
         private static bool TransparencyLevelsMatch (WindowTransparencyLevel requested, WindowTransparencyLevel received)

+ 5 - 0
src/Avalonia.Controls/WindowBase.cs

@@ -116,6 +116,11 @@ namespace Avalonia.Controls
             set { SetValue(TopmostProperty, value); }
         }
 
+        /// <summary>
+        /// Gets the scaling factor for Window positioning and sizing.
+        /// </summary>
+        public double DesktopScaling => PlatformImpl?.DesktopScaling ?? 1;
+        
         /// <summary>
         /// Activates the window.
         /// </summary>