Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Silverlight TabControl - Finding and selecting a TabItem from a given Control in the TabItem

I am building a LOB application that has a main section and a TabControl with various TabItems in it. On hitting save the idea is that any fields in error are highlighted and the first field in error gets the focus.

If the first, and only, field in error is on an Unselected tab the tab should then become selected and the field in error should become highlighted and have focus. But I can not get this to work.

What appears to be happening is that the Unselected tab is not in the visual tree so you can't navigate back to the owning TabItem and make it the currently selected TabItem in the TabControl.

Has anyone got an idea on how this can be done\achieved?

like image 958
David Gray Wright Avatar asked May 03 '10 00:05

David Gray Wright


1 Answers

To load the TabItem:

tabControl.SelectedItem = tabItemOfInterest;
tabControl.UpdateLayout();

This causes the tabItemOfInterest to load alongwith all the contained controls within the TabItem.

The below line alone does not loads the tabItemOfInterest:

tabControl.SelectedItem = tabItemOfInterest;

I would, however, be very interested in the approach David adopted to get to the erroneous control.

like image 118
DiligentKarma Avatar answered Oct 13 '22 02:10

DiligentKarma