From a0be18e3f66989e8fd91acb53b025c407fb81e1d Mon Sep 17 00:00:00 2001 From: Jumar Macato Date: Fri, 19 Jun 2020 15:38:26 +0800 Subject: [PATCH] Fix indeterminate animation on old theme --- src/Avalonia.Controls/ProgressBar.cs | 42 +++++++++++++++++--- src/Avalonia.Themes.Default/ProgressBar.xaml | 8 ++-- 2 files changed, 40 insertions(+), 10 deletions(-) diff --git a/src/Avalonia.Controls/ProgressBar.cs b/src/Avalonia.Controls/ProgressBar.cs index d29e878b73..2a732e9d90 100644 --- a/src/Avalonia.Controls/ProgressBar.cs +++ b/src/Avalonia.Controls/ProgressBar.cs @@ -11,12 +11,14 @@ namespace Avalonia.Controls { public class ProgressBarTemplateProperties : AvaloniaObject { - private double _Container2Width; - private double _ContainerWidth; + private double _container2Width; + private double _containerWidth; private double _containerAnimationStartPosition; private double _containerAnimationEndPosition; private double _container2AnimationStartPosition; private double _container2AnimationEndPosition; + private double _indeterminateStartingOffset; + private double _indeterminateEndingOffset; public static readonly DirectProperty ContainerAnimationStartPositionProperty = AvaloniaProperty.RegisterDirect( @@ -54,6 +56,18 @@ namespace Avalonia.Controls p => p.ContainerWidth, (p, o) => p.ContainerWidth = o); + public static readonly DirectProperty IndeterminateStartingOffsetProperty = + AvaloniaProperty.RegisterDirect( + nameof(IndeterminateStartingOffset), + p => p.IndeterminateStartingOffset, + (p, o) => p.IndeterminateStartingOffset = o); + + public static readonly DirectProperty IndeterminateEndingOffsetProperty = + AvaloniaProperty.RegisterDirect( + nameof(IndeterminateEndingOffset), + p => p.IndeterminateEndingOffset, + (p, o) => p.IndeterminateEndingOffset = o); + public double ContainerAnimationStartPosition { get => _containerAnimationStartPosition; @@ -74,14 +88,14 @@ namespace Avalonia.Controls public double Container2Width { - get => _Container2Width; - set => SetAndRaise(Container2WidthProperty, ref _Container2Width, value); + get => _container2Width; + set => SetAndRaise(Container2WidthProperty, ref _container2Width, value); } public double ContainerWidth { - get => _ContainerWidth; - set => SetAndRaise(ContainerWidthProperty, ref _ContainerWidth, value); + get => _containerWidth; + set => SetAndRaise(ContainerWidthProperty, ref _containerWidth, value); } public double Container2AnimationEndPosition @@ -89,6 +103,18 @@ namespace Avalonia.Controls get => _container2AnimationEndPosition; set => SetAndRaise(Container2AnimationEndPositionProperty, ref _container2AnimationEndPosition, value); } + + public double IndeterminateStartingOffset + { + get => _indeterminateStartingOffset; + set => SetAndRaise(IndeterminateStartingOffsetProperty, ref _indeterminateStartingOffset, value); + } + + public double IndeterminateEndingOffset + { + get => _indeterminateEndingOffset; + set => SetAndRaise(IndeterminateEndingOffsetProperty, ref _indeterminateEndingOffset, value); + } } private Border _indicator; @@ -182,6 +208,10 @@ namespace Avalonia.Controls TemplateProperties.Container2AnimationStartPosition = barIndicatorWidth2 * -1.5; // Position at -150% TemplateProperties.Container2AnimationEndPosition = barIndicatorWidth2 * 1.66; // Position at 166% + + // Remove these properties when we switch to fluent as default and removed the old one. + TemplateProperties.IndeterminateStartingOffset = -dim; + TemplateProperties.IndeterminateEndingOffset = dim * 2; var padding = Padding; var rectangle = new RectangleGeometry( diff --git a/src/Avalonia.Themes.Default/ProgressBar.xaml b/src/Avalonia.Themes.Default/ProgressBar.xaml index 9a12ccd720..af3613a2a6 100644 --- a/src/Avalonia.Themes.Default/ProgressBar.xaml +++ b/src/Avalonia.Themes.Default/ProgressBar.xaml @@ -61,11 +61,11 @@ Easing="LinearEasing"> + Value="{Binding TemplateProperties.IndeterminateStartingOffset, RelativeSource={RelativeSource TemplatedParent}}" /> + Value="{Binding TemplateProperties.IndeterminateEndingOffset, RelativeSource={RelativeSource TemplatedParent}}" /> @@ -77,11 +77,11 @@ Easing="LinearEasing"> + Value="{Binding TemplateProperties.IndeterminateStartingOffset, RelativeSource={RelativeSource TemplatedParent}}" /> + Value="{Binding TemplateProperties.IndeterminateEndingOffset, RelativeSource={RelativeSource TemplatedParent}}" />