WPF: How to programmatically remove focus from a TextBox

前端 未结 9 1787
感动是毒
感动是毒 2020-11-30 23:04

I want to add a simple (at least I thought it was) behaviour to my WPF TextBox.

When the user presses Escape I want the TextBox he is editi

9条回答
  •  悲哀的现实
    2020-11-30 23:47

    For me, it's quite tricky, especially when using with LostFocus binding. However, my workaround is to add an empty label and focus on it.

    ...

    OnKeyDown(object sender, RoutedEventArgs e)
    {
      //if is Esc
      ResetFocusArea.Focus();
    }
    

提交回复
热议问题