Hello!
I have a SciChartSurface with 193 series on it and my application needs to display a legend with 193 items. The requirement is that a legend should be located underneath the plot as a scrollable panel with items arranged in a wrap-panel fashion. The problem is that it takes a long time to render this many items because WrapPanel does not use Virtualization.
I found a 3-rd party control (https://github.com/sbaeumlisberger/VirtualizingWrapPanel) that implements virtualization in a WrapPanel. However, it is designed to work inside a ListBox/ListView and does not as an ItemPanelTemplate for SciChartLegend.
Is it possible to render LegendData in a custom control? I’ve noticed that LegendData is a ChartDataObject. However, when I bind its SeriesInfo property my ListBox is not populated.
Here is my XAML:
In my SciChartSurface I’ve added a modifier:
<s:SciChartSurface.ChartModifier>
<s:ModifierGroup>
<!-- Turn this legend off because we've got a custom one below -->
<s:LegendModifier GetLegendDataFor="AllSeries" ShowLegend="False" />
<local:ErrorBarExclusionLegendModifier x:Name="mwErrorBarExcluder" />
<s:TooltipModifier />
<local:MouseClickChartModifier RightClickPosition="{Binding RightClickPosition, Mode=OneWayToSource}" />
</s:ModifierGroup>
</s:SciChartSurface.ChartModifier>
Then I declare a ListBox:
<ListBox
Grid.Row="4"
Grid.Column="0"
Height="220"
ItemTemplate="{StaticResource SciChartLegendItemTemplate}"
ItemsSource="{Binding LegendData, ElementName=mwErrorBarExcluder, Converter={StaticResource SeriesConv}}">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<wtk:VirtualizingWrapPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
</ListBox>
Since I can’t bind ItemsSource to ChartDataObject I wrote a simple converter that extracts the collection of SeriesInfo objects:
public object Convert(object aValue, Type aTargetType, object aParameter, CultureInfo aCulture)
{
ChartDataObject fSource = aValue as ChartDataObject;
return fSource?.SeriesInfo;
}
What am I doing wrong?
Thank you in advance for your suggestions.
- You must login to post comments
I resolved my own issue. Turned out ErrorBarExclusionLegendModifier is a local class that filters series. It updated ChartDataObject.SeriesInfo but not the object itself so the PropertyChanged event was never fired. I modified it to expose ObservableCollection instead and removed the converter. Now it works. https://github.com/sbaeumlisberger/VirtualizingWrapPanel is a useful control.
- Alexander Gdalevich answered 4 years ago
- You must login to post comments
Please login first to submit.