【问题标题】:Moving focus in TextChanged results in "Cannot Undo or Redo while undo unit is open." when doing Ctrl-Z在 TextChanged 中移动焦点会导致“撤消单元打开时无法撤消或重做”。做 Ctrl-Z 时
【发布时间】: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


    【解决方案1】:

    这可能对其他人有用。

    我在网上搜索了几次并遇到了此消息,但没有与我的情况相似/没有解决方案,但我确实在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();
    }
    

    【讨论】:

      猜你喜欢
      • 2015-11-25
      • 2017-02-09
      • 1970-01-01
      • 1970-01-01
      • 2010-12-06
      • 1970-01-01
      • 1970-01-01
      • 2011-11-25
      • 2011-08-04
      相关资源
      最近更新 更多