tags:

views:

1475

answers:

1

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.

A: 

<ScrollViewer>
    <TabControl
     TabStripPlacement="Left"
     x:Name="Tab"
    >
    </TabControl>
</ScrollViewer>

gets you the scrollbar which will be enabled when needed.

Donnelle
Thanks Donnelle. It turned out that the scrollviewer is not what i want because it scrolled everything on my control out of view NOT just the left column where i stacked the tab icons. I'm still thinking of a way to scroll just the left column (ie; grid column) on my control.
So are you looking to have scrolling functionality like Firefox's tabs, except that you want the scrollbar to advance to the next row of tabs, rather than scroll one tab at a time horizontally?
Dave