Progress ring work sort of completed
This commit is contained in:
@@ -2,8 +2,7 @@
|
|||||||
x:Class="KingPing.AnalogOutputView"
|
x:Class="KingPing.AnalogOutputView"
|
||||||
xmlns="https://github.com/avaloniaui"
|
xmlns="https://github.com/avaloniaui"
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
|
||||||
<SettingsExpander.Footer>
|
<SettingsExpander.Footer>
|
||||||
<ProgressRing />
|
<ProgressRing IsIndeterminate="True" />
|
||||||
|
</SettingsExpander.Footer>
|
||||||
</SettingsExpander.Footer>
|
|
||||||
</SettingsExpander>
|
</SettingsExpander>
|
||||||
|
|||||||
@@ -29,10 +29,11 @@
|
|||||||
SweepAngle="360" />
|
SweepAngle="360" />
|
||||||
<Arc
|
<Arc
|
||||||
x:Name="Arc"
|
x:Name="Arc"
|
||||||
StartAngle="0"
|
StartAngle="270"
|
||||||
Stroke="{DynamicResource ProgressRingForeground}"
|
Stroke="{DynamicResource ProgressRingForeground}"
|
||||||
StrokeLineCap="Round"
|
StrokeLineCap="Round"
|
||||||
StrokeThickness="{DynamicResource ProgressRingStrokeThickness}" />
|
StrokeThickness="{DynamicResource ProgressRingStrokeThickness}"
|
||||||
|
SweepAngle="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=TemplateSettings.SweepAngle}" />
|
||||||
</Grid>
|
</Grid>
|
||||||
</ControlTemplate>
|
</ControlTemplate>
|
||||||
</Setter>
|
</Setter>
|
||||||
|
|||||||
@@ -7,7 +7,15 @@ namespace TheXamlGuy.UI.Avalonia.Controls
|
|||||||
public class ProgressRing : RangeBase
|
public class ProgressRing : RangeBase
|
||||||
{
|
{
|
||||||
public static readonly StyledProperty<bool> IsIndeterminateProperty =
|
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
|
public bool IsIndeterminate
|
||||||
{
|
{
|
||||||
@@ -15,23 +23,40 @@ namespace TheXamlGuy.UI.Avalonia.Controls
|
|||||||
set => SetValue(IsIndeterminateProperty, value);
|
set => SetValue(IsIndeterminateProperty, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ProgressRingTemplateSettings TemplateSettings
|
||||||
|
{
|
||||||
|
get => GetValue(TemplateSettingsProperty);
|
||||||
|
set => SetValue(TemplateSettingsProperty, value);
|
||||||
|
}
|
||||||
|
|
||||||
protected override void OnApplyTemplate(TemplateAppliedEventArgs args)
|
protected override void OnApplyTemplate(TemplateAppliedEventArgs args)
|
||||||
{
|
{
|
||||||
UpdateIsIndeterminate();
|
UpdateIsIndeterminate();
|
||||||
|
UpdateValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs args)
|
||||||
|
{
|
||||||
|
base.OnPropertyChanged(args);
|
||||||
|
if (args.Property == IsIndeterminateProperty)
|
||||||
|
{
|
||||||
|
UpdateIsIndeterminate();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (args.Property == ValueProperty)
|
||||||
|
{
|
||||||
|
UpdateValue();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateIsIndeterminate()
|
private void UpdateIsIndeterminate()
|
||||||
{
|
{
|
||||||
PseudoClasses.Set(":indeterminate", IsIndeterminate);
|
PseudoClasses.Set(":indeterminate", IsIndeterminate);
|
||||||
|
|
||||||
}
|
}
|
||||||
protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
|
|
||||||
|
private void UpdateValue()
|
||||||
{
|
{
|
||||||
base.OnPropertyChanged(change);
|
TemplateSettings.SetValue(ProgressRingTemplateSettings.SweepAngleProperty, Value == Maximum ? 360 : 360 * (Value / (Maximum - Minimum)));
|
||||||
if (change.Property == IsIndeterminateProperty)
|
|
||||||
{
|
|
||||||
UpdateIsIndeterminate();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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