Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 10 additions & 50 deletions src/Wpf.Ui/Controls/Arc/Arc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ namespace Wpf.Ui.Controls;
/// </example>
public class Arc : Shape
{
private Viewbox? _rootLayout;

/// <summary>Identifies the <see cref="StartAngle"/> dependency property.</summary>
public static readonly DependencyProperty StartAngleProperty = DependencyProperty.Register(
nameof(StartAngle),
Expand Down Expand Up @@ -59,6 +57,12 @@ static Arc()
typeof(Arc),
new FrameworkPropertyMetadata(PenLineCap.Round, PropertyChangedCallback)
);

// Modify the metadata of the StrokeEndLineCap dependency property.
StrokeEndLineCapProperty.OverrideMetadata(
typeof(Arc),
new FrameworkPropertyMetadata(PenLineCap.Round, PropertyChangedCallback)
);
}

/// <summary>
Expand Down Expand Up @@ -93,17 +97,6 @@ public SweepDirection SweepDirection
/// </summary>
public bool IsLargeArc { get; internal set; } = false;

private void EnsureRootLayout()
{
if (_rootLayout != null)
{
return;
}

_rootLayout = new Viewbox { SnapsToDevicePixels = true };
AddVisualChild(_rootLayout);
}

/// <inheritdoc />
protected override Geometry DefiningGeometry => DefinedGeometry();

Expand Down Expand Up @@ -196,45 +189,12 @@ protected static void PropertyChangedCallback(DependencyObject d, DependencyProp
control.InvalidateVisual();
}

protected override Visual? GetVisualChild(int index)
{
if (index != 0)
{
throw new ArgumentOutOfRangeException(nameof(index), "Arc should have only 1 child");
}

EnsureRootLayout();

return _rootLayout;
}

protected override Size MeasureOverride(Size availableSize)
{
EnsureRootLayout();

_rootLayout!.Measure(availableSize);
return _rootLayout.DesiredSize;
}

protected override Size ArrangeOverride(Size finalSize)
{
EnsureRootLayout();

_rootLayout!.Arrange(new Rect(default, finalSize));
return finalSize;
}

/// <summary>Overrides the default OnRender method to draw the <see cref="Arc" /> element.</summary>
/// <param name="drawingContext">A <see cref="DrawingContext" /> object that is drawn during the rendering pass of this <see cref="System.Windows.Shapes.Shape" />.</param>
protected override void OnRender(DrawingContext drawingContext)
{
base.OnRender(drawingContext);
Pen pen = new(Stroke, StrokeThickness)
{
StartLineCap = StrokeStartLineCap,
EndLineCap = StrokeStartLineCap,
};
// Geometry calculations depend on RenderSize, so we need to invalidate visual when size changes.
// The base Shape class doesn't do this automatically for custom-sized geometries.
InvalidateVisual();

drawingContext.DrawGeometry(Stroke, pen, DefinedGeometry());
return base.ArrangeOverride(finalSize);
}
}
Loading