UWP/WinRT: How to enable undo hooks on a TextBox?

怎甘沉沦 提交于 2019-12-23 02:53:43

问题


The TextBox class already supports undo, as it is present and functional in the context menu.

I would like to implement undo/redo buttons as found in every common document editor such as Microsoft Word. They would be disabled when they have no action to take, and when there is an undo/redo stack to move through, pressing the buttons would cause the TextBox's contents to undo and redo.

Looking at the TextBox API, there doesn't seem to be any mention of how to hook into the undo data. The only discussion is a mention that undo is present on the context menu.

How are undo/redo hooks implemented on a TextBox?

If it makes a difference, I'm currently coding in C++/CX.


回答1:


You definitely can record the history manually by TextChanged event. Undo command is used to display the previously input. Hook into the control seems not possible.

Handle the ContextMenuOpening event from TextBox and you can modify the Popup by your own commands, for example your own undo/redo history.

A good sample: https://code.msdn.microsoft.com/windowsapps/Context-menu-sample-40840351 also works fine with UWP.



来源:https://stackoverflow.com/questions/31886766/uwp-winrt-how-to-enable-undo-hooks-on-a-textbox

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!