Undo Redo in UWP DOCX Editor
18 Aug 20262 minutes to read
SfRichTextBoxAdv preserves the history of every editing operation performed on its document, so any action can be undone with ease. Undone actions are kept in a separate stack, enabling you to redo them.
NOTE
By default, the undo and redo stacks each preserve up to 500 actions.
UI command to perform undo and redo operations
The following code example demonstrates how to bind commands for performing undo and redo operations.
<!-- Binds button to the UndoCommand -->
<Button Content="Undo" Command="{Binding ElementName=richTextBoxAdv, Path=UndoCommand, Mode=TwoWay}" />
<!-- Binds button to the RedoCommand -->
<Button Content="Redo" Command="{Binding ElementName=richTextBoxAdv, Path=RedoCommand, Mode=TwoWay}" />The following code example demonstrates how to execute the undo and redo commands programmatically.
// Executes the UndoCommand on SfRichTextBoxAdv.
richTextBoxAdv.UndoCommand.Execute(null);
// Executes the RedoCommand on SfRichTextBoxAdv.
richTextBoxAdv.RedoCommand.Execute(null);NOTE
You can also use the standard keyboard shortcuts Ctrl+Z and Ctrl+Y to perform undo/redo.
Enable or disable undo and redo
Disable undo for all editing actions
Undo is enabled by default in SfRichTextBoxAdv. To disable it, set the IsUndoEnabled property of the EditorSettings class to false.
The following code example demonstrates how to disable undo on SfRichTextBoxAdv.
<Syncfusion:SfRichTextBoxAdv x:Name="richTextBoxAdv">
<Syncfusion:SfRichTextBoxAdv.EditorSettings>
<Syncfusion:EditorSettings IsUndoEnabled="False"/>
</Syncfusion:SfRichTextBoxAdv.EditorSettings>
</Syncfusion:SfRichTextBoxAdv>// Initializes the SfRichTextBoxAdv control with undo disabled.
SfRichTextBoxAdv richTextBoxAdv = new SfRichTextBoxAdv();
richTextBoxAdv.EditorSettings.IsUndoEnabled = false;Disable undo for style modification actions
SfRichTextBoxAdv enables undo for all editing operations by default. To disable undo only for modifications to an existing style, set the CanUndoStyle property of the EditorSettings class to false.
The following code example demonstrates how to disable undo for style modifications on SfRichTextBoxAdv.
<Syncfusion:SfRichTextBoxAdv x:Name="richTextBoxAdv">
<Syncfusion:SfRichTextBoxAdv.EditorSettings>
<Syncfusion:EditorSettings CanUndoStyle="False"/>
</Syncfusion:SfRichTextBoxAdv.EditorSettings>
</Syncfusion:SfRichTextBoxAdv>// Initializes the SfRichTextBoxAdv control with undo for style modifications disabled.
SfRichTextBoxAdv richTextBoxAdv = new SfRichTextBoxAdv();
richTextBoxAdv.EditorSettings.CanUndoStyle = false;NOTE
The
IsUndoEnabledandCanUndoStyleproperties are available starting from Syncfusion UWP RichTextBox v18.1.0.X.