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.

0
0

Hello,

I am currently trying to create a Text Annotation that has a Top section displaying the point data ( like a tooltip), but allows custom entry of text underneath. My current attempt is to re-template the TextAnnotation, and I have got it this far (real styling will come later, just trying to get layout for now:

        <Style x:Key="TextAnnotationStyle" TargetType="s:TextAnnotation" >
        <Setter Property="Background" Value="#22B22020"/>
        <Setter Property="BorderThickness" Value="1"/>
        <Setter Property="BorderBrush" Value="Black" />
        <Setter Property="Foreground" Value="#666666"/>
        <Setter Property="CornerRadius" Value="2" />
    </Style>

    <Style x:Key="PositionedTextAnnotationStyle" TargetType="s:TextAnnotation" BasedOn="{StaticResource TextAnnotationStyle}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="s:TextAnnotation">
                    <Border x:Name="PART_TextAnnotationRoot"
                       Margin="{TemplateBinding Margin}"
                    Background="{TemplateBinding Background}"
                    BorderBrush="{TemplateBinding BorderBrush}"
                    BorderThickness="{TemplateBinding BorderThickness}"
                    CornerRadius="{TemplateBinding CornerRadius}"
                            Opacity="0">
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition Height="Auto"/>
                            </Grid.RowDefinitions>

                            <StackPanel Grid.Row="0" Orientation="Horizontal" Background="{TemplateBinding Background}">
                                <TextBlock Text="Frequency: " />
                                <TextBlock Text="{Binding X1, Mode=TwoWay, RelativeSource={RelativeSource AncestorType=s:TextAnnotation}}" FontWeight="Bold"/>
                                <TextBlock Text=" Time: " />
                                <TextBlock Text="{Binding Y1, Mode=TwoWay, RelativeSource={RelativeSource AncestorType=s:TextAnnotation}}" FontWeight="Bold"/>
                            </StackPanel>
                            <TextBox Grid.Row="1" 
                                     x:Name="PART_InputTextArea" 
                                     Background="Transparent" 
                                     BorderThickness="0"/>
                        </Grid>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>

    </Style>

My question is this: the bindings of the 2 TextBlocks to the annotation’s current point don’t appear to be working. There is no output for failed Bindings when it runs, but I get no data when it renders. See the attached screen cap… Am I going down the right path? Is there another direction I should be using, or is there something small that I am missing to make the binding work?

Thank you,
Mike.

Version
4.0.6.8578
Images
  • You must to post comments
0
0

Hi Michael

Retemplating TextAnnotation seems mighty complicated for this task. Is it possible to use a CustomAnnotation which is simply one of our annotation types with a .Content of your choice?

Best regards,
Andrew

  • You must to post comments
0
0

Thanks. My goal has been to create an architecture where a user can choose one of many annotations, most of which will be custom (I may need more help as I go… :+) ), and then have each bound a it’s own ViewModel. This is the first “guinea pig” implementation of that pattern. Your suggestion helped, and I ended up with the following solution. I have a ViewModelBase with X1 and Y1 properties, and a PositionedTextAnnotationViewModel which adds a Text property. Then in XAML:

<s:CustomAnnotation x:Class="Grapes.Common.Charts.Annotations.PositionedTextAnnotation"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
         xmlns:s="http://schemas.abtsoftware.co.uk/scichart"
         xmlns:local="clr-namespace:Grapes.Common.Charts.Annotations"
         mc:Ignorable="d"
         d:DesignHeight="300" d:DesignWidth="300"
                X1="{Binding X1, Mode=OneWayToSource}"
                Y1="{Binding Y1, Mode=OneWayToSource}">

<Border x:Name="PART_TextAnnotationRoot"
                    Margin="2"
                    Background="Azure"
                    BorderBrush="Black"
                    BorderThickness="1"
                    CornerRadius="2"  >
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>

        <StackPanel Grid.Row="0" Orientation="Horizontal">
            <TextBlock Text="Frequency: " />
            <Label Content="{Binding X1}"/>
            <TextBlock Text=" Time: " />
            <Label Content="{Binding Y1}"/>
        </StackPanel>
        <TextBox Grid.Row="1" x:Name="PART_InputTextArea" Text="{Binding Text}" />
    </Grid>
</Border>

And on AnnotationCreationModifier.AnnotationCreated:

  var vm = PositionedTextAnnotationViewModel.Create();
  annotation.DataContext = vm;

The keys were to make the bindings on the Annotation Mode=OneWayToSource (otherwise the annotation picks up the NaN values on the VM) and also to change the TextBlocks to Labels so their size reacts to data changes. I Still have formatting to do of course, but the pattern is there, thank you very much!

Mike.

  • You must to post comments
Showing 2 results
Your Answer

Please first to submit.