Progress ring work sort of completed
This commit is contained in:
@@ -29,10 +29,11 @@
|
||||
SweepAngle="360" />
|
||||
<Arc
|
||||
x:Name="Arc"
|
||||
StartAngle="0"
|
||||
StartAngle="270"
|
||||
Stroke="{DynamicResource ProgressRingForeground}"
|
||||
StrokeLineCap="Round"
|
||||
StrokeThickness="{DynamicResource ProgressRingStrokeThickness}" />
|
||||
StrokeThickness="{DynamicResource ProgressRingStrokeThickness}"
|
||||
SweepAngle="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=TemplateSettings.SweepAngle}" />
|
||||
</Grid>
|
||||
</ControlTemplate>
|
||||
</Setter>
|
||||
|
||||
@@ -7,7 +7,15 @@ namespace TheXamlGuy.UI.Avalonia.Controls
|
||||
public class ProgressRing : RangeBase
|
||||
{
|
||||
public static readonly StyledProperty<bool> IsIndeterminateProperty =
|
||||
AvaloniaProperty.Register<ProgressRing, bool>(nameof(IsIndeterminate), true);
|
||||
AvaloniaProperty.Register<ProgressRing, bool>(nameof(IsIndeterminate), false);
|
||||
|
||||
public static readonly StyledProperty<ProgressRingTemplateSettings> TemplateSettingsProperty =
|
||||
AvaloniaProperty.Register<ProgressRing, ProgressRingTemplateSettings>(nameof(TemplateSettings));
|
||||
|
||||
public ProgressRing()
|
||||
{
|
||||
SetValue(TemplateSettingsProperty, new ProgressRingTemplateSettings());
|
||||
}
|
||||
|
||||
public bool IsIndeterminate
|
||||
{
|
||||
@@ -15,23 +23,40 @@ namespace TheXamlGuy.UI.Avalonia.Controls
|
||||
set => SetValue(IsIndeterminateProperty, value);
|
||||
}
|
||||
|
||||
public ProgressRingTemplateSettings TemplateSettings
|
||||
{
|
||||
get => GetValue(TemplateSettingsProperty);
|
||||
set => SetValue(TemplateSettingsProperty, value);
|
||||
}
|
||||
|
||||
protected override void OnApplyTemplate(TemplateAppliedEventArgs args)
|
||||
{
|
||||
UpdateIsIndeterminate();
|
||||
UpdateValue();
|
||||
}
|
||||
|
||||
protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs args)
|
||||
{
|
||||
base.OnPropertyChanged(args);
|
||||
if (args.Property == IsIndeterminateProperty)
|
||||
{
|
||||
UpdateIsIndeterminate();
|
||||
}
|
||||
|
||||
if (args.Property == ValueProperty)
|
||||
{
|
||||
UpdateValue();
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateIsIndeterminate()
|
||||
{
|
||||
PseudoClasses.Set(":indeterminate", IsIndeterminate);
|
||||
|
||||
}
|
||||
protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
|
||||
|
||||
private void UpdateValue()
|
||||
{
|
||||
base.OnPropertyChanged(change);
|
||||
if (change.Property == IsIndeterminateProperty)
|
||||
{
|
||||
UpdateIsIndeterminate();
|
||||
}
|
||||
TemplateSettings.SetValue(ProgressRingTemplateSettings.SweepAngleProperty, Value == Maximum ? 360 : 360 * (Value / (Maximum - Minimum)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
using Avalonia;
|
||||
using Avalonia.Controls.Primitives;
|
||||
|
||||
namespace TheXamlGuy.UI.Avalonia.Controls
|
||||
{
|
||||
public class ProgressRingTemplateSettings : TemplatedControl
|
||||
{
|
||||
public static readonly StyledProperty<double> SweepAngleProperty =
|
||||
AvaloniaProperty.Register<ProgressRingTemplateSettings, double>(nameof(SweepAngle), 0);
|
||||
|
||||
public double SweepAngle
|
||||
{
|
||||
get => GetValue(SweepAngleProperty);
|
||||
set => SetValue(SweepAngleProperty, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user