Jump to content
Software FX Community

SeriesAttributes.Visibility=Visibility.Hidden doesn't cause the legend to update


Recommended Posts

That's an interesting issue. You can change the template for a legend box item, so we have a sample/prototype that shows checkboxes in the legend box to allow you to show/hide series. Obviously if unchecking a series would cause the legend box item to dissapear it would give you no way to turn it back on.

We have also already assigned meaning to Visibility.Hidden/Visibility.Collapsed, Hidden will cause the series to still "contribute" to the pane or axis this series is attached to. (Note that in the current builds only pane functionality has been implemented but future builds will also incorporate axis functionality).

Because of this we will be adding a property called ShowHiddenSeries in the LegendBox, when set to false you will get the behavior you want.



Link to comment
Share on other sites

You will need these namespaces in your root node


This template in your Window/Page resources


DataTemplate x:Key="CheckableLegend">   <DataTemplate.Resources>   <cfxConverters:VisibilityToBooleanConverter x:Key="visibilityToBool"/>   </DataTemplate.Resources>   <Grid>   <Grid.ColumnDefinitions>   <ColumnDefinition Width="Auto" />   <ColumnDefinition Width="Auto" SharedSizeGroup="FirstRow"/>   <ColumnDefinition Width="*" />   </Grid.ColumnDefinitions>   <CheckBox Background="{Binding Path=Fill}" IsChecked="{Binding Path=Visibility, Converter={StaticResource visibilityToBool}}" Margin="2,0" VerticalAlignment="Center"/>   <cfxControls:MarkerLegendControl Content="{Binding Path=Self}" Grid.Column="1" />   <Border Background="Transparent" Grid.Column="2" VerticalAlignment="Center"> <ContentControl IsHitTestVisible="false" Content="{Binding Path=Content}" ContentTemplate="{Binding Path=ContentTemplate}" Foreground="{Binding Path=Foreground}" FontFamily="{Binding Path=FontFamily}" FontSize="{Binding Path=FontSize}" FontStyle="{Binding Path=FontStyle}" FontWeight="{Binding Path=FontWeight}"/>   </Border>   </Grid>   <DataTemplate.Triggers>   <DataTrigger Binding="{Binding Path=Dimmed}">   <DataTrigger.Value>   <sys:Boolean>True</sys:Boolean>   </DataTrigger.Value>   <Setter Property="Opacity" Value="0.25" />   </DataTrigger>   </DataTemplate.Triggers></DataTemplate>

And this code in your Window/Page Loaded event

  chart1.LegendBox.ItemAttributes[chart1.Series].Template = (DataTemplate) FindResource("CheckableLegend");

Please note the following:

- VisibilityToBooleanConverter will collapse when the boolean is false, future builds will support a property to change this behavior.- By using MarkerLegendControl you are allowing us to represent different galleries with different shapes, you could also "draw" your own shape and bind to properties such as Fill, Stroke, etc.- Wrapping the ContentControl inside a border fixes an issue trapping mouse events for highlight purposes.



Link to comment
Share on other sites

Thanks Juan.  I'm actually looking for something a little simpler than that even.

 Is it possible for me to set the chart1.LegendBox.ItemsAttributes through XAML?

chart1.LegendBox.ItemAttributes[chart1.Series].Template = (

DataTemplate) FindResource("CheckableLegend");

We're not using code-behind for our bindings or anything.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...