Hi sciChart,
I create a custom annotation base type BoxAnnotation.
<s:BoxAnnotation x:Class="ChartComponent.Annotations.TowLines"
xmlns=" http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x=" http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:s=" http://schemas.abtsoftware.co.uk/scichart">
</s:BoxAnnotation>
I use style
<Style BasedOn="{StaticResource AnnotationBaseStyle}" TargetType="Annotations:TowLines">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="s:BoxAnnotation">
<Border x:Name="PART_BoxAnnotationRoot"
Margin="{TemplateBinding Margin}"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
CornerRadius="{TemplateBinding CornerRadius}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="2"/>
<RowDefinition Height=""/>
<RowDefinition Height="2"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width=""/>
</Grid.ColumnDefinitions>
<s:HorizontalLineAnnotation Grid.Row="0" Grid.Column="0" VerticalContentAlignment="Top" Stroke="Blue" Margin="0,0,50,0" StrokeThickness="2">
<s:AnnotationLabel LabelPlacement="Right" FontSize="10" Foreground="White"/>
</s:HorizontalLineAnnotation>
<s:HorizontalLineAnnotation Grid.Row="2" Grid.Column="0" VerticalContentAlignment="Bottom" Stroke="Red" Margin="0,0,50,0" StrokeThickness="2">
<s:AnnotationLabel LabelPlacement="Right" FontSize="10" Foreground="White"/>
</s:HorizontalLineAnnotation>
</Grid>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
The label of HorizontalLineAnnotation in custom annotation not show.
- shiwa asked 11 years ago
- You must login to post comments
Hi there,
Could I ask you, why do you need to do something like this? What do you want to achieve? Maybe we can suggest you another way how to implement the desired behavior.
The main problem with your implementation is using HorizontalLineAnnotations inside the ControlTemplate, for annotations use own layout system and are drawn relative to the chart and during its rendering. Also that is why labels aren’t shown.
Concerning your implementation, I can suggest you binding X1,X2 coordinates for annotations inside the template to corresponding properties of parent annotation and setting HorizontalAlignment=”Center(default value is “Stretch”, so annotation is drawn using Y coordinate only). Please, try something like like this:
<ControlTemplate TargetType="s:BoxAnnotation"> <Border x:Name="PART_BoxAnnotationRoot" Margin="{TemplateBinding Margin}" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="{TemplateBinding CornerRadius}"> <Grid> <Grid.RowDefinitions> <RowDefinition Height="2"/> <RowDefinition Height="*"/> <RowDefinition Height="2"/> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition Width="*"/> </Grid.ColumnDefinitions> <s:HorizontalLineAnnotation HorizontalAlignment="Center" X1="{TemplateBinding X1}" X1="{TemplateBinding X2}" LabelPlacement="Right" ... /> <s:HorizontalLineAnnotation HorizontalAlignment="Center" X1="{TemplateBinding X1}" X1="{TemplateBinding X2}" LabelPlacement="Right" ... /> </Grid> </Border> </ControlTemplate>
Please, let us know the above helps!
Best regards,
Yuriy
- Yuriy Zadereckiy answered 11 years ago
- You must login to post comments
Please login first to submit.