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!

Please note: SciChart team will only answer questions from customers with active support subscriptions. Expired support questions will be ignored. If your support status shows incorrectly, contact us and we will be glad to help.

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.