Is there any way to have to tabcontrol take the size of the largest tab item (well, actually, the tabitem\'s content)?
Since the tabcontrol has no specific size assi
This worked for me in conjunction with Grid.IsSharedSizeScope approach shown above.
Note that SetCurrentValue is used instead of just setting the SelectedIndex property - this way we keep possible existing bindings:
private void TabControl_OnLoaded(object sender, RoutedEventArgs e)
{
//NOTE: loop through tab items to force measurement and size the tab control to the largest tab
TabControl tabControl = (TabControl)sender;
// backup selection
int indexItemLast = tabControl.SelectedIndex;
int itemCount = tabControl.Items.Count;
for (
int indexItem = (itemCount - 1);
indexItem >= 0;
indexItem--)
{
tabControl.SetCurrentValue(Selector.SelectedIndexProperty, indexItem);
tabControl.UpdateLayout();
}
// restore selection
tabControl.SetCurrentValue(Selector.SelectedIndexProperty, indexItemLast);
}