Pre loader

Templating LineAnnotation

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

Answered
0
0

Hi,

I’m trying to template the LineAnnotation. I have a subclass inheriting from LineAnnotation which has some additional dependency properties. I’m trying to put a border around the LineAnnotation but because it’s in a canvas the border’s size is not correct. How would I go about making the border have the correct width? You can see what I’m getting with the curent template in the image.

Also, is there a way to template IsSelected visuals?

            <ControlTemplate x:Key="LineAnnotationTemplate" TargetType="local:BorderedLineAnnotation">
            <Grid x:Name="PART_LineAnnotationRoot" Margin="{TemplateBinding Margin}">
                <Border BorderBrush="{TemplateBinding IsHighlighted, Converter={StaticResource BooleanToHighlightColorConverter}}" BorderThickness="1">
                    <Line x:Name="PART_Line" Stroke="{TemplateBinding Stroke}" StrokeDashArray="{TemplateBinding StrokeDashArray}" StrokeThickness="{TemplateBinding StrokeThickness}"/>
                </Border>
                <Line x:Name="PART_GhostLine"/>
            </Grid>
        </ControlTemplate>

One last thing, what is “PART_GhostLine”, and what does it do?

Thanks

Images
  • You must to post comments
Best Answer
1
0

Hi there,

The template for the LineAnnotation type is

<Style BasedOn="{StaticResource AnnotationBaseStyle}" TargetType="a:LineAnnotation">
   <Setter Property="Stroke" Value="{me:ThemeBinding RubberBandStrokeBrush}" />
   <Setter Property="StrokeThickness" Value="2.0" />
   <Setter Property="Template">
      <Setter.Value>
         <ControlTemplate TargetType="a:LineAnnotation">
            <Grid x:Name="PART_LineAnnotationRoot">
               <Line x:Name="PART_GhostLine"
                    Stroke="Transparent"
                    StrokeThickness="{s:Static Member=visuals:ManipulationMargins.AnnotationLineWidth}" /> <!-- defaults to 5 -->
               <Line x:Name="PART_Line"
                    Stroke="{TemplateBinding Stroke}"
                    StrokeDashArray="{TemplateBinding StrokeDashArray}"
                    StrokeThickness="{TemplateBinding StrokeThickness}" />
            </Grid>
         </ControlTemplate>
      </Setter.Value>
   </Setter>
</Style>

Where AnnotationBaseStyle is defined as

<!--  Annotations  -->
<Style x:Key="AnnotationBaseStyle" TargetType="a:AnnotationBase">
   <Style.Setters>
      <Setter Property="IsTabStop" Value="False" />
      <Setter Property="Foreground" Value="{me:ThemeBinding TickTextBrush}" />
      <Setter Property="FontSize" Value="12" />
   </Style.Setters>
</Style>

The PART_GhostLine provides a thicker, transparent line behind the main line which enables mouse-over to work more responsively. e.g. if the mouse is within 5 pixels of the edges of the line, it will still be detectable.

Does this help you implement your own control template for lines?

Best regards,
Andrew

  • kewur
    Yes, thank you Andrew. I was able to get the behavior I wanted.
  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.

Try SciChart Today

Start a trial and discover why we are the choice
of demanding developers worldwide

Start TrialCase Studies