Browse Source

Hide scrollbars on ScrollViewer when not needed.

Also added an image size slider to test.
pull/4/head
Steven Kirk 11 years ago
parent
commit
73ebfc9475
  1. 3
      Perspex.Controls/Primitives/ScrollBar.cs
  2. 4
      Perspex.Controls/Primitives/Track.cs
  3. 12
      Perspex.Controls/ScrollViewer.cs
  4. 2
      Perspex.Layout/LayoutManager.cs
  5. 15
      TestApplication/Program.cs

3
Perspex.Controls/Primitives/ScrollBar.cs

@ -7,6 +7,7 @@
namespace Perspex.Controls.Primitives
{
using System;
using System.Reactive.Linq;
public class ScrollBar : TemplatedControl
{
@ -27,6 +28,8 @@ namespace Perspex.Controls.Primitives
public ScrollBar()
{
this.Classes.Add(":vertical");
this.GetObservable(OrientationProperty).Subscribe(o =>
{
if (o == Orientation.Horizontal)

4
Perspex.Controls/Primitives/Track.cs

@ -119,9 +119,9 @@ namespace Perspex.Controls.Primitives
{
var range = this.Maximum - this.Minimum;
var thumbFraction = this.ViewportSize / range;
var valueFraction = this.Value / range;
var valueFraction = (this.Value - this.Minimum) / range;
if (double.IsNaN(thumbFraction))
if (double.IsNaN(thumbFraction) || double.IsInfinity(thumbFraction))
{
thumbFraction = 0;
}

12
Perspex.Controls/ScrollViewer.cs

@ -60,9 +60,9 @@ namespace Perspex.Controls
this.GetObservable(ViewportProperty).StartWith(this.Viewport))
.Select(x => new { Extent = x[0], Viewport = x[1] });
//this.horizontalScrollBar.Bind(
// IsVisibleProperty,
// extentAndViewport.Select(x => x.Extent.Width > x.Viewport.Width));
this.horizontalScrollBar.Bind(
IsVisibleProperty,
extentAndViewport.Select(x => x.Extent.Width > x.Viewport.Width));
this.horizontalScrollBar.Bind(
ScrollBar.MaximumProperty,
@ -72,9 +72,9 @@ namespace Perspex.Controls
ScrollBar.ViewportSizeProperty,
extentAndViewport.Select(x => x.Viewport.Width));
//this.verticalScrollBar.Bind(
// IsVisibleProperty,
// extentAndViewport.Select(x => x.Extent.Height > x.Viewport.Height));
this.verticalScrollBar.Bind(
IsVisibleProperty,
extentAndViewport.Select(x => x.Extent.Height > x.Viewport.Height));
this.verticalScrollBar.Bind(
ScrollBar.MaximumProperty,

2
Perspex.Layout/LayoutManager.cs

@ -37,9 +37,9 @@ namespace Perspex.Layout
public void ExecuteLayoutPass()
{
this.LayoutQueued = false;
this.root.Measure(this.root.ClientSize);
this.root.Arrange(new Rect(this.root.ClientSize));
this.LayoutQueued = false;
}
public void InvalidateMeasure(ILayoutable item)

15
TestApplication/Program.cs

@ -203,6 +203,8 @@ namespace TestApplication
private static TabItem ImagesTab()
{
ScrollBar size;
return new TabItem
{
Header = "Images",
@ -214,6 +216,13 @@ namespace TestApplication
Gap = 8,
Children = new Controls
{
(size = new ScrollBar
{
Minimum = 100,
Maximum = 400,
Value = 400,
Orientation = Orientation.Horizontal,
}),
new ScrollViewer
{
Width = 200,
@ -221,10 +230,10 @@ namespace TestApplication
Content = new Image
{
Source = new Bitmap("github_icon.png"),
Width = 400,
Height = 400,
[!Image.WidthProperty] = size[!ScrollBar.ValueProperty],
[!Image.HeightProperty] = size[!ScrollBar.ValueProperty],
},
}
},
}
},
};

Loading…
Cancel
Save