SciChart® the market leader in Fast WPF Charts, WPF 3D Charts, iOS Chart, Android Chart and JavaScript Chart Components



I’ve been trying to make the textannotations resize with the graph itself, because the text becomes very large compared to the graph if the window is sized to be smaller.

I’ve seen some people have asked the same question before me, but the solution with the Scale Transforms is offsetting the annotations when the graph is resized, which doesn’t look good, and the ControlTemplate Solution here: isn’t working and puts up a background color which I can’t seem to get rid of.

I also looked at making a controltemplate for BoxAnnotations but I’m using Properties that aren’t defined in BoxAnnotation such as the HorizontalAnchorPoint.

This is the template I’m trying to use:

            <Style TargetType="{x:Type SciChart:TextAnnotation}">
            <Setter Property="Template">
                        <ControlTemplate TargetType="SciChart:TextAnnotation">
                            <Border x:Name="PART_TextAnnotationRoot"
        Margin="{TemplateBinding Margin}"
        Background="{TemplateBinding Background}"
        BorderBrush="{TemplateBinding BorderBrush}"
        BorderThickness="{TemplateBinding BorderThickness}"
        CornerRadius="{TemplateBinding CornerRadius}">
                                <Viewbox Stretch="{TemplateBinding TextStretch}">
                                    <TextBox x:Name="PART_InputTextArea"
             Margin="{TemplateBinding Padding}"
             VerticalAlignment="{TemplateBinding VerticalAlignment}"
             FontFamily="{TemplateBinding FontFamily}"
             FontSize="{TemplateBinding FontSize}"
             FontWeight="{TemplateBinding FontWeight}"
             Foreground="{TemplateBinding Foreground}"
             IsEnabled="{Binding CanEditText,
                                 RelativeSource={RelativeSource TemplatedParent}}"
             IsTabStop="{TemplateBinding IsEditable}"
             Text="{Binding Text,
                            RelativeSource={RelativeSource TemplatedParent},
             TextAlignment="{TemplateBinding TextAlignment}"
             TextWrapping="Wrap" />

Any help would be appreciated.

  • You must to post comments
Best Answer

A lot of people ask about this, but fundamentally the approach of Viewbox is not going to work, as the Annotation is placed on a canvas, so the annotation will always size to fit its contents (not restrict content size – which is required for Viewbox to work).

What you could do instead however is use a simple binding to the parent canvas width and dynamically adjust FontSize of the TextAnnotation. Please find an example below:


<Window x:Class="Abt.Controls.SciChart.Wpf.TestSuite.TestCases.AnnotationDynamicResize.AnnotationsDymamicResize"
        Title="AnnotationsDymamicResize" Height="300" Width="300">
            <annotationDynamicResize:AnnotationFontSizeConverter x:Key="FontSizeConverter"/>


                <s:TextAnnotation Text="Hello World!" FontSize="{Binding Path=ActualWidth, RelativeSource={RelativeSource FindAncestor, AncestorType=Canvas}, Converter={StaticResource FontSizeConverter}}" />


using System.Windows;

namespace Abt.Controls.SciChart.Wpf.TestSuite.TestCases.AnnotationDynamicResize
    public partial class AnnotationsDymamicResize : Window
        public AnnotationsDymamicResize()

    public class AnnotationFontSizeConverter : IValueConverter
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
            double width = (double) value;

            if (width < 100)
                return 10;

            if (width > 1000)
                return 19;

            return width*0.01 + 9;

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
            throw new NotImplementedException();


enter image description here

  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.