How to automatically size TabControl in a DockPanel - WPF

15,531

Just set the HorizontalAlignment and VerticalAlignment properties of your TabControl to "Stretch":

<DockPanel>
    <StackPanel DockPanel.Dock="Bottom" Orientation="Horizontal" Margin="5">
        <TextBlock Text="Hello" />
        <TextBlock Text="World" />
    </StackPanel>

    <TabControl HorizontalAlignment="Stretch" 
                VerticalAlignment="Stretch">
        <TabItem Header="Small">
            <TextBlock Text="Just Some Small Stuff" />
        </TabItem>
        <TabItem Header="Bigger">
            <StackPanel>
                <TextBlock Text="One line" />
                <TextBlock Text="The next line" />
            </StackPanel>
        </TabItem>

    </TabControl>
</DockPanel>
Share:
15,531
CrazyDart
Author by

CrazyDart

Updated on July 10, 2022

Comments

  • CrazyDart
    CrazyDart almost 2 years

    I have a simple WPF Forms app. I have a DockPanel as my root panel. The first child is a StackPanel that has some controls in it, then the second control is a TabControl. What I want, and the panel types can change all they want is for the TabControl to maintain the fill size of the window except for what the first StackPanel consumes. However no matter what I try the TabControl seems to change its size depending on whats inside it, not whats it is inside of.

    <Window>
        <DockPanel>
            <StackPanel> </StackPanel>
            <TabControl> </TabControl>
        </DockPanel>
    </Window>
    
  • CrazyDart
    CrazyDart over 13 years
    Well, how about that. That works great. Had I fiddled around long enough I would have figured it out, but truth be told I am more of a web guy than a WPF/XAML guy! Thanks!
  • Wonko the Sane
    Wonko the Sane over 13 years
    No problem. I'm more of a WPF/XAML guy. ;)