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

The BoxAnnotation draws a rectangle at X1,Y1,X2,Y2 where coordinates are data-values. The BoxAnnotation supports BorderThickness, BorderBrush, CornerRadius and Background. The BoxAnnotation supports user dragging when IsEditable = true.



Declaring a BoxAnnotation in XAML

Example Title
Copy Code
<!-- Where xmlns:s="" -->
      <!-- Declares a BoxAnnotation at X1=3, X2=3.5, Y1=4, Y2=5 -->
      <!-- The annotation will move with the chart as you zoom and pan -->
      <s:BoxAnnotation Background="#55279B27" BorderBrush="#279B27" BorderThickness="1"
                       CornerRadius="3" X1="3.5" X2="5" Y1="4" Y2="5"/>  

Declaring a BoxAnnotation in Code

Declaring a BoxAnnotation
Copy Code
var sciChartSurface = new SciChartSurface();
sciChartSurface.Annotations.Add(new BoxAnnotation()
   BorderBrush = new SolidColorBrush(Colors.FromArgb(0xFF, 0x27, 0x9B, 0x27)),
   Background = new SolidColorBrush(Colors.FromArgb(0x55, 0x27, 0x9B, 0x27)),
   BorderThickness = new Thickness(1),
   CornerRadius = new Thickness(1),
   X1 = 3,
   X2 = 3.5,
   Y1 = 4,
   Y2 = 5,
   IsEditable = true,

Templating the BoxAnnotation

The Default Style and ControlTemplate for the BoxAnnotation is defined below. You can template a BoxAnnotation if you want to create a custom annotation with four control points. Just ensure you keep the PART_BoxAnnotationRoot. Any content you put inside it can be custom content.

Templating the BoxAnnotation
Copy Code
<!--  BoxAnnotation  -->
<Style BasedOn="{StaticResource AnnotationBaseStyle}" TargetType="a:BoxAnnotation">
   <Setter Property="Template">
         <ControlTemplate TargetType="a:BoxAnnotation">
            <Border x:Name="PART_BoxAnnotationRoot"
                  Margin="{TemplateBinding Margin}"
                  Background="{TemplateBinding Background}"
                  BorderBrush="{TemplateBinding BorderBrush}"
                  BorderThickness="{TemplateBinding BorderThickness}"
                  CornerRadius="{TemplateBinding CornerRadius}" />