views:

2203

answers:

1

Hi

I have different tabItems in a TabControl and each tabItem has some input fields.

I am moving between the tabItems programmatically (like a wizard to move from the first to the next)

I am using this code inside the "Next" button

tabItem2.isSelected = true;

my problem that when I move between the tabItems by clicking on them, the focus (keyboard focus) will move to the first textbox input.

But programmatically with the previous code, the focus won't move to the first input textbox item inside the tabItem.

Any idea?

+1  A: 

If you're forcing the IsSelected property, I'd also give the first TextBox a name and set the focus after you set the selected tab.

If you're building your UI dynamically, this won't work, but you can create a utility method which searches the logical tree (or the visual tree if you're using presenters/view-models) for the first input control and then set the focus.

micahtan
Or instead of calling textbox.Focus(), you could do what WPF does internally within its TabItem.OnPreviewGotKeyboardFocus method. That is, call tabitem.MoveFocus().
HappyNomad