im attempting to convert this method into just XAML using Converters. I want to do this so I can use just a style to change the control so it doesn't really on hard-coded C#.
This will allow me to place this control anywhere I need and change it's size and what data it's binded to using just one line of XAML.
This code below works perfectly, but like I said I want to put it all into converters.
class CircularProgress
{
public static void RenderArc(int Angle)
{
int Radius = 88;
int StrokeThickness = 2;
System.Drawing.Point startPoint = new System.Drawing.Point(Radius, 0);
System.Drawing.Point endPoint = ComputeCartesianCoordinate(Angle, Radius);
endPoint.X += Radius;
endPoint.Y += Radius;
pathRoot.Width = Radius * 2 + StrokeThickness;
pathRoot.Height = Radius * 2 + StrokeThickness;
pathRoot.Margin = new Thickness(StrokeThickness, StrokeThickness, 0, 0);
bool largeArc = Angle > 180.0;
System.Drawing.Size outerArcSize = new System.Drawing.Size(Radius, Radius);
pathFigure.StartPoint = startPoint;
if (startPoint.X == Math.Round(endPoint.X) && startPoint.Y == Math.Round(endPoint.Y))
endPoint.X -= 0.01;
arcSegment.Point = endPoint;
arcSegment.Size = outerArcSize;
arcSegment.IsLargeArc = largeArc;
}
private static System.Drawing.Point ComputeCartesianCoordinate(double angle, double radius)
{
double angleRad = (Math.PI / 180.0) * (angle - 90);
double x = radius * Math.Cos(angleRad);
double y = radius * Math.Sin(angleRad);
return new System.Drawing.Point(x, y);
}
}
Here I have started the style, and started to use the converters, how ever im struggling to figure out how I could send the Radius to my converter, this is really the only parameter that I need to send to deter main its size, so I was hoping to add the radius as a tag, and then reference it in the converter:
<Style TargetType="ProgressBar" x:Key="CircularProgress">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<Grid x:Name="PathGrid" Margin="2">
<Canvas>
<Ellipse Margin="10"
Fill="Transparent"
Stroke="#434953"
StrokeThickness="3"
Width="180"
Height="180" />
<Path x:Name="pathRoot"
Stroke="#8ab71c"
StrokeThickness="8"
HorizontalAlignment="Left"
VerticalAlignment="Top">
<Path.Data>
<PathGeometry>
<PathFigureCollection>
<PathFigure x:Name="pathFigure" StartPoint="{Binding ElementName=pathRoot, Path=ActualWidth, Converter={StaticResource StartPointConverter},ConverterParameter=88, Mode=OneWay}">
<PathFigure.Segments>
<PathSegmentCollection>
<ArcSegment x:Name="arcSegment" SweepDirection="Clockwise" />
</PathSegmentCollection>
</PathFigure.Segments>
</PathFigure>
</PathFigureCollection>
</PathGeometry>
</Path.Data>
</Path>
</Canvas>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
This is the converter, I need the object value
to be taken from the Tag. Can anyone give me advice on this?
Edit: Here is my attempt at binding to the tag:
<PathFigure.StartPoint>
<Binding Path="ActualWidth"
Converter="{StaticResource StartPointConverter}"
ConverterParameter="{Binding RelativeSource={RelativeSource Mode=Self}, Path=Tag}"
Mode="OneWay" />
</PathFigure.StartPoint>
However i'm getting this error message when attempting to run my application:
A 'Binding' cannot be set on the 'ConverterParameter' property of type 'Binding'. A 'Binding' can only be set on a DependencyProperty of a DependencyObject.