04-02-2015 10:46 AM - edited 04-02-2015 10:46 AM
Ha! So I copied the exact code I pasted (the one you said worked for you) and I don't get the error at ni: Plot
BUT, I get this error now...
Error 1 The namespace prefix "niPrimitives" is not defined.
We are getting really close LOL. Is there something I need to define?
Thanks!
04-02-2015 12:28 PM
Yes, niPrimitives is another schema-based namespace:
xmlns:niPrimitives="http://schemas.ni.com/controls/2009/xaml/presentation/primitives"
04-02-2015 12:35 PM
Nice! Thank you... I got this to work.
Altough the toggle button for every plot is not there anymore but I don't think I will need it (at least not now).
09-16-2016 09:07 AM
@phansen wrote: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>
Hi Paul.
Here I am more than a year later 🙂
Could you please post same XAML DataTemplate but only this time include the ToggleButton control? I would like to try and substitute ToggleButton (that looks like default Windows style) with custom CheckMark. So I need the complete DataTemplate to see how Plot visibility is bound to ToggleButton.
Thank you in advance!
09-16-2016 10:56 AM
Plot visibility is handled specifically by binding IsChecked on the ToggleButton to the plot's Visibility with {Binding Visibility, Converter={StaticResource VisibilityToBoolean}}, which uses this converter:
<niPrimitives:MatchedValueConverter x:Key="VisibilityToBoolean" DefaultValue="Collapsed" DefaultResult="False">
<niPrimitives:MatchPair Value="Visible" Result="True" />
</niPrimitives:MatchedValueConverter>
If you are interested, here is the full style we use on the ToggleButton:
<Style x:Key="LegendGlyphVisibilityToggle" TargetType="{x:Type ToggleButton}">
<Setter Property="Width" Value="{Binding GlyphSize.Width, RelativeSource={RelativeSource AncestorType={x:Type ni:Legend},Mode=FindAncestor}}" />
<Setter Property="Height" Value="{Binding GlyphSize.Height, RelativeSource={RelativeSource AncestorType={x:Type ni:Legend}, Mode=FindAncestor}}" />
<Setter Property="Margin" Value="3" />
<Setter Property="Padding" Value="1" />
<Setter Property="HorizontalContentAlignment" Value="Center" />
<Setter Property="VerticalContentAlignment" Value="Center" />
<Setter Property="IsChecked" Value="{Binding Visibility, Converter={StaticResource VisibilityToBoolean}}" />
</Style>
The ToggleButton itself just wraps the legend glyph from the earlier template.