How to automatically expand a tab control as items are added to it without creating a scrollbar?

I am using a WPF user control (tab control) to dynamically add tabs 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 connect all the elements of my tab to the left column:

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

How do I get a tab control to automatically increase (i.e. stretch) its height to show all tabs when I add them? At the moment, I have to manually increase the height of the display window to see all the tabs. Your ideas / tips are welcome.

PS: , ( ), , , .

+3
1

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

, , .

+1

Source: https://habr.com/ru/post/1698788/


All Articles