Pre loader

TextAnnotation resize with SciChartSurface

Welcome to the SciChart Forums!

  • Please read our Question Asking Guidelines for how to format a good question
  • Some reputation is required to post answers. Get up-voted to avoid the spam filter!
  • We welcome community answers and upvotes. Every Q&A improves SciChart for everyone

WPF Forums | JavaScript Forums | Android Forums | iOS Forums



After I’ve added some TextAnnotations on the graph, I’ve noticed that the TextAnnotations and CustomaAnnotations doesn’t resize with the view. They all stay constant in size. I’ve found a previous question about this in here:

But I’m not getting the results I hoped for with this. The test is still not resizing with the surface. Since it’s been a while that a question was asked about this, maybe there are new methods to do this in Scichart?


  • You must to post comments
Best Answer

I decided to go with LayoutTransform because creating a controltemplate didn’t work for me for some reason and it put a background on the annotation and I couldn’t find what property was controlling it.

So, I created a Style:

    <Style x:Key="TextAnnotationStyle" TargetType="s:TextAnnotation">
    <Setter Property="LayoutTransform">
            <ScaleTransform ScaleY="{Binding ScaleX, RelativeSource={RelativeSource Self}}">
                    <Binding Path="ActualWidth" Converter="{StaticResource ControlSizeToTextSizeConverter}" RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType={x:Type UserControl}}">

And made a converter for resizing to the width,

    public class ControlSizeToTextSizeConverter : IValueConverter
    static double MaxSizeWidth = 660;

    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        double scale = ((double)value / MaxSizeWidth);
        if(scale > 1)
            scale = 1;

        if (scale < 0.45f)
            scale = 0;
        else if (scale < 0.55d)
            scale = 0.55d;

        return scale;

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

you might notice that it “hides” the text when the graph is too small. You also have to give this a “desired size” in pixels where it shouldn’t apply any scale transforms (that’s what scale = 1 does) so it prevents the text to become too big. You might also notice that the sizing is uniform in this case, but if you are ok with a non uniform resizing, just bind ScaleY to the ActualHeight with the converter instead of ScaleX’s value. You also might need to hold the desired size of the height in the converter as well, that’s one of the setbacks of this approach but it’s acceptable in my case.


  • You must to post comments
Great Answer

Hi Kewur,

Thank you for your inquiry. There isn’t any inbuilt way to get font size adjusted now as well, because this has not been often asked for and a workaround exists. Alternatively, you could achieve the same using the BoxAnnotation, which can be anchored by 4 corners and has a simpler template:

    <Style 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}" >

                    <Viewbox Stretch="Fill">

                        <!-- TextBlock with adjustable font size -->
                        <TextBlock Text="Some Text" />



Also there is a Behavior which does the same at StackOverflow.

So you could extend the BoxAnnotation class and bind the TextBlock within the template from above to some custom property and get the desired behavior.

Hope this helps! Please feel free to comment if you have any questions/remarks,

Best regards,

  • Andrew Burnett-Thompson
    Good idea. Another idea is use TextAnnotation.LayoutTransform with a ScaleTransform. However, this would require knowing a scale factor (difficult to compute for X and Y Axis). There's about 3 ways to achieve this, it's going to require some research you on your part. If you do find a good solution, please post it as answer! This will help our forums stay current! Thanks! Andrew
  • You must to post comments
Showing 2 results
Your Answer

Please first to submit.