gpt4 book ai didi

c# - 用于撤消命令的 UWP TextBox 方法

转载 作者:太空宇宙 更新时间:2023-11-03 12:25:55 24 4
gpt4 key购买 nike

我知道当我按 ctrl+Z 时,文本框默认有撤消命令。我正在创建 UWP 应用程序,我需要通过按 GUI 中的某个按钮来调用此命令。我该怎么做?有没有像 textbox.Undo() 这样的方法?

最佳答案

我认为您不会找到类似 Textbox.Undo() 的任何东西,但您可以将所有更改保存在列表中并在需要时还原文本。

.XAML:

<TextBox Text="{Binding MyText}" />

.CS:

private List<string> _history;

private double _myText;
public double MyText
{
get { return _myText; }
set
{
if(_myText != value) {
_myText = value;
_history.Add(value);
//Notify
}
}
}

private void Undo() {
_myText = _history.LastOrDefault();
//Notify
}

关于c# - 用于撤消命令的 UWP TextBox 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45072258/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com