0
votes

I have a report part in my WPF application which contains some different WPF Pages. I need my report pages to be edittable by user. Each report page contains different Textbox and RichTextBox controls.

Whenever some control's value is changed, if I press ctrl+z and ctrl+y on my keyboard, Undo and Redo will happen only if the control is focused.

Is there any way to extend the functionality of these key combinations to execute Undo and Redo process on all of existing controls in the page without needing to focus on them?

2

2 Answers

0
votes

If you lock your effects under a command pattern you can handle the undo/redo events yourself. As long as the wpf controls involved are bound to the data that is done/undone/redone. That makes it possible.

see Undo/Redo Implementation For Multiple Variables

0
votes

You could use the brute force approach.

Assuming you're using MVVM ( if you're not then you should learn and use it ).

Handle propertchanged in the viewmodel(s) and persist before and after by serialising the entire viewmodel to a collection of viewmodels. One for each state. You then iterate backwards through that collection to go back and forwards to re-apply.

This is relatively easy to implement but the downside is the potential to lose changes between redo.

You could improve on that by adding a bit more sophistication. Retaining a property name, old and new value per propertychange.