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


I am adding annotations to a chart that is bound to MVVM data and has multiple Y axes. The annotation data all applies to a single series/axis. I have seen that the IsHidden property can be used to toggle the visibility of an annotation. Is there a way to have the annotations tied to the visibility of a series/axis? So if the series is hidden by unchecking its box in the legend, can the associated annotations all be hidden also?

I realize that I can iterate my annotation collection and toggle the property when the series visibility changes, but it would be nice if there were a way for that to happen automatically.

  • You must to post comments

I hate to revive an old thread; however, today I found myself in a scenario where I was trying to use a DataTrigger to define whether my annotation would be visible or not. I was using the Visibility property and despite using the DataTrigger correctly it didn’t work. I found that I had to use the “IsHidden” property of the Annotation for my DataTrigger to work. I find this relevant to anyone who faces the same problem I did. Although there is a Visibility property for this element, it doesn’t respond to the value of this property. With irony, it will respond if you apply the same logic outside of a data trigger and use simple binding in the XAML which declares the annotation like this below. However, it is a good practice to avoid properties like “Visibility” within a ViewModel.

<s:LineAnnotation Visibility="{Binding Path=MyLineVisibility}" />

See snippet from my XAML for a LineAnnotation that worked the way I preferred.

<s:LineAnnotation Stroke="Purple" 
                                     X1="{Binding Path=FiftyLineX1}" 
                                     X2="{Binding Path=FiftyLineX2}" 
                                     Y1="{Binding Path=FiftyLineField}" 
                                     Y2="{Binding Path=FiftyLineField}">
                    <Style TargetType="{x:Type s:LineAnnotation}">
                        <Setter Property="IsHidden" Value="True" />
                            <DataTrigger Binding="{Binding Path=MeasurementExists, UpdateSourceTrigger=PropertyChanged}" Value="True">
                                <Setter Property="IsHidden" Value="False" />
  • Andrew Burnett-Thompson
    Hi Chris, that’s right, quirk of the API – Visibility is used internally to hide elements that are off canvas, which makes performance of annotations better. You need to set Annotation.IsHidden true or false to hide/show it. Thanks for posting!
  • You must to post comments

There’s no easy way to do this other than ‘Foreach annotation in Annotations where YAxisId = …’.

I was going to suggest a default style, but since AnnotationBase.YAxis is not a dependency property you can’t bind AnnotationBase.IsHidden directly to YAxis.Visibility.

Maybe you could do it with an element name binding from AnnotationBase.IsHidden to YAxis.Visibility but it wouldn’t be clean or easy. I think stick with what you have!

  • You must to post comments
Showing 2 results
Your Answer

Please first to submit.