csharpc-sharpdotnetxamlavaloniauicross-platformcross-platform-xamlavaloniaguimulti-platformuser-interfacedotnetcore
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
1.4 KiB
49 lines
1.4 KiB
// Copyright (c) The Avalonia Project. All rights reserved.
|
|
// Licensed under the MIT license. See licence.md file in the project root for full license information.
|
|
|
|
using Avalonia.Controls.Primitives;
|
|
using Avalonia.Controls.Templates;
|
|
|
|
namespace Avalonia.Controls
|
|
{
|
|
/// <summary>
|
|
/// A control used to indicate the progress of an operation.
|
|
/// </summary>
|
|
public class ProgressBar : RangeBase
|
|
{
|
|
private Border _indicator;
|
|
|
|
static ProgressBar()
|
|
{
|
|
ValueProperty.Changed.AddClassHandler<ProgressBar>(x => x.ValueChanged);
|
|
}
|
|
|
|
/// <inheritdoc/>
|
|
protected override Size ArrangeOverride(Size finalSize)
|
|
{
|
|
UpdateIndicator(finalSize);
|
|
return base.ArrangeOverride(finalSize);
|
|
}
|
|
|
|
/// <inheritdoc/>
|
|
protected override void OnTemplateApplied(TemplateAppliedEventArgs e)
|
|
{
|
|
_indicator = e.NameScope.Get<Border>("PART_Indicator");
|
|
UpdateIndicator(Bounds.Size);
|
|
}
|
|
|
|
private void UpdateIndicator(Size bounds)
|
|
{
|
|
if (_indicator != null)
|
|
{
|
|
double percent = Maximum == Minimum ? 1.0 : (Value - Minimum) / (Maximum - Minimum);
|
|
_indicator.Width = bounds.Width * percent;
|
|
}
|
|
}
|
|
|
|
private void ValueChanged(AvaloniaPropertyChangedEventArgs e)
|
|
{
|
|
UpdateIndicator(Bounds.Size);
|
|
}
|
|
}
|
|
}
|
|
|