Hi,
There are some methods exposed in the API, ZoomBy and ZoomExtent which can programmatically be called from the code behind.
I am binding the series using IRenderableSeriesViewModel in MVVM pattern. Can we zoom the sciChart surface on a button click in ModelView?
Appreciating your help on this.
Thanks
- Anil Prasad asked 8 years ago
- You must login to post comments
Hi Anil
You can control the SciChartSurface directly from the ViewModel by following this technique:
ViewportManager – Full Control over Axis Ranges and Viewport
You can call the following functions on a ViewportManager from a ViewModel. Use these to have direct control over the SciChartSurface in absence of a SciChartSurface instance itself.
Assuming you have bound a ViewportManager as per Declaring a Binding to a ViewportManager in MVVM
public class MyViewModel : INotifyPropertyChanged
{
// Viewmodel
private DefaultViewportManager _viewportManager = new DefaultViewportManager();
public IViewportManager ViewportManager
{
get { return _viewportManager; }
set
{
_viewportManager = value;
OnPropertyChanged("ViewportManager");
}
}
public void Foo()
{
// All things you can do from the ViewModel with a ViewportManager
// We don't recommend doing them all at once! :)
_viewportManager.ZoomExtents();
_viewportManager.AnimateZoomExtents(TimeSpan.FromMilliseconds(500));
_viewportManager.ZoomExtentsY();
_viewportManager.AnimateZoomExtentsY(TimeSpan.FromMilliseconds(500));
_viewportManager.ZoomExtentsX();
_viewportManager.AnimateZoomExtentsX(TimeSpan.FromMilliseconds(500));
}
}
Note that there may be a short delay between setting data and being able to zoom to extents on it. This is because of the delay in binding in WPF itself.
In order to work around this delay, we recommend a technique like this:
// Invoke AnimateZoomExtents after binding engine has stabilised
_viewportManager.BeginInvoke(() =>
{
var duration = TimeSpan.FromMilliseconds(250);
_viewportManager.AnimateZoomExtents(duration);
});
Best regards,
Andrew
- Andrew Burnett-Thompson answered 8 years ago
-
Thanks Andrew, the zoomextent works perfectly. But I could not see the ZoomBy method in the viewportmanager interface. What I have written in the code behind file is: // TODO: Need to implement zoom using MVVM private void BtnZoomIn_Click(object sender, RoutedEventArgs e) { TemperatureGraph.ChartModifier.XAxis.ZoomBy(-0.1, -0.1); } I want to perform the same in the ViewModel Class. Please help! Regards, Anil
-
ZoomBy is unfortunately an API on the Axis itself. It is not available on the ViewportManager. If you want to call this function in an MVVM fashion you will need to use WPF Behaviors or think of a way to call a View methods from the ViewModel. http://stackoverflow.com/questions/19847860/how-to-call-method-in-window-xaml-cs-from-viewmodel-cs-without-introducing
- You must login to post comments
Please login first to submit.