We are using HorizontalLineAnnotation and VerticalLineAnnotations on a chart. We have subclassed these classes so that we could use our own AnnotationLabels that display text instead of the value of the line position.
something like this:
`
<s:HorizontalLineAnnotation.Resources>
</s:HorizontalLineAnnotation.Resources>
<s:HorizontalLineAnnotation.Stroke>
<SolidColorBrush Color="{Binding Color}"/>
</s:HorizontalLineAnnotation.Stroke>
<s:HorizontalLineAnnotation.ToolTip>
<ToolTip Content="{Binding Label}"
Visibility="{Binding Label, Converter={StaticResource EmptyStringToVisibilityCollapsedConverter}}"/>
</s:HorizontalLineAnnotation.ToolTip>
<s:AnnotationLabel x:Name="_annotationLabel" LabelPlacement="Axis" BorderThickness="0" Text="{Binding DataContext.Label}"
Background="Transparent">
<s:AnnotationLabel.Foreground>
<SolidColorBrush Color="{Binding DataContext.Color}"/>
</s:AnnotationLabel.Foreground>
</s:AnnotationLabel>
`
Now we want to use our own custom control similar to a TextBlock as the axis label. Is it possible to template the AnnotationLabel or maybe another way to accomplish this? The custom control we have is used to highlight part of the text in the textblock (using Runs) for search highlighting so even if we have to do it a different way, that would acceptable.
What I would like to do:
.
.
.
<s:AnnotationLabel x:Name="_annotationLabel" LabelPlacement="Axis" BorderThickness="0" Text="{Binding DataContext.Label}" Background="Transparent">
<s:AnnotationLabel.Foreground>
<SolidColorBrush Color="{Binding DataContext.Color}"/>
</s:AnnotationLabel.Foreground>
<s:AnnotationLabel.Style>
<Style TargetType="s:AnnotationLabel">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="s:AnnotationLabel">
<controls:HighlightingTextBlock Text="{TemplateBinding Text}" HighlightedText="{Binding
DataContext.HighlightedLabelText}"/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</s:AnnotationLabel.Style>
</s:AnnotationLabel>
- patrick milinazzo asked 4 years ago
- last active 4 years ago