I have a simple SciChart CompositeAnnotation:
<s:CompositeAnnotation x:Class="KernelDensity.DensityAnnotation"
xmlns:s="http://schemas.abtsoftware.co.uk/scichart"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Canvas.ZIndex="1" MouseDoubleClick="DensityAnnotation_OnMouseDoubleClick">
<s:CompositeAnnotation.Annotations>
<s:BoxAnnotation x:Name="DensityBoxArea" Background="#FFBADAFF" BorderBrush ="Black" BorderThickness="1" CoordinateMode="Relative" CornerRadius="1" Width="1" Height="1" Opacity="0.5" X1="0" X2="1" Y1="0" Y2="1" >
<s:BoxAnnotation.Template>
<ControlTemplate TargetType="s:BoxAnnotation">
<Border x:Name="PART_BoxAnnotationRoot"
Margin="{TemplateBinding Margin}"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
CornerRadius="{TemplateBinding CornerRadius}">
<Image x:Name="DensityPlot" Width="Auto" Stretch="Fill"/>
</Border>
</ControlTemplate>
</s:BoxAnnotation.Template>
</s:BoxAnnotation>
<s:TextAnnotation x:Name="SelectedSeriesTextAnnotation"
Background="Black"
CoordinateMode="Relative"
CornerRadius="3"
Foreground="White"
HorizontalAnchorPoint="Center"
X1="0.5"
Y1="0.5"
FontSize="14"
Text="{Binding SelectedSeriesTextAnnotationText}">
</s:TextAnnotation>
</s:CompositeAnnotation.Annotations>
<s:CompositeAnnotation.ToolTip >
<ToolTip Placement="Right">
<TextBlock Text="{Binding SelectedSeriesTextAnnotationText}" FontSize="15" Foreground="Black"/>
</ToolTip>
</s:CompositeAnnotation.ToolTip>
</s:CompositeAnnotation>
Here you can see that TextAnnotation-Text attribute and ToolTip-TextBlock-Text attribute have the same bindings to my view model property. The problem is that this binding works correctly for ToolTip TextBlock Text attribute, but doesn't work for TextAnnotation Text attribute (as if there is no binding at all). How can I fix this problem?
The first thing to check when diagnosing any binding issues are if there are any warnings in the Visual Studio output window. Look for lines like this in the Console / Output window
System.Windows.Data Information: 10 : Cannot retrieve value using the binding and no valid fallback value exists; using default instead. BindingExpression:Path=IDontExist; DataItem=null; target element is ‘TextBlock’ (Name=”); target property is ‘Text’ (type ‘String’)
If there are no BindingExpression errors in the output window, the next thing to check is the DataContext of the object that is failing to bind. What type is it? Is it set at runtime?
A great tool to inspect bindings is WPF Snoop. You can hover an item and see the properties live. You can also see binding errors right there. There is a related question and answer here which shows how to do this.
Binding errors will show up red if there are any, and you can inspect if the DataContext is null or wrong type at runtime.