0

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.

Martyn Ball
  • 4,679
  • 8
  • 56
  • 126
  • 3
    http://stackoverflow.com/questions/15309008/binding-converterparameter – Valera Scherbakov Oct 31 '15 at 14:42
  • Just found that post aha, but still I would like some advice on how some people would do what i'm attempting. – Martyn Ball Oct 31 '15 at 14:43
  • @ValeraScherbakov, See updated post – Martyn Ball Oct 31 '15 at 14:51
  • The same thing was asked in mentioned question. The answer is fully completed. I don't see any reason to copy and paste answer. – Valera Scherbakov Oct 31 '15 at 15:08
  • _"I would like some advice on how some people would do what i'm attempting"_ -- how they would do what? If you mean how to pass the `Tag` property value to the converter, the duplicate question answers that. If you mean how to do the whole thing generally, well...that's too broad a question for Stack Overflow. You need to address the broader design yourself; if you have a _specific_ question that comes up in the process, please feel free to post a question here about that. – Peter Duniho Oct 31 '15 at 18:16

0 Answers0