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

0
0

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

Version
4.2.2.9777
  • You must to post comments
0
0

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

  • 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. http://stackoverflow.com/questions/19847860/how-to-call-method-in-window-xaml-cs-from-viewmodel-cs-without-introducing
  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.