Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

[WPF] Problem with the binding between annotation and the plot

Hi,all.

My work is based on a graph with several plots in it. Now I'm tring to add a cursor and a annotation to indicate the y-values under the same x-index.I'm planning to use the same brush in each textblock of annotation and the corresponding plot, but I don't know how to set the binding.The following xaml codes is what I wrote and seems not  to work.

 

   <ni:Graph.Plots>
        <ni:Plot Label="Plots[0]" >
            <ni:LinePlotRenderer Stroke="Blue"  StrokeThickness="0.5"/>
        </ni:Plot> 

        ...

   </ni:Graph.Plots>

   <ni:PointAnnotation.LabelTemplate>
        <DataTemplate>
              <TextBlock Text="{Binding ElementName=cursor, Path=Value[1]}"
                               Foreground="{Binding ElementName=Plots[0],Path=Stroke}" />

              ...

        </DataTemplate>
    </ni:PointAnnotation.LabelTemplate>

 

Another small question is how to hide the values near the cursor? Since I want to show the values by the annotations on top of the graph.

 

0 Kudos
Message 1 of 2
(5,374 Views)

You are close, but there are two issues with the bindings you are using:


  1. The Plot has its Label set to "{{Plots[0]}}", but a label does not act as a name in XAML, which means ElementName will not be able to find it.
     
  2. The Stroke property is defined on the Renderer of the plot, not on the plot itself, so the Path is referencing a non-existent property.

Here is an example showing all the graph children with the correct bindings:


    <ni:Graph.Plots>
        <ni:Plot x:Name="plot0" Label="Plots[0]">
            <ni:LinePlotRenderer Stroke="Blue" StrokeThickness="0.5" />
        </ni:Plot>
    </ni:Graph.Plots>

    <ni:Graph.Children>
        <ni:Cursor x:Name="cursor" />

        <ni:PointAnnotation>
            <ni:PointAnnotation.LabelTemplate>
                <DataTemplate>
                    <TextBlock
                        Text="{Binding ElementName=cursor, Path=Value[1]}"
                        Foreground="{Binding ElementName=plot0, Path=Renderer.Stroke}" />
                </DataTemplate>
            </ni:PointAnnotation.LabelTemplate>
        </ni:PointAnnotation>
    </ni:Graph.Children>

~ Paul H
0 Kudos
Message 2 of 2
(5,364 Views)