WPF Charting Documentation - SciChart WPF Charts SDK v5.x
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="http://schemas.abtsoftware.co.uk/SciChart" -->
<s:SciChartSurface>
   <s:SciChartSurface.Annotations>
      <!-- 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/>
   </s:SciChartSurface.Annotations>
</s:SciChartSurface>

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">
      <Setter.Value>
         <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}"
                      AcceptsReturn="True"
                      Background="Transparent"
                      BorderThickness="0"
                      FontFamily="{TemplateBinding FontFamily}"
                      FontSize="{TemplateBinding FontSize}"
                      FontWeight="{TemplateBinding FontWeight}"
                      Foreground="{TemplateBinding Foreground}"
                      IsTabStop="{TemplateBinding IsEditable}"
                      Style="{StaticResource AnnotationTextBoxStyle}"
                      Text="{Binding Text,
                                 RelativeSource={RelativeSource TemplatedParent},
                                 Mode=TwoWay}"
                      TextAlignment="{TemplateBinding TextAlignment}"
                      TextWrapping="Wrap" />
            </Border>
         </ControlTemplate>
      </Setter.Value>
   </Setter>
</Style>

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.

 

 

 


SCICHART ® is a Registered Trademark in the UK, US and EEC. Copyright SciChart Ltd 2011-2018.

Email us to give feedback!