开发者

WPF C# undo redo

开发者 https://www.devze.com 2023-01-08 01:24 出处:网络
I have to do UNDO REDO implementation in WPF for NumericEditors like textbox. I am using infragistics xamNumericEditor control. How can I start? Which method is best to follow. I have searched net.开发

I have to do UNDO REDO implementation in WPF for NumericEditors like textbox. I am using infragistics xamNumericEditor control. How can I start? Which method is best to follow. I have searched net.开发者_开发百科 Found that memento and command patterns are there. Which one is best?


This article covers 3 different ways to implement the Undo/Redo pattern, including using Memento and Command Patterns.


You may find the Monitored Undo Framework to be useful. http://muf.codeplex.com/

It doesn't use the "top down" command pattern, but instead monitors for changes as they happen and allows you to put a delegate on the undo stack that will reverse the change. You can find more info and documentaiton on the codeplex site.


You may want to consider whether the UI level is the right place to implement Undo/Redo. This depends on whether you're tracking more significant changes to your data or merely short-term editing in the UI. In the latter case, you often don't care if you lose Undo state once you move on to another control.

If you're purely looking for local Undo/Redo in the context of editing (such as undoing a Cut or Delete operation), then you can get this for free on the standard text box control (and possibly the Infragistics control) using ApplicationCommands.Undo and ApplicationCommands.Redo. Try attaching these to a MenuItem or Button and experiment with how they work.

0

精彩评论

暂无评论...
验证码 换一张
取 消