Hosea146
Hosea146

Reputation: 7722

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 to work.

Upvotes: 0

Views: 572

Answers (1)

HCL
HCL

Reputation: 36795

Use the follwing code:

// Select here your tab
// ...
Dispatcher.BeginInvoke(new Action(delegate {       
    yourTextBox.Focus();        
 }), System.Windows.Threading.DispatcherPriority.ContextIdle, null);

Upvotes: 1

Related Questions