Undo Redo in UWP RichTextBox (SfRichTextBoxAdv)

10 May 20212 minutes to read

The SfRichTextBoxAdv provides history preservation support, which means each editing operation performed against its document content will be preserved in history. You can easily undo any editing action with ease. The undone actions will also be preserved in a separate stack enabling you to redo the action again.

NOTE

Currently, the number of actions that can be preserved in both undo and redo stacks is limited to 500.

UI Command to perform undo/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}" />

NOTE

In order to perform undo/redo, the standard keyboard shortcuts such as CTRL + Z, CTRL + Y can also be used.

Enable/Disable Undo Redo

Disable Undo for all the editing actions

In SfRichTextBoxAdv, the Undo functionality is enabled by default. You can disable it by using the IsUndoEnabled property of the EditorSettings class.

The following code example demonstrates how to disable the Undo functionality in SfRichTextBoxAdv.

<Syncfusion:SfRichTextBoxAdv x:Name="richTextBoxAdv">
	<Syncfusion:SfRichTextBoxAdv.EditorSettings>
		<Syncfusion:EditorSettings IsUndoEnabled="False"/>
	</Syncfusion:SfRichTextBoxAdv.EditorSettings>
</Syncfusion:SfRichTextBoxAdv>
// Defines the SfRichTextBoxAdv control with undo operation disabled.
SfRichTextBoxAdv richTextBoxAdv = new SfRichTextBoxAdv();
richTextBoxAdv.EditorSettings.IsUndoEnabled = false;

NOTE

This API is supported starting from release version v18.1.0.X.

Disable Undo for style modification actions

In SfRichTextBoxAdv, the Undo functionality is enabled by default for all the editing operations. If you want to disable the Undo functionality for modifying an existing style alone. You can disable it by using the CanUndoStyle property of the EditorSettings class.

The following code example demonstrates how to disable the Undo support for modifying an existing style in SfRichTextBoxAdv.

<Syncfusion:SfRichTextBoxAdv x:Name="richTextBoxAdv">
	<Syncfusion:SfRichTextBoxAdv.EditorSettings>
		<Syncfusion:EditorSettings CanUndoStyle="False"/>
	</Syncfusion:SfRichTextBoxAdv.EditorSettings>
</Syncfusion:SfRichTextBoxAdv>
// Defines the SfRichTextBoxAdv control with document style undo operation disabled.
SfRichTextBoxAdv richTextBoxAdv = new SfRichTextBoxAdv();
richTextBoxAdv.EditorSettings.CanUndoStyle = false;

NOTE

This API is supported starting from release version v18.1.0.X.