【发布时间】:2015-04-08 15:08:42
【问题描述】:
我有 TextBox1 & TextBox2, TB1 和 OnTextChanged-handler,我将焦点移到 TB2。
现在,如果我再次手动聚焦 TB1 并按 Ctrl-Z,我会收到消息 "Cannot Undo or Redo while undo unit is open."。任何人? :)
【问题讨论】:
标签: wpf focus undo textchanged
我有 TextBox1 & TextBox2, TB1 和 OnTextChanged-handler,我将焦点移到 TB2。
现在,如果我再次手动聚焦 TB1 并按 Ctrl-Z,我会收到消息 "Cannot Undo or Redo while undo unit is open."。任何人? :)
【问题讨论】:
标签: wpf focus undo textchanged
这可能对其他人有用。
我在网上搜索了几次并遇到了此消息,但没有与我的情况相似/没有解决方案,但我确实在MSDN for the TextBox.Undo() method 看到了以下内容:
"The Undo method does not work with the KeyPress or TextChanged events."
我现在尝试的是使用 BeginInvoke 进行聚焦异步。
private void TB1_TextChanged(object sender, TextChangedEventArgs e)
{
Dispatcher.BeginInvoke((Action)FocusTB2);
}
public void FocusTB2()
{
TB2.Focus();
}
【讨论】: