02-10-2014 06:22 AM
Hello,
can i change the Legend that it shows the current Value of the Plot ?
It works with Windows Forms and Labview.
Please have a look at the Image as Example:
02-10-2014 01:28 PM
The default data template used to display plots in the WPF Legend
use a glyph and a text box to show the Renderer
and Label
for a plot.
You can either add custom objects that associate each plot with a current value, or use a property like Tag
on the plot itself. Below is an example of the latter approach, using a data template targeted at Plot
and displaying Tag
:
<DataTemplate DataType="{x:Type ni:Plot}">
<StackPanel Orientation="Horizontal">
<niPrimitives:LegendGlyph Margin="3"
Renderer="{Binding ActualRenderer}"
Background="{Binding ItemBackground, RelativeSource={RelativeSource AncestorType={x:Type ni:Legend}, Mode=FindAncestor}}"
Width="{Binding GlyphSize.Width, RelativeSource={RelativeSource AncestorType={x:Type ni:Legend}, Mode=FindAncestor}}"
Height="{Binding GlyphSize.Height, RelativeSource={RelativeSource AncestorType={x:Type ni:Legend}, Mode=FindAncestor}}" />
<ContentPresenter Margin="3"
VerticalAlignment="Center"
Content="{Binding Tag}" />
</StackPanel>
</DataTemplate>
02-11-2014 01:21 AM
Hi Paul,
im sorry but it didn't work in my case.
Here is my code. Did i made something wrong ?
<Border Style="{StaticResource ControlsBorderStyle}" Grid.Row="1" Grid.ColumnSpan="2"> <Border.Resources> <DataTemplate DataType="{x:Type ni:Plot}"> <StackPanel Orientation="Horizontal"> <niPrimitives:LegendGlyph Margin="3" Renderer="{Binding ActualRenderer}" Background="{Binding ItemBackground, RelativeSource={RelativeSource AncestorType={x:Type ni:Legend}, Mode=FindAncestor}}" Width="{Binding GlyphSize.Width, RelativeSource={RelativeSource AncestorType={x:Type ni:Legend}, Mode=FindAncestor}}" Height="{Binding GlyphSize.Height, RelativeSource={RelativeSource AncestorType={x:Type ni:Legend}, Mode=FindAncestor}}" /> <ContentPresenter Margin="3" VerticalAlignment="Center" Content="{Binding Tag}" /> </StackPanel> </DataTemplate> </Border.Resources> <ni:Graph x:Name="graph" DataSource="{Binding chartCollection}" RenderMode="Raster" PreferIndexData="True" SuppressScaleLayout="True" nix:GraphExtensions.PlotsSource="{Binding Plots2}" nix:GraphExtensions.AxesSource="{Binding GraphAxes}"> <ni:Graph.ContextMenu> <ContextMenu> <MenuItem Header="Konfiguration" Command="{Binding ShowConfigurationCommand}" > </MenuItem> <MenuItem Header="Entfernen" Command="{Binding RemoveMeCommand}" > </MenuItem> <MenuItem Header="Ebene nach vorne" Command="{Binding MoveOneLayerUpCommand}" > </MenuItem> <MenuItem Header="Ebene nach hinten" Command="{Binding MoveOneLayerDownCommand}" > </MenuItem> </ContextMenu> </ni:Graph.ContextMenu> </ni:Graph> </Border> <Border BorderBrush="White" BorderThickness="0,1,1,1" Grid.Row="1" Grid.RowSpan="2" Grid.Column="2"> <ni:Legend x:Name="legend" ItemsSource="{Binding ElementName=graph, Path=Plots}" Margin="0,0,5,0" Padding="5" Background="Transparent" BorderThickness="0"> </ni:Legend> </Border> <Border BorderBrush="White" BorderThickness="1,0,1,1" Grid.Row="2" Grid.ColumnSpan="2" > <StackPanel HorizontalAlignment="Center" Orientation="Horizontal"> <ni:GraphInteractionPalette Graph="{Binding ElementName=graph}" /> <Button Content="Start" Width="30" Command="{Binding StartCommand}"/> <Button Content="Stop" Width="30" Command="{Binding StopCommand}"/> </StackPanel> </Border>
02-11-2014 10:07 AM
Looking at the structure of your XAML:
Since WPF resources are found by traversing parent elements, the legend will not see the data template defined under the graph's border. If you move the resources to the legend's border, or move the resources up to the parent grid, then the legend should be able to resolve the resource.
02-12-2014 03:24 AM
Hi Paul,
i changed it to:
<StackPanel> <StackPanel.Resources> <DataTemplate DataType="{x:Type ni:Plot}"> <StackPanel Orientation="Horizontal"> <niPrimitives:LegendGlyph Margin="3" Renderer="{Binding ActualRenderer}" Background="{Binding ItemBackground, RelativeSource={RelativeSource AncestorType={x:Type ni:Legend}, Mode=FindAncestor}}" Width="{Binding GlyphSize.Width, RelativeSource={RelativeSource AncestorType={x:Type ni:Legend}, Mode=FindAncestor}}" Height="{Binding GlyphSize.Height, RelativeSource={RelativeSource AncestorType={x:Type ni:Legend}, Mode=FindAncestor}}" /> <ContentPresenter Margin="3" VerticalAlignment="Center" Content="{Binding Tag}" /> </StackPanel> </DataTemplate> </StackPanel.Resources> <ni:Graph x:Name="graph" DataSource="{Binding chartCollection}" RenderMode="Vector" PreferIndexData="True" SuppressScaleLayout="True" nix:GraphExtensions.PlotsSource="{Binding Plots2}" nix:GraphExtensions.AxesSource="{Binding GraphAxes}"> <ni:Graph.ContextMenu> <ContextMenu> <MenuItem Header="Konfiguration" Command="{Binding ShowConfigurationCommand}" > </MenuItem> <MenuItem Header="Entfernen" Command="{Binding RemoveMeCommand}" > </MenuItem> <MenuItem Header="Ebene nach vorne" Command="{Binding MoveOneLayerUpCommand}" > </MenuItem> <MenuItem Header="Ebene nach hinten" Command="{Binding MoveOneLayerDownCommand}" > </MenuItem> </ContextMenu> </ni:Graph.ContextMenu> </ni:Graph> <ni:Legend x:Name="legend" ItemsSource="{Binding ElementName=graph, Path=Plots}" Margin="0,0,5,0" Padding="5" Background="Transparent" BorderThickness="0"> </ni:Legend> </StackPanel>
and i got the same Result.
02-12-2014 09:40 AM
From the screenshot, it looks like the custom data template is being used. You can confirm this by changing the {Binding Tag}
in the data template to {Binding Tag, TargetNullValue=NULL}
, or setting the background on the stack panel in the data template, to confirm that updating the data template updates the legend items.
02-13-2014 01:28 AM
hi Paul,
i cannot get it working. Please see the Demo-Projekt. It shows always NULL if i do this.
02-13-2014 09:27 AM
Since the legend now shows the "NULL
" fallback value, that indicates the custom data template is being used, but the value of Tag
is always null
.
With the custom data template, you can set the Tag
property on your plots just as you would assign the Text
property on legend items in Windows Forms. For example, in the Model.cs
file in your attached project, if you add p.Tag = "test value";
after creating the plot in the GraphControl
constructor (line 155), you will see that value instead of "NULL
" appear in the legend.
02-19-2014 02:25 PM
You mentioned the the current values display in the Winforms legend. How did you get that to work. I didn't find any option for that. I'm using Measurement Studio 2010. Was that a new addition to a later version?
02-19-2014 02:36 PM
There is no concept of a "current value" in the WPF or Windows Forms graphs. My understanding from the screenshot was that the Text
property on the Windows Forms LegendItem
was being used to reflect the application's concept of "current value".