SciChart WPF 2D Charts > ChartModifier API > Zooming And Panning > ZoomHistoryManager (Undo / Redo of Zoom)
ZoomHistoryManager (Undo / Redo of Zoom)

 SciChart features the ability to Undo and Redo zoom operations, with a customisable stack depth.

 

Enabling Undo/Redo of Zoom

To enable Undo Redo of zoom, simply set the SciChartSurface.ZoomHistoryManager property.

XAML
Enabling Undo/Redo of Zoom
Copy Code
<Grid>
   <Grid.Resources>
      <s:ZoomHistoryManager x:Key="ZoomHistoryManager" x:Shared="False" HistoryDepth="10"/>
   </Grid.Resources>

   <!-- Set the ZoomHistoryManager to a non-shared StaticResource, or,
   <!-- bind to an instance in your ViewModel -->
   <!-- to enable controlling of Zoom Undo Redo via the ViewModel -->
   <s:SciChartSurface Name="SciChart"
             ZoomHistoryManager="{StaticResource ZoomHistoryManager}">

      <!-- XAxis, YAxis, RenderableSeries omitted for brevity -->
  
   </s:SciChartSurface>
</Grid>
Code
Enabling Undo/Redo of Zoom
Copy Code
var sciChartSurface = new SciChartSurface();
sciChartSurface.ZoomHistoryManager = new ZoomHistoryManager()
{
   HistoryDepth = 10,
   AnimationDuration = TimeSpan.FromMilliseconds(500)
};

Programmatically Undo a Zoom

You can undo a zoom by executing the ZoomHistoryManager.UndoCommand. You can also bind to this command in your UI e.g. via Button.Command binding.

Programmatically Redo a Zoom

You can redo a zoom by executing the ZoomHistoryManager.RedoCommand. You can also bind to this command in your UI e.g. via Button.Command binding.

Setting the Zoom History Stack-Depth

You can set the zoom-history stack depth via the ZoomHistoryManager.HistoryDepth property. By default this is set to 10.

Enabling/Disabling Animation on Undo/Redo of zoom

You can set the animation duration via the ZoomHistoryManager.AnimationDuration property. By default this is set to 500ms. If you set this property to TimeSpan.Zero, animation will be disabled for the ZoomHistoryManager.

Programmatically Clearing the Zoom History Stack

You can clear the zoom-history stack at any time by calling the ZoomHistoryManager.ClearHistory() method.

  

 

See Also