C# 在 WPF 中撤消/重做?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/779758/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Undo/Redo in WPF?
提问by djcouchycouch
Possible Duplicate:
data structure used to implement UNDO and REDO option
可能的重复:
用于实现 UNDO 和 REDO 选项的数据结构
Does WPF provide a framework to handle undo/redo? If not, what's a common way to do it?
WPF 是否提供了处理撤消/重做的框架?如果不是,那么常见的做法是什么?
Thanks!
谢谢!
采纳答案by NathanAW
I've implemented undo / redo for a WPF application and ended up publishing my undo / redo code to http://muf.codeplex.com/.
我已经为 WPF 应用程序实现了撤消/重做,并最终将我的撤消/重做代码发布到了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.
您也可以通过 NuGet 获取它。只需寻找“MUF”或“Monitored Undo Framework”。它包括对 Silverlight 4.0 以及 .NET 3.5、4.0 和 WP7 的支持。
Comments and questions are welcome on the codeplex site ( http://muf.codeplex.com/). You'll also find complete documentation and sample apps there.
欢迎在 codeplex 站点 ( http://muf.codeplex.com/)上发表评论和提问。您还可以在那里找到完整的文档和示例应用程序。
回答by Christopher
As of .NET 3.0, this is the way to get the localized Name, Key Gesture and some functionality quick:
从 .NET 3.0 开始,这是快速获取本地化名称、按键手势和一些功能的方法:
<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.
但是,如果您没有采取进一步的行动,每个 TextBox 都会维护其自己的撤消/重做列表,而重做/撤消命令仅影响当前具有焦点的项目。必须有某种方法可以切换到单个的、窗口/应用程序范围的撤消/重做列表,但我刚刚开始搜索,并且大部分时间我都找到了“如何自己编写代码”的文章。
But a technique using attached properties, described here, seems very promising and could be easy/stable.
但是这里描述的使用附加属性的技术似乎非常有前途并且可能很容易/稳定。