UWP/WinRT:如何在 TextBox 上启用撤消挂钩? [英] UWP/WinRT: How to enable undo hooks on a TextBox?

查看:30
本文介绍了UWP/WinRT:如何在 TextBox 上启用撤消挂钩?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

TextBox 类已经支持撤消,因为它在上下文菜单中存在并且起作用.

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

我想实现在每个常见的文档编辑器(如 Microsoft Word)中都能找到的撤消/重做按钮.当它们没有动作时,它们将被禁用,并且当有一个撤消/重做堆栈要移动时,按下按钮会导致 TextBox 的内容撤消和重做.

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.

查看 TextBoxAPI,似乎没有提到如何挂钩撤消数据.唯一的讨论是提到上下文菜单中存在撤消.

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.

如何在 TextBox 上实现撤消/重做挂钩?

How are undo/redo hooks implemented on a TextBox?

如果有什么不同,我目前正在使用 C++/CX 进行编码.

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

推荐答案

您绝对可以通过 TextChanged 事件手动记录历史记录.撤消命令用于显示之前的输入.似乎无法连接到控件.

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.

处理来自文本框的 ContextMenuOpening 事件,您可以通过您自己的命令修改弹出窗口,例如您自己的撤消/重做历史记录.

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

一个很好的示例:https://code.msdn.microsoft.com/windowsapps/Context-menu-sample-40840351 也适用于 UWP.

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

这篇关于UWP/WinRT:如何在 TextBox 上启用撤消挂钩?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆