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

Welcome to the SciChart Community Forums!

Please use the forums below to ask questions about SciChart. Take a moment to read our Question asking guidelines on how to ask a good question and our support policy

We also have a tag=SciChart on Stackoverflow.com where you can earn rep for your questions!

0
0

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&quot;
xmlns:x=" http://schemas.microsoft.com/winfx/2006/xaml&quot;
xmlns:s=" http://schemas.abtsoftware.co.uk/scichart"&gt;

</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="
"/>

                            &lt;/Grid.ColumnDefinitions&gt;
                            &lt;s:HorizontalLineAnnotation Grid.Row=&quot;0&quot; Grid.Column=&quot;0&quot; VerticalContentAlignment=&quot;Top&quot; Stroke=&quot;Blue&quot; Margin=&quot;0,0,50,0&quot; StrokeThickness=&quot;2&quot;&gt;
                                &lt;s:AnnotationLabel LabelPlacement=&quot;Right&quot; FontSize=&quot;10&quot; Foreground=&quot;White&quot;/&gt;
                            &lt;/s:HorizontalLineAnnotation&gt;
                            &lt;s:HorizontalLineAnnotation Grid.Row=&quot;2&quot; Grid.Column=&quot;0&quot; VerticalContentAlignment=&quot;Bottom&quot; Stroke=&quot;Red&quot; Margin=&quot;0,0,50,0&quot; StrokeThickness=&quot;2&quot;&gt;
                                &lt;s:AnnotationLabel LabelPlacement=&quot;Right&quot; FontSize=&quot;10&quot; Foreground=&quot;White&quot;/&gt;
                            &lt;/s:HorizontalLineAnnotation&gt;
                        &lt;/Grid&gt;
                    &lt;/Border&gt;
                &lt;/ControlTemplate&gt;
            &lt;/Setter.Value&gt;
        &lt;/Setter&gt;
    &lt;/Style&gt;

The label of HorizontalLineAnnotation in custom annotation not show.

Images
  • You must to post comments
0
0

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

  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.