SciChart® the market leader in Fast WPF Charts, WPF 3D Charts, iOS Chart, Android Chart and JavaScript Chart Components
Hi Guys
I am using an ItemsControl to display a collection of SciStockCharts. I want to be able to use a single SciChartOverview (not part of the Item Template) to set the visible range on all of the charts displayed in the ItemsControl. Is this possible and if so how would I go about achieving it.
Thanks in advance
Regards
Ian Carson
Hello Ian,
I’m cleaning the threads and found your solution to bind the Overview to the first SciChartSurface inside an ItemsControl
Hi Andrew
In the end I looked at this problem from a completely different angle and came up with this solution.
This is the full SciChartOverviewExtension code.
Thanks & Regards
Ian
SciChartOverviewExtension Source Code
public class SciChartOverviewExtensions
{
public static readonly DependencyProperty ItemsControlParentSurfaceProperty =
DependencyProperty.RegisterAttached("ItemsControlParentSurface",
typeof(ItemsControl),
typeof(SciChartOverviewExtensions),
new PropertyMetadata(default(ItemsControl), OnItemsControlPropertyChanged));
public static void SetItemsControlParentSurface(UIElement element, ItemsControl value)
{
element.SetValue(ItemsControlParentSurfaceProperty, value);
}
public static ItemsControl GetItemsControlParentSurface(UIElement element)
{
return (ItemsControl)element.GetValue(ItemsControlParentSurfaceProperty);
}
private static void OnItemsControlPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var overview = (SciChartOverview)d;
var itemsControl = e.NewValue as ItemsControl;
if (itemsControl == null)
{
overview.ParentSurface = null;
return;
}
itemsControl.ItemContainerGenerator.StatusChanged += (_, __) =>
{
if (itemsControl.ItemContainerGenerator.Status != GeneratorStatus.ContainersGenerated) return;
var item0Element = itemsControl.ItemContainerGenerator.ContainerFromIndex(0) as FrameworkElement;
if (item0Element == null)
{
overview.ParentSurface = null;
return;
}
item0Element.Loaded += (s, a) =>
{
var sciChartSurfaceOnLoad = item0Element.FindChild<SciChartSurface>();
overview.ParentSurface = sciChartSurfaceOnLoad;
overview.ParentSurface.RenderableSeries.CollectionChanged += (o, args) =>
{
if (args.Action == NotifyCollectionChangedAction.Add)
overview.DataSeries = overview.ParentSurface.RenderableSeries[0].DataSeries;
};
};
};
}
}
Usage:
<ItemsControl x:Name="ItemsControl" ItemSource="{Binding ViewModelList}">
<ItemsControl.ItemTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
<SciChartOverview local:SciChartOverviewExtensions.ItemsControlParentSurface="{Binding ElementName=ItemsControl}"/>
UPDATE v3.2
The above solution will only work with ItemsControl in WPF. It will not work with the SciChartGroup. To add an Overview in the SciChartGroup we have created an FAQ titled How to add a SciChartOverview to a SciChartGroup using the ScrollBar API in v3.2
Hope this helps!
Andrew
Hi Ian,
Happy new year to you!
It’s a tricky problem, because you need to declare your SciChartOverview outside the ItemsControl, but bind it to the SciChartSurface (or SciStockChart) that is the first child of the ItemsControl.
I’m working on a solution for you now. I should have something to show tomorrow.
Best regards,
Andrew
Please login first to submit.