|
@@ -4,6 +4,7 @@
|
|
|
|
|
|
|
|
using System;
|
|
using System;
|
|
|
using Avalonia.Controls.Primitives;
|
|
using Avalonia.Controls.Primitives;
|
|
|
|
|
+using Avalonia.Data;
|
|
|
using Avalonia.Layout;
|
|
using Avalonia.Layout;
|
|
|
|
|
|
|
|
namespace Avalonia.Controls
|
|
namespace Avalonia.Controls
|
|
@@ -16,6 +17,9 @@ namespace Avalonia.Controls
|
|
|
public static readonly StyledProperty<bool> IsIndeterminateProperty =
|
|
public static readonly StyledProperty<bool> IsIndeterminateProperty =
|
|
|
AvaloniaProperty.Register<ProgressBar, bool>(nameof(IsIndeterminate));
|
|
AvaloniaProperty.Register<ProgressBar, bool>(nameof(IsIndeterminate));
|
|
|
|
|
|
|
|
|
|
+ public static readonly StyledProperty<bool> ShowProgressTextProperty =
|
|
|
|
|
+ AvaloniaProperty.Register<ProgressBar, bool>(nameof(ShowProgressText));
|
|
|
|
|
+
|
|
|
public static readonly StyledProperty<Orientation> OrientationProperty =
|
|
public static readonly StyledProperty<Orientation> OrientationProperty =
|
|
|
AvaloniaProperty.Register<ProgressBar, Orientation>(nameof(Orientation), Orientation.Horizontal);
|
|
AvaloniaProperty.Register<ProgressBar, Orientation>(nameof(Orientation), Orientation.Horizontal);
|
|
|
|
|
|
|
@@ -35,20 +39,27 @@ namespace Avalonia.Controls
|
|
|
|
|
|
|
|
static ProgressBar()
|
|
static ProgressBar()
|
|
|
{
|
|
{
|
|
|
- PseudoClass<ProgressBar, Orientation>(OrientationProperty, o => o == Orientation.Vertical, ":vertical");
|
|
|
|
|
- PseudoClass<ProgressBar, Orientation>(OrientationProperty, o => o == Orientation.Horizontal, ":horizontal");
|
|
|
|
|
- PseudoClass<ProgressBar>(IsIndeterminateProperty, ":indeterminate");
|
|
|
|
|
-
|
|
|
|
|
ValueProperty.Changed.AddClassHandler<ProgressBar>((x, e) => x.UpdateIndicatorWhenPropChanged(e));
|
|
ValueProperty.Changed.AddClassHandler<ProgressBar>((x, e) => x.UpdateIndicatorWhenPropChanged(e));
|
|
|
IsIndeterminateProperty.Changed.AddClassHandler<ProgressBar>((x, e) => x.UpdateIndicatorWhenPropChanged(e));
|
|
IsIndeterminateProperty.Changed.AddClassHandler<ProgressBar>((x, e) => x.UpdateIndicatorWhenPropChanged(e));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ public ProgressBar()
|
|
|
|
|
+ {
|
|
|
|
|
+ UpdatePseudoClasses(IsIndeterminate, Orientation);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
public bool IsIndeterminate
|
|
public bool IsIndeterminate
|
|
|
{
|
|
{
|
|
|
get => GetValue(IsIndeterminateProperty);
|
|
get => GetValue(IsIndeterminateProperty);
|
|
|
set => SetValue(IsIndeterminateProperty, value);
|
|
set => SetValue(IsIndeterminateProperty, value);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ public bool ShowProgressText
|
|
|
|
|
+ {
|
|
|
|
|
+ get => GetValue(ShowProgressTextProperty);
|
|
|
|
|
+ set => SetValue(ShowProgressTextProperty, value);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
public Orientation Orientation
|
|
public Orientation Orientation
|
|
|
{
|
|
{
|
|
|
get => GetValue(OrientationProperty);
|
|
get => GetValue(OrientationProperty);
|
|
@@ -75,6 +86,24 @@ namespace Avalonia.Controls
|
|
|
return base.ArrangeOverride(finalSize);
|
|
return base.ArrangeOverride(finalSize);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ protected override void OnPropertyChanged<T>(
|
|
|
|
|
+ AvaloniaProperty<T> property,
|
|
|
|
|
+ Optional<T> oldValue,
|
|
|
|
|
+ BindingValue<T> newValue,
|
|
|
|
|
+ BindingPriority priority)
|
|
|
|
|
+ {
|
|
|
|
|
+ base.OnPropertyChanged(property, oldValue, newValue, priority);
|
|
|
|
|
+
|
|
|
|
|
+ if (property == IsIndeterminateProperty)
|
|
|
|
|
+ {
|
|
|
|
|
+ UpdatePseudoClasses(newValue.GetValueOrDefault<bool>(), null);
|
|
|
|
|
+ }
|
|
|
|
|
+ else if (property == OrientationProperty)
|
|
|
|
|
+ {
|
|
|
|
|
+ UpdatePseudoClasses(null, newValue.GetValueOrDefault<Orientation>());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/// <inheritdoc/>
|
|
/// <inheritdoc/>
|
|
|
protected override void OnTemplateApplied(TemplateAppliedEventArgs e)
|
|
protected override void OnTemplateApplied(TemplateAppliedEventArgs e)
|
|
|
{
|
|
{
|
|
@@ -121,5 +150,21 @@ namespace Avalonia.Controls
|
|
|
{
|
|
{
|
|
|
UpdateIndicator(Bounds.Size);
|
|
UpdateIndicator(Bounds.Size);
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ private void UpdatePseudoClasses(
|
|
|
|
|
+ bool? isIndeterminate,
|
|
|
|
|
+ Orientation? o)
|
|
|
|
|
+ {
|
|
|
|
|
+ if (isIndeterminate.HasValue)
|
|
|
|
|
+ {
|
|
|
|
|
+ PseudoClasses.Set(":indeterminate", isIndeterminate.Value);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (o.HasValue)
|
|
|
|
|
+ {
|
|
|
|
|
+ PseudoClasses.Set(":vertical", o == Orientation.Vertical);
|
|
|
|
|
+ PseudoClasses.Set(":horizontal", o == Orientation.Horizontal);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|