Is it possible to annotate CustomGridLines?

2 posts, 0 answers
  1. Alexis
    Alexis avatar
    1 posts
    Member since:
    Aug 2010

    Posted 01 Dec 2010 Link to this post

    I have been trying to use the CustomGridLines feature to highlight a particular date, what I'd like to do is add a label next to the line, explaining what it's highlighting. Is this possible at all?
  2. Evgenia
    Evgenia avatar
    1437 posts

    Posted 06 Dec 2010 Link to this post

    Hello Alexis,

    It is possible to add Label for your Custom Gridline by retemplating the CustomGridLine. Put this code snippet between UserControl.Resources opening and closing tags:
    <SolidColorBrush x:Key="AxisStroke" Color="#FF000000" />
            <Style x:Key="CustomGridLineStyle"
                TargetType="telerikCharting:CustomGridLine" >
                <Setter Property="Stroke" Value="{StaticResource AxisStroke}" />
                <Setter Property="StrokeThickness" Value="1" />
                <Setter Property="Template" >
                        <ControlTemplate TargetType="telerikCharting:CustomGridLine">
                            <Line X1="{TemplateBinding ElementX1}" 
                              X2="{TemplateBinding ElementX2}" 
                              Y1="{TemplateBinding ElementY1}" 
                              Y2="{TemplateBinding ElementY2}" 
                              Stroke="{TemplateBinding Stroke}"
                              StrokeThickness="{TemplateBinding StrokeThickness}"
                              Style="{TemplateBinding ElementStyle}"/>
                              <TextBlock Text="{Binding}"/>
    A grid layout wrapper is addded containing a TextBlock together with the Line that actually displays the custom gridline ( I've marked the new things added to the default template with yellow).

    In code behind you need to add CustomGridLine's new style together with a string for a DataContext. This string is bound to Text  property of TextBlock:

                  new CustomGridLine()
                      Margin = new Thickness(5,90,0,0),
                      YIntercept = 90,
                      Stroke = new SolidColorBrush(Colors.Purple),
                      StrokeThickness = 2,
                      Style = this.Resources["CustomGridLineStyle"] as Style,
                      DataContext = "My custom text",

    Have in mind that with this approach you will be able to locate the Label of the CustomGridLine by applying Margin to it as shown above.

    Kind regards,
    the Telerik team
    Browse the videos here>> to help you get started with RadControls for Silverlight
Back to Top