Browse Source

implemented ScrollSize from IScrollable.

danwalmsley 9 years ago
parent
commit
8e9cf40ead

+ 16 - 0
samples/XamlTestApplicationPcl/TestScrollable.cs

@@ -37,6 +37,22 @@ namespace XamlTestApplication
             get { return _viewport; }
         }
 
+        public Size ScrollSize
+        {
+            get
+            {
+                return new Size(double.PositiveInfinity, 1);
+            }
+        }
+
+        public Size PageScrollSize
+        {
+            get
+            {
+                return new Size(double.PositiveInfinity, Bounds.Height);
+            }
+        }
+
         protected override Size MeasureOverride(Size availableSize)
         {
             using (var line = new FormattedText(

+ 18 - 5
src/Perspex.Controls/Presenters/ScrollContentPresenter.cs

@@ -220,11 +220,24 @@ namespace Perspex.Controls.Presenters
         {
             if (Extent.Height > Viewport.Height)
             {
-                var y = Offset.Y + (-e.Delta.Y * 50);
-                y = Math.Max(y, 0);
-                y = Math.Min(y, Extent.Height - Viewport.Height);
-                Offset = new Vector(Offset.X, y);
-                e.Handled = true;
+                var scrollable = Child as IScrollable;
+
+                if (scrollable != null)
+                {                    
+                    var y = Offset.Y + (-e.Delta.Y * scrollable.ScrollSize.Height);
+                    y = Math.Max(y, 0);
+                    y = Math.Min(y, Extent.Height - Viewport.Height);
+                    Offset = new Vector(Offset.X, y);
+                    e.Handled = true;
+                }
+                else
+                {
+                    var y = Offset.Y + (-e.Delta.Y * 50);
+                    y = Math.Max(y, 0);
+                    y = Math.Min(y, Extent.Height - Viewport.Height);
+                    Offset = new Vector(Offset.X, y);
+                    e.Handled = true;
+                }
             }
         }
 

+ 10 - 0
src/Perspex.Controls/Primitives/IScrollable.cs

@@ -40,5 +40,15 @@ namespace Perspex.Controls.Primitives
         /// Gets the size of the viewport, in logical units.
         /// </summary>
         Size Viewport { get; }
+
+        /// <summary>
+        /// Gets the size to scroll by, in logical units.
+        /// </summary>
+        Size ScrollSize { get; }
+
+        /// <summary>
+        /// Gets the size to page by, in logical units.
+        /// </summary>
+        Size PageScrollSize { get; }
     }
 }