SciChart WPF 2D Charts > Annotations API > The TextAnnotation Type
The TextAnnotation Type

The TextAnnotation type draws a TextBlock with optional background at X1,Y1. The text is editable when the use clicks on the TextBlock and TextAnnotation.IsEditable = true. The text alignment is provided by the TextAnnotation.HorizontalAnchorPoint and TextAnnotation.VerticalAnchorPoint properties.

Declaring a TextAnnotation in XAML

Declaring a TextAnnotation
Copy Code
<!-- Where xmlns:s="" -->
      <!-- Declares a TextAnnotation at X1=1, Y1=2, -->
      <!-- The annotation will move with the chart as you zoom and pan -->
      <s:TextAnnotation FontSize="12" Text="Hi 2 U!" X1="1" Y1="2" Background="#333"
                        BorderThickness="1", BorderBrush="#222"/>

Declaring a TextAnnotation in Code

Declaring a TextAnnotation
Copy Code
var sciChartSurface = new SciChartSurface();
sciChartSurface.Annotations.Add(new TextAnnotation()
   Text = "Hi 2 U!",
   FontSize = 12,
   Background = new SolidColorBrush(Colors.FromArgb(0xFF, 0x33, 0x33, 0x33)),
   BorderBrush = new SolidColorBrush(Colors.FromArgb(0xFF, 0x22, 0x22, 0x22)),
   BorderThickness = new Thickness(1,1,1,1),
   X1 = 1,
   Y1 = 2,

Templating the TextAnnotation

The Default Style and ControlTemplate for the TextAnnotation is defined below. You shouldn’t need to change this, but if you want to template the annotation, here are the template parts:

Templating the TextAnnotation
Copy Code
<Style BasedOn="{StaticResource AnnotationBaseStyle}" TargetType="a:TextAnnotation">
   <Setter Property="Foreground" Value="{me:ThemeBinding TickTextBrush}" />
   <Setter Property="Background" Value="Transparent" />
   <Setter Property="Template">
         <ControlTemplate TargetType="a:TextAnnotation">
            <Border x:Name="PART_TextAnnotationRoot"
                  Margin="{TemplateBinding Margin}"
                  Background="{TemplateBinding Background}"
                  BorderBrush="{TemplateBinding BorderBrush}"
                  BorderThickness="{TemplateBinding BorderThickness}"
                  CornerRadius="{TemplateBinding CornerRadius}">
               <TextBox x:Name="PART_InputTextArea"
                      Margin="{TemplateBinding Padding}"
                      VerticalAlignment="{TemplateBinding VerticalAlignment}"
                      FontFamily="{TemplateBinding FontFamily}"
                      FontSize="{TemplateBinding FontSize}"
                      FontWeight="{TemplateBinding FontWeight}"
                      Foreground="{TemplateBinding Foreground}"
                      IsTabStop="{TemplateBinding IsEditable}"
                      Style="{StaticResource AnnotationTextBoxStyle}"
                      Text="{Binding Text,
                                 RelativeSource={RelativeSource TemplatedParent},
                      TextAlignment="{TemplateBinding TextAlignment}"
                      TextWrapping="Wrap" />

TextAnnotation Alignment

TextAnnotation Alignment relative to the X1,Y1 control point is provided by the HorizontalAnchorPoint and VerticalAnchorPoint properties. The defaults are HorizontalAnchorPoint.Left and VerticalAnchorPoint.Top. You can see how changing the anchor points affects placement of the TextAnnotation below.