Pre loader

MVVM ViewportManager.ZoomExtents doesn't seem to work as expected

Welcome to the SciChart Forums!

  • Please read our Question Asking Guidelines for how to format a good question
  • Some reputation is required to post answers. Get up-voted to avoid the spam filter!
  • We welcome community answers and upvotes. Every Q&A improves SciChart for everyone

WPF Forums | JavaScript Forums | Android Forums | iOS Forums


Hi, I’m trying to just create a simple WPF MVVM application that binds to the ViewportManager and add series dynamically. The data range (X and Y) will vary and I’d like to zoom to fit after a new series is added. Seems simple, but I cannot get it to work. I’ve tried calling ZoomExtents on a bound DefaultViewportManager as well as InvalidateElement() and InvalidateParentSurface(RangeMode.ZoomToFit) and they all have no affect. I was assuming I was doing something wrong, but if you try the WPF demo/sample application it does the same thing. If you go to 2D Charts -> MVVM Examples -> Manipulate Series MVVM, there is a call to AnimateZoomExtents that doesn’t work either after you add a series. You still have to double click on the graph after clicking the plus button to make it fit the graph. I just want to zoom to fit the data and not use code behind. The functionality is clearly there because if you define <s:ZoomExtentsModifier ExecuteOn="MouseDoubleClick"/> it works perfectly, so how do I force that to happen from my view model? Thank you!

  • Matthias Fritsche
    Two years later ZoomExtends is still broken in the “Manipulate Series Mvvm” Example in exactly the same way described here. This is for SciChart version
  • Andrew Burnett-Thompson
    You are right, an omission on our part. But the workaround suggested below works perfectly to fix it.
  • You must to post comments
Best Answer

Hi Andy,

Can you try this code from ViewModel (assuming you have a ViewportManager in your ViewModel bound to SciChartSurface.ViewportManager)

           _viewportManager.BeginInvoke(() =>
                bool isZoomExtendsAnimated = true;
                var duration = isZoomExtendsAnimated ? TimeSpan.FromMilliseconds(250) : TimeSpan.FromMilliseconds(0);

This should invoke a ZoomExtents on your chart. You can change your data then call this code immediately afterwards and it should theoretically update

Best regards,

  • You must to post comments

Awesome, that worked. Just to verify, simply doing

            _viewportManager.BeginInvoke(() => { _viewportManager.ZoomExtents(); });

works as well if you never want to animate. I’m guessing this has to do with the fact that just doing:


from the view model, attempts to modify the graph on a non UI thread and throws an exception? Will I need to follow this pattern for other calls to the Viewport Manager from my view model?

You might want to update your sample code! I was struggling over this one for a while. If it is the UI thread I would also suggest not eating the error…had I gotten an exception on the direct .ZoomExtents() call I would have been able to figure out the problem pretty quickly.

Again, thank you for your prompt evaluation mode and this certainly helps!

  • Andrew Burnett-Thompson
    No its because when you simply call ZoomExtents after changing your data, WPF might not have propagated the data changes to the View as these are processed by the Dispatcher at DispatcherPriority.DataBind level. Hence the beginInvoke schedules the Viewport to ZoomExtents *after* the data has updated.
  • Andy None
    That makes sense. Thank you!
  • You must to post comments
Showing 2 results
Your Answer

Please first to submit.