Pre loader

X-Axis zoom using Command in WPF

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



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.


  • You must 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; }
               _viewportManager = value;

       public void Foo()
             // All things you can do from the ViewModel with a ViewportManager
             // We don't recommend doing them all at once! :)

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);

Best regards,

  • Anil Prasad
    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
  • Andrew Burnett-Thompson
    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.
  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.