SciChart WPF 2D Charts > The Trading Drawing Tools API > Freedraw (Brush) Drawing Tool
Freedraw (Brush) Drawing Tool

The BrushAnnotation tool allows a user to free-draw onto the chart, to leave some notes or to highlight important places on a chart and so-on.

Note: The Drawing Tools API in SciChart.Charting.DrawingTools is available in the Enterprise and SDK Editions of SciChart only

The BrushAnnotation derives from AnnotationBase, so it has no common properties of Trading Annotations, but it has some specific properties.

Adding a BrushAnnotation via mouse click

To add a BrushAnnotation via mouse click you have to add TradingAnnotationCreationModifier to your SciChartSurface.ChartModifier and set AnnotationType as BrushAnnotation. Please see the article on the TradingAnnotationCreationModifier for how to use this type.

Declaring a BrushAnnotation in XAML

To declare a BrushAnnotation in XAML you have to declare the annotation and then declare its InitialBasePoints collection that is actually collection of ComparablePoint objects. You can set as many points as you need to make your drawing.

Declaring a BrushAnnotation in XAML
Copy Code
<!-- XAxis, YAxis, RenderableSeries omitted for brevity -->
<s:SciChartSurface.Annotations>
    <!--Declare ElliotWaveAnnotation-->
    <s:BrushAnnotation IsEditable="True">
    <!-- Declare InitialBasePoints collection that is used for
         creating annotation from XAML.
         InitialBasePoints is actually observable collection of
         ComparablePoint-s. ComparablePoint stores X and Y point Value.
    -->
       <s: BrushAnnotation.InitialBasePoints>
             <!-- Placing first point -->
             <s:ComparablePoint X="0"  Y="0"/>
             <!-- Placing second point -->
             <s:ComparablePoint X="2"  Y="0"/>
             <!-- Placing third point -->
             <s:ComparablePoint X="4"  Y="2"/>
             <!-- Placing fourth point -->
             <s:ComparablePoint X="6"  Y="4"/>
             <!-- Placing fifth point -->
             <s:ComparablePoint X="9"  Y="4"/>
             <!-- Placing sixth point -->
             <s:ComparablePoint X="11"  Y="-4"/>
       </s: BrushAnnotation.InitialBasePoints>
     </s: BrushAnnotation >
</s:SciChartSurface.Annotations>

Declaring a BrushAnnotation in Code-Behind

To add a BrushAnnotation in code, simply use the following C# code:

Example Title
Copy Code
// Create a SciChartSurface. XAxis, YAxis omitted for brevity
var sciChartSurface = new SciChartSurface();
// Create a BrushAnnotation.
var brushAnn = new BrushAnnotation();
// BrushAnnotation should be added to
//SciChartSurface.Annotation collection first, to make SetBasePoint() method
//works correctly
sciChart.Annotations.Add(brushAnn);
// Set first point of BrushAnnotation
brushAnn.SetBasePoint(0, 0);
   
// Set second point of BrushAnnotation
brushAnn.SetBasePoint(2, 4);
 // Set third point of BrushAnnotation
brushAnn.SetBasePoint(4, 0);   
// Set fourth point of BrushAnnotation
brushAnn.SetBasePoint(6, -4);
// Set fifth point of BrushAnnotation
brushAnn.SetBasePoint(9, 0);
// Set sixth point of BrushAnnotation
brushAnn.SetBasePoint(11, -4);

 

Declaring a BrushAnnotation in MVVM

To add a BrushAnnotation via MVVM please follow the instructions for adding annotations with MVVM: Declaring Annotations in MVVM with the AnnotationsBinding Markup Extension

To add a BrushAnnotation via a ViewModel you have to use SciChart markup extension called AnnotationsBinding,

The AnnotationsBinding Markup Extension
Copy Code
<s:SciChartSurface Annotations="{s:AnnotationsBinding Annotations}">
</s:SciChartSurface>

Now you need to create collection for Annotations in ViewModel. Then create and add an BrushAnnotationViewModel to that collection of Annotations like this:

ViewMode
Copy Code
public class MyViewModel : INotifyPropertyChanged
 { 
    public ObservableCollection<IAnnotationViewModel> Annotations { get; }
 
    public void Foo()
    {
        // Create a BrushAnnotationViewModel.
        pitchfork = new BrushAnnotationViewModel();
        // BrushAnnotationViewModelshould be added to
        //SciChartSurface.Annotation collection first, to make SetBasePoint() method
        //works correctly
        Annotations.Add(pitchfork);
        // Set first point of BrushAnnotationViewModel
        pitchfork.SetBasePoint(0, 0);
           
        // Set second point of BrushAnnotationViewModel
        pitchfork.SetBasePoint(2, 4);
         // Set third point of BrushAnnotationViewModel
        pitchfork.SetBasePoint(4, 0);   
    }
 }