WPF - TabControl Problem
I have a TabControl with three Tab Items. When the user clicks on the second TabItem, I want to take him/her back to the first TabItem and set a certain TextBox to have the keyboard focus, if a certain circumstance is met. I'm having a heck of a time making this happen. I can easily set the current TabItem to the first one, but no matter what I try, I cannot get the keyboard focus to the TextBox I want. I've tried calling the Focus method on the TextBox and I've tried using the Keyboard.Focus() method. Nothing seems t开发者_如何学Pythono work.
Use the follwing code:
// Select here your tab
// ...
Dispatcher.BeginInvoke(new Action(delegate {
yourTextBox.Focus();
}), System.Windows.Threading.DispatcherPriority.ContextIdle, null);
精彩评论