I can't set ChartAnnotationLabelDefinition.Template.

3 posts, 1 answers
  1. Yaroslav
    Yaroslav avatar
    153 posts
    Member since:
    Jan 2016

    Posted 03 Oct 2016 Link to this post

    Hello. I try to set ChartAnnotationLabelDefinition.Template in the way where the label of annotation has red color. But I havn't got the required result yet. I wrote the following XAML markup:

    <telerik:RadCartesianChart Visibility="{Binding IsAbsoluteBarChartVisible}">
                <!--The definition of an annotation line-->
                    <telerik:CartesianGridLineAnnotation Axis="{Binding ElementName=verticalAxis}" Value="{Binding AnnotationValue}" Label="{Binding AnnotationLabel}" Stroke="Red" StrokeThickness="2" DashArray="8 2">
                            <telerik:ChartAnnotationLabelDefinition Location="Inside"  VerticalAlignment="Bottom"  HorizontalAlignment="Center">
                                <!--HERE IS THE TEMPLATE DEFINITION-->
                                        <TextBlock Foreground="Red" FontWeight="DemiBold"/>
                <!-- X axis-->
                <!-- Y axis-->
                    <telerik:LinearAxis x:Name="verticalAxis" Title="Децибелы [Дб]" Minimum="{Binding ChartMinimum}" Maximum="{Binding ChartMaximum}" MajorStep="{Binding CurrentStep}"/>
                <!--The chart itself-->
                    <telerik:BarSeries ShowLabels="True" CategoryBinding="Category" ValueBinding="Value" ItemsSource="{Binding Data}"/>

    But when I run my application and navigate to the View where charts are displayed then I see only annotation without label (please see 'AnnotationWithoutLabels.PNG' file attached). When I comment the following part of XAML markup

            <TextBlock Foreground="Red" FontWeight="DemiBold"/>

    then I see annotation with black colored label (please see 'AnnotationWithBlackColoredLabel.PNG' file attached). How do I get a bright red color for the annotation label?

  2. Answer
    Martin Ivanov
    Martin Ivanov avatar
    1408 posts

    Posted 04 Oct 2016 Link to this post

    Hello Yaroslav,

    The label is not displayed when you set the Template property, because the TextBlock inside the DataTemplate doesn't have its Text property set. 
            <TextBlock Text="{Binding}" Foreground="Red" FontWeight="DemiBold"/>
    Note that the data context passed in the template is the value of the annotation's Label property.

    If you don't want to use a template you can achieve the same result by setting the DefaultVisualStyle instead of the Template property.
        <Style TargetType="TextBlock">
            <Setter Property="Foreground" Value="Red" />

    Telerik by Progress
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
  3. Yaroslav
    Yaroslav avatar
    153 posts
    Member since:
    Jan 2016

    Posted 05 Oct 2016 in reply to Martin Ivanov Link to this post

    Martin, fthank you for your help.
Back to Top