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

1
0

I am trying out SciChart ( and WPF ) for a large dataset and till so far very pleased with the results. I have followed the example as described here http://support.scichart.com/index.php?/Knowledgebase/Article/View/17258/0/creating-a-custom-scichartoverview-with-many-series-using-the-scrollbar-api and can successfully view my bound data and everything is perfect for the first instance.

However, when I assign this usercontrol to different tabs they still somehow share data about the viewstate ( the overview window does not resize, and the slider thing in front of it stays at the same values. My guess is that it has to do with the messages in ActualSizePropertyProxy , but since I am new to SciChart and WPF I was hoping that maybe someone here knows what it is.

Thanks.

  • You must to post comments
2
1

Hi Michael,

There is a little known ‘feature’ in WPF called TabControl virtualisation. This means if you have two tabs bound to view models, and use a DataTemplate to define your tab content, WPF virtualises and re-uses the tab content. Meaning in your case, you might have one instance of a SciChartSurface on two tabs.

Please see this stack overflow question on Why do Tab Controls Re-use View Instances when changing tabs.

You can actually disable this by using a simple converter technique. It’s worth testing the following out to see if your problem was related to Tab Control Virtualization:

public class NewViewForEachInstanceConverter : IValueConverter
{
    private readonly IDictionary<object, object> _views = new Dictionary<object, object>();

    public Type ViewType { get; set; }

    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        if (value == null) return null;
        object view;
        _views.TryGetValue(value, out view);
        if (view != null) return view;

        view = Activator.CreateInstance(ViewType);
        _views.Add(value, view);

        return view;
    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        throw new NotImplementedException();
    }
}

Usage

<UserControl>
    <UserControl.Resources>
        <Infrastructure:NewViewForEachInstanceConverter 
            x:Key="NewControlForEachInstanceConverter" ViewType="{x:Type Views:SomeView}" />
    </UserControl.Resources>
   .....
    <TabControl ItemsSource="{Binding ThingsIWantToBeTabs}">
        <TabControl.ContentTemplate>
            <DataTemplate>
                <ContentControl Content="
                    {Binding Converter={StaticResource NewControlForEachInstanceConverter}}" />
            </DataTemplate>
        </TabControl.ContentTemplate>
    </TabControl>
</UserControl>
  • You must to post comments
0
0

Thank you so much! That completely solved the problem.

Leaks won’t be a problem for me as I will have only a few open tab during the lifespan of the app so very happy with the results. Now going to try out annotations đŸ˜€

  • Andrew
    Great, glad it helped :) most of the memory in SciChart is held in the DataSeries so unless you have hundreds or thousands of chart instances, it should be fine. Thanks!
  • You must to post comments
Showing 2 results
Your Answer

Please first to submit.