From bf9071dcd057a377cd094b2699ba332d25154322 Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Mon, 4 May 2015 11:54:05 +0200 Subject: [PATCH] Fix ScrollBar.Value. Wasn't being updated inside ListBox and this is why... --- Perspex.Controls/Primitives/ScrollBar.cs | 13 +++++++++++++ Perspex.Themes.Default/ScrollBarStyle.cs | 2 +- Perspex.Themes.Default/ScrollViewerStyle.cs | 16 +++++++++++----- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/Perspex.Controls/Primitives/ScrollBar.cs b/Perspex.Controls/Primitives/ScrollBar.cs index 523edba956..4b36ff8a51 100644 --- a/Perspex.Controls/Primitives/ScrollBar.cs +++ b/Perspex.Controls/Primitives/ScrollBar.cs @@ -9,6 +9,7 @@ namespace Perspex.Controls.Primitives using System; using System.Reactive; using System.Reactive.Linq; + using Perspex.Controls.Templates; public class ScrollBar : TemplatedControl { @@ -88,6 +89,18 @@ namespace Perspex.Controls.Primitives return base.MeasureOverride(availableSize); } + protected override void OnTemplateApplied() + { + base.OnTemplateApplied(); + + // Binding between this.Value and track.Value must be done explicitly like this rather + // than using standard bindings as it shouldn't be able to to be overridden by binding + // e.g. ScrollBar.Value. + var track = this.GetTemplateChild("track"); + track.GetObservable(ValueProperty).Subscribe(x => this.Value = x); + this.GetObservable(ValueProperty).Subscribe(x => track.Value = x); + } + private bool CalculateIsVisible() { switch (this.Visibility) diff --git a/Perspex.Themes.Default/ScrollBarStyle.cs b/Perspex.Themes.Default/ScrollBarStyle.cs index 21c5ba10a7..452a7228b3 100644 --- a/Perspex.Themes.Default/ScrollBarStyle.cs +++ b/Perspex.Themes.Default/ScrollBarStyle.cs @@ -66,9 +66,9 @@ namespace Perspex.Themes.Default Background = Brushes.Silver, Content = new Track { + Id = "track", [~Track.MinimumProperty] = control[~ScrollBar.MinimumProperty], [~Track.MaximumProperty] = control[~ScrollBar.MaximumProperty], - [~~Track.ValueProperty] = control[~ScrollBar.ValueProperty], [~Track.ViewportSizeProperty] = control[~ScrollBar.ViewportSizeProperty], [~Track.OrientationProperty] = control[~ScrollBar.OrientationProperty], Thumb = new Thumb diff --git a/Perspex.Themes.Default/ScrollViewerStyle.cs b/Perspex.Themes.Default/ScrollViewerStyle.cs index 7a14e1cd65..00c65fcb69 100644 --- a/Perspex.Themes.Default/ScrollViewerStyle.cs +++ b/Perspex.Themes.Default/ScrollViewerStyle.cs @@ -31,7 +31,9 @@ namespace Perspex.Themes.Default private Control Template(ScrollViewer control) { - return new Grid + ScrollBar vert; + + var result = new Grid { ColumnDefinitions = new ColumnDefinitions { @@ -59,23 +61,27 @@ namespace Perspex.Themes.Default Id = "horizontalScrollBar", Orientation = Orientation.Horizontal, [~ScrollBar.MaximumProperty] = control[~ScrollViewer.HorizontalScrollBarMaximumProperty], - [~~ScrollBar.ValueProperty] = control[~~ScrollViewer.HorizontalScrollBarValueProperty], + //[~~ScrollBar.ValueProperty] = control[~~ScrollViewer.HorizontalScrollBarValueProperty], [~ScrollBar.ViewportSizeProperty] = control[~ScrollViewer.HorizontalScrollBarViewportSizeProperty], [~ScrollBar.VisibilityProperty] = control[~ScrollViewer.HorizontalScrollBarVisibilityProperty], [Grid.RowProperty] = 1, }, - new ScrollBar + (vert = new ScrollBar { Id = "verticalScrollBar", Orientation = Orientation.Vertical, [~ScrollBar.MaximumProperty] = control[~ScrollViewer.VerticalScrollBarMaximumProperty], - [~~ScrollBar.ValueProperty] = control[~~ScrollViewer.VerticalScrollBarValueProperty], + //[~~ScrollBar.ValueProperty] = control[~~ScrollViewer.VerticalScrollBarValueProperty], [~ScrollBar.ViewportSizeProperty] = control[~ScrollViewer.VerticalScrollBarViewportSizeProperty], [~ScrollBar.VisibilityProperty] = control[~ScrollViewer.VerticalScrollBarVisibilityProperty], [Grid.ColumnProperty] = 1, - }, + }), }, }; + + vert[~~ScrollBar.ValueProperty] = control[~~ScrollViewer.VerticalScrollBarValueProperty]; + + return result; } } }