I followed this post http://support.scichart.com/index.php?/Knowledgebase/Article/View/17244/39/tutorial—custom-legend-with-color-picker-and-custom-point-markers for creating a custom Chart Legend and it worked great. One feature of it that I really liked was the checkbox behavior: CheckedChangeZoomExtentsBehaviour.EnableZoomExtentsOnChecked=”True” which zooms the chart to extents everytime you show or hide a series.
This checkbox behavior breaks when I move the Legend outside of the chart, which I accomplished by following this post: https://www.scichart.com/questions/question/moving-legend-outside-sci-chart-plots
How can I keep this checkbox behavior when moving the Legend outside of the Chart area?
Note: if I set ShowLegend=”True” in my s:LegendModifie> tag, the behavior properly works with the legend outside the Chart area, but now I have duplicate legends both inside and outside my chart area with this setting set.
<!-- LEGEND_ITEM_TEMPLATE -->
<DataTemplate x:Key="LegendItemTemplate" DataType="s:SeriesInfo">
<!-- DataContext is of type SeriesInfo -->
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<!-- Visibility checkbox, bound to SeriesInfo.RenderableSeries.IsVisible -->
<CheckBox Margin="5,0,0,0"
HorizontalAlignment="Left"
VerticalAlignment="Center"
behaviors:CheckedChangeZoomExtentsBehaviour.EnableZoomExtentsOnChecked="True"
Foreground="{StaticResource LegendTextBrush}"
IsChecked="{Binding RenderableSeries.IsVisible, Mode=TwoWay}"
Visibility="{Binding LegendData.ShowVisibilityCheckboxes, RelativeSource={RelativeSource AncestorType=s:SciChartLegend}, Converter={StaticResource BooleanToVisibilityConverter}}" />
<s:PointMarker Grid.Column="1" Margin="5,0,0,0" Width="40" Height="10" VerticalAlignment="Center" HorizontalAlignment="Center"
DataContext="{Binding RenderableSeries}"
DeferredContent="{Binding LegendMarkerTemplate}"
Visibility="{Binding ShowSeriesMarkers, RelativeSource={RelativeSource AncestorType=s:SciChartLegend}, Converter={StaticResource BooleanToVisibilityConverter}}" />
<!-- Series Name, bound to SeriesInfo.SeriesName -->
<TextBlock Margin="5,0,5,0"
Grid.Column="2"
HorizontalAlignment="Left"
Foreground="{StaticResource LegendTextBrush}"
Text="{Binding SeriesName}" />
</Grid>
</DataTemplate>
<!-- LEGEND MODIFIER -->
<s:LegendModifier x:Name="ChartLegend" ShowLegend="True" GetLegendDataFor="AllSeries" LegendItemTemplate="{StaticResource LegendItemTemplate}" ShowVisibilityCheckboxes="True" />
<!-- MY LEGEND CONTROL ELSEWHERE ON THE PAGE -->
<s:SciChartLegend x:Name="legendControl" DockPanel.Dock="Top"
Orientation="Horizontal" Margin="10"
ScrollViewer.HorizontalScrollBarVisibility="Auto"
ScrollViewer.VerticalScrollBarVisibility="Auto"
LegendData="{Binding LegendData, ElementName=ChartLegend, Mode=OneWay}"
ShowVisibilityCheckboxes="True" />
- Chris Ludlow asked 8 years ago
- last edited 8 years ago
- You must login to post comments
Hi Chris,
Sure thing, it won’t work if a Legend lies outside. The implementation in CheckedChangeZoomExtentsBehaviour looks for a VisualParent, and SciChartSurface isn’t a VisualParent of the Legend in this case.
There are many ways to amend this. For example, you could add another attached property of ISciChartSurface type and bind it to your SciChartSurface. It will give you access to the surface inside CheckedChangeZoomExtentsBehaviour and you won’t need to look for it in the VisualTree any more.
Hope this helps,
Best regards,
Yuriy
- Yuriy Zadereckii answered 8 years ago
- You must login to post comments
Please login first to submit.