Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Undo/Redo in WPF? [duplicate]

Tags:

c#

wpf

undo-redo

Does WPF provide a framework to handle undo/redo? If not, what's a common way to do it?

like image 439
djcouchycouch Avatar asked Apr 23 '09 00:04

djcouchycouch


2 Answers

I've implemented undo / redo for a WPF application and ended up publishing my undo / redo code to http://muf.codeplex.com/.

You can also get it via NuGet. Just look for "MUF" or "Monitored Undo Framework". It includes support for Silverlight 4.0, as well as .NET 3.5, 4.0, and WP7.

Comments and questions are welcome on the codeplex site ( http://muf.codeplex.com/ ). You'll also find complete documentation and sample apps there.

like image 144
NathanAW Avatar answered Nov 12 '22 12:11

NathanAW


As of .NET 3.0, this is the way to get the localized Name, Key Gesture and some functionality quick:

<MenuItem Command="ApplicationCommands.Redo"/>
<MenuItem Command="ApplicationCommands.Undo"/>

However, without further action on your part each TextBox maintains it's own Undo/Redo list and the Redo/Undo Command only affects the item currently having the focus. There must be some way to switch to a single, window/application wide undo/redo list, but I have just started to search and mostly I found "How to code it yourself" articles.

But a technique using attached properties, described here, seems very promising and could be easy/stable.

like image 25
Christopher Avatar answered Nov 12 '22 12:11

Christopher