Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

select tabItem programmatically in WPF

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?

like image 308
Ghassan Karwchan Avatar asked Jun 01 '09 23:06

Ghassan Karwchan


1 Answers

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.

like image 141
micahtan Avatar answered Oct 16 '22 01:10

micahtan