11-15-2012 08:52 PM
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.
11-16-2012 11:30 AM
You are close, but there are two issues with the bindings you are using:
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.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>