How to automatically extend the tab control as items are added to it without creating a scroll bar?

Posted by MICHELINE on Stack Overflow See other posts from Stack Overflow or by MICHELINE
Published on 2008-10-28T05:59:17Z Indexed on 2010/05/28 15:01 UTC
Read the original article Hit count: 161

Filed under:
|

I am using a WPF user control (tab control) to add tab items dynamically in the simplified code below:

....
foreach (string id in ids)
{
    TabControl.Items.Add(CreateTabItem(id));
}

private TabItem CreateTabItem(string name)
{
    StackPanel txtBlock = new TextBlock();
    txtblock.Text = name;
    txtBlock.HorizontalAlignment = Horizontalalignment.Center;
    panel.Children.Add(txtBlock);

    TabItem item = new TabItem();
    item.Header = panel;

    <SomeControl> control = new <SomeControl>();
    item.Content = control;
    return item;
 }

In the xaml file I specified the following to stack all my tab items to the left column:

MinWidth="100" MinHeight="300" TabStripPlacement="Left"

How do I make my tab control automatically extending (ie. stretching) its height to show all the tab items as I add them in? For now, I have to manually extend the height of the display window to see all the tab items. Your insights/tips are greatly appreciated.

PS: if you know how to make the vertical scroll bar appears (without adding scroll bar to my control) as soon as the tab items exceed the window height, I can settle for that if there are no answers for my original intent.

© Stack Overflow or respective owner

Related posts about wpf

Related posts about tabcontrol