Hey. I have a tabcontrol that is bound to an observable collection.
I've tried doing
var tabitem = (TabItem)this.SingleOrDefault(ti => ti.Name == tabname);
tabitem.Focus();
((UserControl)tabitem.Content).Focus();
And it does seem like it focuses on the tabit开发者_StackOverflow社区em, but only on a btn in the header of the tabitem, not on the content. the tabitem content is another usercontrol.
How can I change the focus to the content, so that the tab actually is selected and not just the tabheader
I know of tabcontrol.selecteditem, but Iøm not really sure how I would implement this as the observablecollection is actually a class that i've called ObservableTabCollection, that just implements observable collection.
Bind TabControl.SelectedItem
two-way to a specific TabItem from your ObservableTabCollection. Then you can set the binding to any item you pull out of your ObservableTabCollection to make that tab the shown tab.
My solution became to simply create a method on the observabletabcollection that would associate the tabcontrol with the observabletabcollection
public TabControl AssociatedTabControl;
internal void BindToTabControl(TabControl TabCtrl)
{
AssociatedTabControl = TabCtrl;
}
and then inside a method call
if (AssociatedTabControl != null) AssociatedTabControl.SelectedItem = tabitem;
精彩评论