SciChart® the market leader in Fast WPF Charts, WPF 3D Charts, iOS Chart, Android Chart and JavaScript Chart Components
I need to put a text box annotation that is located in the top left of the chart. It should remain at the top left even when the chart is zoomed, moved, etc. This should likely be some sort of anchor?
I figured it out. Use a custom TextAnnotation and then set the Horizontal and Vertical Alignment properties.
<Style x:Key="TextAnnotationTopLeft" TargetType="s:TextAnnotation">
<Setter Property="HorizontalAlignment" Value="Left" />
<Setter Property="VerticalAlignment" Value="Top" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="s:TextAnnotation">
<Border x:Name="PART_TextAnnotationRoot"
Margin="{TemplateBinding Margin}"
Background="White"
BorderBrush="Purple"
BorderThickness="0"
CornerRadius="{TemplateBinding CornerRadius}">
<TextBox x:Name="PART_InputTextArea"
Margin="10"
VerticalAlignment="{TemplateBinding VerticalAlignment}"
AcceptsReturn="True"
Background="White"
FontFamily="{TemplateBinding FontFamily}"
FontSize="{TemplateBinding FontSize}"
FontWeight="Bold"
Foreground="Black"
IsTabStop="{TemplateBinding IsEditable}"
Text="{Binding Text,
RelativeSource={RelativeSource TemplatedParent},
Mode=TwoWay}"
TextAlignment="{TemplateBinding TextAlignment}"
TextWrapping="Wrap" />
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Hey Chris,
I’m glad you figured it out, however this is also a feature native to SciChart.
See usage of Annotation.CoordinateMode = CoordinateMode.Relative.
In this mode, the X1,Y1 coordinates are from 0.0 to 1.0 where 0.0 is the left (or bottom) edge of the chart, and 1.0 is the right (or top) edge of the chart.
Furthermore, TextAnnotation can be anchored to the left / top (controlling where the X,Y coordinate operates from) using the HorizontalAnchorPoint and VerticalAnchorPoint properties.
Best regards,
Andrew
Please login first to submit.