Browse Source

Merge pull request #8498 from timunie/fix/ProgressBarShouldListenToTrackSize

fix for ProgressBar not listening to size changes of parent track
pull/8597/head
Max Katz 4 years ago
committed by GitHub
parent
commit
1a076162fe
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 11
      src/Avalonia.Controls/ProgressBar.cs

11
src/Avalonia.Controls/ProgressBar.cs

@ -100,6 +100,7 @@ namespace Avalonia.Controls
private double _indeterminateStartingOffset;
private double _indeterminateEndingOffset;
private Border? _indicator;
private IDisposable? _trackSizeChangedListener;
public static readonly StyledProperty<bool> IsIndeterminateProperty =
AvaloniaProperty.Register<ProgressBar, bool>(nameof(IsIndeterminate));
@ -195,8 +196,9 @@ namespace Avalonia.Controls
/// <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)
@ -216,8 +218,15 @@ namespace Avalonia.Controls
/// <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();
}

Loading…
Cancel
Save