1

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?

bvl
  • 161
  • 2
  • 12
  • 1
    Are there any binding errors in the Visual Studio output window? If you inspect the application with WPF Snoop or Visual Studio XAML Inspector, what is the DataContext of the TextAnnotation? – Dr. Andrew Burnett-Thompson Aug 27 '20 at 08:54
  • 1
    @Dr.AndrewBurnett-Thompson Thank you! It turned out that the data context for annotations was being set elsewhere. The problem was solved by setting the correct data context for annotations in the *.xaml.cs file. For example: SelectedSeriesTextAnnotation.DataContext = new MyVM(). – bvl Aug 27 '20 at 14:55
  • 1
    Great!! I will add an answer so this question doesnt look unanswered :) – Dr. Andrew Burnett-Thompson Aug 27 '20 at 16:34
  • 1
    First thing to do: Take it up with Scichart AMAZING support. – TomTom Aug 27 '20 at 16:44

1 Answers1

1

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.

enter image description here

Binding errors will show up red if there are any, and you can inspect if the DataContext is null or wrong type at runtime.

Dr. Andrew Burnett-Thompson
  • 20,980
  • 8
  • 88
  • 178