How to add the SegmentedRadialGaugeIndicator by code?

2 posts, 0 answers
  1. javier
    javier avatar
    48 posts
    Member since:
    Aug 2012

    Posted 06 Feb 2011 Link to this post

    Hi there,


    How to add the following items to a RadialGaugeRange by code (during runtime)?:
    -SegmentedRadialGaugeIndicator
    -ArrowGaugeIndicator
    -DataTemplate

    I have trie dout this code but it does not work:

                        RadialGaugeRange rgr = new RadialGaugeRange();
                        rgr.MinAngle = -75;
                        rgr.MaxAngle = 255;
                        rgr.TickStep=100;
                        rgr.MajorTickStep=150;
                        rgr.LabelStep=100;
                        rgr.LabelRadiusScale = 0.95;
                        rgr.TickRadiusScale = 0.75;
                        rgr.HorizontalAlignment=System.Windows.HorizontalAlignment.Center;
                        rgr.VerticalAlignment=System.Windows.VerticalAlignment.Center;

                        ArrowGaugeIndicator arrow = new ArrowGaugeIndicator();
                        arrow.ArrowThickness = 2;
                        arrow.ArrowTailRadius = 1.4;
                        //arrow.ArrowColor = Colors.Yellow;
                        arrow.Value = g.Kpi.Value;                   
                        rgr.Indicators.Add(arrow);

                        RadialGaugeRange rangeArrow = new RadialGaugeRange();
                        rangeArrow.MinAngle = 180;
                        rangeArrow.MaxAngle = 360;
                        //RadialGaugeRange.IndicatorRadiusScaleProperty = 0.31;
                        rgr.Children.Add(rangeArrow);

                        SegmentedRadialGaugeIndicator ind = new SegmentedRadialGaugeIndicator();
                        BarIndicatorSegment seg1=new BarIndicatorSegment();
                        seg1.Length=2;
                        seg1.Thickness=3;

                        BarIndicatorSegment seg2 = new BarIndicatorSegment();
                        seg2.Length = 1.66;
                        seg2.Thickness = 3;

                        BarIndicatorSegment seg3 = new BarIndicatorSegment();
                        seg3.Length = 2.34;
                        seg3.Thickness = 3;
                       
                        ind.Segments.Add(seg1);
                        ind.Segments.Add(seg2);
                        ind.Segments.Add(seg3);

                        rgr.Children.Add(ind);

                        Grid.SetRow(rgr, 1);
                        Grid.SetColumn(rgr, 0);
                        newGrid.Children.Add(rgr);

    By other hand, how can I assing these properties:
    arrow.ArrowColor = Colors.Yellow;
    RadialGaugeRange.IndicatorRadiusScaleProperty = 0.31;

    Thank you,


    Javier Andrés Cáceres Alvis
    Windows Phone - MVP
    @jacace
  2. Victor
    Admin
    Victor avatar
    1351 posts

    Posted 09 Feb 2011 Link to this post

    Hello javier,

    Thank you for your interest in our gauges for Windows Phone 7.

    The ArrowColor property is of type Brush hence you can not set it to a value of type Color. The naming however is misleading and we will change it in our official version to "ArrowBrush".

    The IndicatorRadiusScale is an attached dependency property, you can set it to a value on an indicator like so:

    RadialGaugeRange.SetIndicatorRadiusScale(arrow, 0.31);

    Here is your code, slightly modified. I have highlighted the changed lines:
    RadialGaugeRange rgr = new RadialGaugeRange();
    rgr.MinAngle = -75;
    rgr.MaxAngle = 255;
    rgr.TickStep = 100;
    rgr.MajorTickStep = 150;
    rgr.LabelStep = 100;
    rgr.LabelRadiusScale = 0.95;
    rgr.TickRadiusScale = 0.75;
     
    ArrowGaugeIndicator arrow = new ArrowGaugeIndicator();
    arrow.ArrowThickness = 2;
    arrow.ArrowTailRadius = 1.4;
    arrow.ArrowColor = new SolidColorBrush(Colors.Yellow);
    arrow.Value = 20;
    rgr.Indicators.Add(arrow);
     
    RadialGaugeRange rangeArrow = new RadialGaugeRange();
    rangeArrow.MinAngle = 180;
    rangeArrow.MaxAngle = 360;
    RadialGaugeRange.SetIndicatorRadiusScale(arrow, 0.31);
     
    SegmentedRadialGaugeIndicator ind = new SegmentedRadialGaugeIndicator();
    BarIndicatorSegment seg1 = new BarIndicatorSegment();
    seg1.Stroke = new SolidColorBrush(Colors.Red);
    seg1.Length = 2;
    seg1.Thickness = 3;
    BarIndicatorSegment seg2 = new BarIndicatorSegment();
    seg2.Stroke = new SolidColorBrush(Colors.Green);
    seg2.Length = 1.66;
    seg2.Thickness = 3;
    BarIndicatorSegment seg3 = new BarIndicatorSegment();
    seg3.Stroke = new SolidColorBrush(Colors.Blue);
    seg3.Length = 2.34;
    seg3.Thickness = 3;
    ind.Segments.Add(seg1);
    ind.Segments.Add(seg2);
    ind.Segments.Add(seg3);
    ind.Value = 100;
     
    rgr.Indicators.Add(ind);
    Grid.SetRow(rgr, 1);
    Grid.SetColumn(rgr, 0);
    this.grid.Children.Add(rgr);
    rgr.Children.Add(rangeArrow);

    I hope this helps. Do not hesitate to contact us with any question and/or suggestion you may have - feedback is most welcome.

    Regards,
    Victor
    the Telerik team
    Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
  3. DevCraft banner
Back to Top