03-30-2015 08:36 AM - edited 03-30-2015 08:41 AM
Hello, I have three questions... (WPF C#)
Thank you!
Solved! Go to Solution.
03-30-2015 10:04 AM
1. A separate label is the expected way to associate a control with a descriptive name.
2. The default template for plot labels in the Legend
uses a TextBox
, which appears to override Foreground
in its default style. An easy workaround is to specify a custom label template:
<DataTemplate x:Key="PlotLabelTemplate">
<TextBlock Text="{Binding}" />
</DataTemplate>
...
<ni:Plot Label="Plot 1" LabelTemplate="{StaticResource PlotLabelTemplate}" />
3. In your screenshot, the axis ticks and labels already match the foreground, so I assume by "Axis color" you mean the baseline color? In that case, you can set the BaselineStroke
property:
<ni:AxisDouble Orientation="Vertical" BaselineStroke="White" />
03-30-2015 10:52 AM - edited 03-30-2015 10:54 AM
Thank you. I got #1 and #3 but can't make #2 work.
This is my XAML code (I generate Plots programatically in C#).
Could you please help?
<DockPanel x:Name="Vco1Graph" Visibility="Visible"> <Grid DockPanel.Dock="Top"> <ni:GraphInteractionPalette Graph="{Binding ElementName=GraphVCO1}" Margin="50,0,0,0"/> <Label Content="VCO__1" HorizontalAlignment="Center" Style="{DynamicResource EvolvDiagsLabel}"/> </Grid> <ni:Legend ItemsSource="{Binding AllPlots, ElementName=GraphVCO1}" DockPanel.Dock="Right" Width="90" IsTabStop="False"
ItemBackground="{DynamicResource ColorSolidReadOnlyBackground}"
BorderBrush="{Binding BorderBrush, ElementName=GraphVCO1}"
Background="{DynamicResource ColorSolidReadOnlyBackground}"
Foreground="{DynamicResource ColorSolidNormalForeground}"/> <ni:Graph x:Name="GraphVCO1" DockPanel.Dock="Top" HorizontalAlignment="Left" Width="877"
PlotAreaBackground="{DynamicResource ColorSolidReadOnlyBackground}"
PlotAreaBorderBrush="{DynamicResource ColorSolidReadOnlyBackground}"> <ni:Graph.Plots> <ni:Plot/> </ni:Graph.Plots> <ni:Graph.Axes> <ni:AxisDouble Orientation="Vertical" BaselineStroke="{DynamicResource ColorSolidNormalForeground}"> <ni:AxisDouble.LabelTemplate> <DataTemplate> <Label Content="dB" Foreground="{DynamicResource ColorSolidNormalForeground}"/> </DataTemplate> </ni:AxisDouble.LabelTemplate> <ni:AxisDouble.MajorGridLines> <ni:GridLines Stroke="{DynamicResource ColorSolidNormalForeground}" StrokeThickness="0.3"/> </ni:AxisDouble.MajorGridLines> </ni:AxisDouble> <ni:AxisDouble Orientation="Horizontal" Adjuster="FitExactly" BaselineStroke="{DynamicResource ColorSolidNormalForeground}"> <ni:AxisDouble.LabelTemplate> <DataTemplate> <Label Content="GHz" Foreground="{DynamicResource ColorSolidNormalForeground}"/> </DataTemplate> </ni:AxisDouble.LabelTemplate> <ni:AxisDouble.MajorGridLines> <ni:GridLines Stroke="{DynamicResource ColorSolidNormalForeground}" StrokeThickness="0.3"/> </ni:AxisDouble.MajorGridLines> </ni:AxisDouble> </ni:Graph.Axes> </ni:Graph> </DockPanel>
03-30-2015 11:39 AM
Since you are generated plots in code, it may make more sense for you to override the default legend template for plots instead:
<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 Label}" />
</StackPanel>
</DataTemplate>
03-30-2015 11:59 AM
Thanks but it's still not clear when I have ti insert this chunk of code. No matter what I try I get errors.
03-30-2015 01:08 PM
Sorry for not specifying that before. It should go in the Resources
for the legend (or in Resources
higher up). For example:
<ni:Legend ItemsSource="{Binding ...}" ...>
<ni:Legend.Resources>
<DataTemplate DataType="{x:Type ni:Plot}">
...
</DataTemplate>
</ni:Legend.Resources>
</ni:Legend>
04-01-2015 07:59 AM
Still no luck... I get:
"Error 1 The name "Plot" does not exist in the namespace "http://schemas.ni.com/controls/2009/xaml/presentation"
<DockPanel> <Grid> <ni:GraphInteractionPalette Graph="{Binding ElementName=GraphVCO1}"/> </Grid> <ni:Legend ItemsSource="{Binding AllPlots, ElementName=GraphVCO1}"> <ni:Legend.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 Label}"/> </StackPanel> </DataTemplate> </ni:Legend.Resources> </ni:Legend> <ni:Graph x:Name="GraphVCO1" <ni:Graph.Plots> <ni:Plot/> </ni:Graph.Plots> </ni:Graph> </DockPanel>
04-02-2015 09:45 AM
If you're in Visual Studio 2013 then you'll need to create a .licx file as outlined here: http://digital.ni.com/public.nsf/allkb/C51E3B38578FAD2786257C070069F386. That error can be caused by not having an licx file.
Kevin
04-02-2015 09:47 AM
I already solved the licx issue last week and have been able to do eveyrhting since then. I just want to change the color of the Legend labels
04-02-2015 10:15 AM
Unfortunately, I could not reproduce the issue you are seeing. It seems particularly odd since you declare a <ni:Plot/>
later on in your example.
Since the schema-based XML namespace does not seem to be recognized, as a workaround you could try using the CLR assembly-based XML namespace:
xmlns:niGraphs="clr-namespace:NationalInstruments.Controls;assembly=NationalInstruments.Controls.Graphs"
...
<DataTemplate DataType="{x:Type niGraphs:Plot}">
...