Undo/Redo commands not working when text is added programmatically

Dear Support,

I am using the SfRichTextBoxAdv control in an UWP app. When content is being added programmatically like this...

SpanAdv span = new SpanAdv { Text = "Here is some text." };
ParagraphAdv paragraph = new ParagraphAdv();
paragraph.Inlines.Add(span);
RichTextBox.Document.Sections[0].Blocks.Add(paragraph);

... I have found that the Undo/Redo commands don't work, even though I have Undo enabled...

RichTextBox.EditorSettings.IsUndoEnabled = true;

I've tried calling the command directly, for example...

RichTextBox.UndoCommand.Execute(null);

... and by binding the command to a button, and then clicking the button programmatically...

<Button x:Name="UndoButton"
              Content="Undo"
              Command="{Binding ElementName=Document,
              Path=UndoCommand, Mode=TwoWay}" />

ButtonAutomationPeer peer = new ButtonAutomationPeer(UndoButton);
IInvokeProvider invokeProv = peer.GetPattern(PatternInterface.Invoke) as IInvokeProvider;
invokeProv.Invoke();

... but neither approach undoes edit operations.

However, Undo/Redo works when content gets typed into the editor, but this is of no use to me.

Is it possible to use these commands when text is being added programmatically, or is there maybe a setting I've missed?

I am using Essential Studio Version 18.1.0.42.

Thanks in advance!

3 Replies

PS Premkumar Sundaramoorthy Syncfusion Team April 27, 2020 05:32 AM UTC

Hi Trumpledor,

Thanks for contacting Syncfusion support.

We are not providing support for Undo/Redo for code level changes made directly in DocumentAdv instance. And there is no plan to implement this in future. Instead of that you can use our selection’s insert methods. Please refer the below code snippet.
 
richTextBoxAdv.Selection.InsertText("Hello"); 

Please let us know if you have any other questions.

Regards,
Premkumar
 



TR Trumpledor April 27, 2020 01:58 PM UTC

Okay, thanks. Much appreciated!


PS Premkumar Sundaramoorthy Syncfusion Team April 28, 2020 03:49 AM UTC

Hi Trumpledor,

Thanks for your update.

Please let us know if you need any further assistance.

Regards,
Premkumar


Loader.
Up arrow icon