SciChart® the market leader in Fast WPF Charts, WPF 3D Charts, and now iOS Charting & Android Chart Components

Welcome to the SciChart Community Forums!

Please use the forums below to ask questions about SciChart. Take a moment to read our Question asking guidelines on how to ask a good question and our support policy

We also have a tag=SciChart on Stackoverflow.com where you can earn rep for your questions!

Answered
2
0

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

  • You must to post comments
Best Answer
3
0

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

enter image description here

Hope this helps!

Andrew

  • You must to post comments
0
0

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

  • Ian Carson
    Hi AndrewThat would be great.Thanks & Regards Ian
  • David T
    Andrew, could you please share your solution to this issue which still doesn't seem to have an elegant way of resolving this issue even in the latest version of SciChart 3.1.I am sure this would benefit many other users here using your product.Also, in the above code given by Ian, it doesn't seem to work or I am not sure on how to integrate this. Plus, there seems to be a missing method "item0Element.FindChild<>" FindChild.???ThanksDavid
  • Andrew
    Hi David. Above is the best solution we have at the moment. The problem is related to WPF. How to access the first item in an ItemsControl generated by template. You can find info on FindChild here: http://stackoverflow.com/a/19539095/303612 and also finding items in ItemsControl here http://stackoverflow.com/questions/980120/finding-control-within-wpf-itemscontrol. We've logged a task in the backlog for potential improvement of this API to make it easier for you guys. Best regards, Andrew
  • David Mecteaux
    Hello,I am also a bit fuzzy on how you should integrate this code to get this to work.
  • Andrew
    I've updated the main answer above :)
  • You must to post comments
Showing 2 results
Your Answer

Please first to submit.