Skip to content

Commit

Permalink
Merge pull request #8498 from timunie/fix/ProgressBarShouldListenToTr…
Browse files Browse the repository at this point in the history
…ackSize

fix for ProgressBar not listening to size changes of parent track
  • Loading branch information
maxkatz6 authored Jul 26, 2022
2 parents ad6eef6 + deb104a commit 1a07616
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/Avalonia.Controls/ProgressBar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ public double Container2AnimationEndPosition
private double _indeterminateStartingOffset;
private double _indeterminateEndingOffset;
private Border? _indicator;
private IDisposable? _trackSizeChangedListener;

public static readonly StyledProperty<bool> IsIndeterminateProperty =
AvaloniaProperty.Register<ProgressBar, bool>(nameof(IsIndeterminate));
Expand Down Expand Up @@ -195,8 +196,9 @@ public Orientation Orientation
/// <inheritdoc/>
protected override Size ArrangeOverride(Size finalSize)
{
var result = base.ArrangeOverride(finalSize);
UpdateIndicator();
return base.ArrangeOverride(finalSize);
return result;
}

protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
Expand All @@ -216,8 +218,15 @@ protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs chang
/// <inheritdoc/>
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
{
// dispose any previous track size listener
_trackSizeChangedListener?.Dispose();

_indicator = e.NameScope.Get<Border>("PART_Indicator");

// listen to size changes of the indicators track (parent) and update the indicator there.
_trackSizeChangedListener = _indicator.Parent?.GetPropertyChangedObservable(BoundsProperty)
.Subscribe(_ => UpdateIndicator());

UpdateIndicator();
}

Expand Down

0 comments on commit 1a07616

Please sign in to comment.