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!
- Andy None asked 8 years ago
- last edited 8 years ago
-
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 5.2.1.11757.
-
You are right, an omission on our part. But the workaround suggested below works perfectly to fix it.
- You must login to post comments
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);
_viewportManager.AnimateZoomExtents(duration);
});
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,
Andrew
- Andrew Burnett-Thompson answered 8 years ago
- You must login 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:
_viewportManager.ZoomExtents();
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 help..in evaluation mode and this certainly helps!
- Andy None answered 8 years ago
-
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.
-
That makes sense. Thank you!
- You must login to post comments
Please login first to submit.