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
- kewur asked 9 years ago
- last edited 9 years ago
- You must login to post comments
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
- Andrew Burnett-Thompson answered 8 years ago
-
Yes, thank you Andrew. I was able to get the behavior I wanted.
- You must login to post comments
Please login first to submit.