CrazyDart
CrazyDart

Reputation: 3801

How to automatically size TabControl in a DockPanel - WPF

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>

Upvotes: 2

Views: 16081

Answers (1)

Wonko the Sane
Wonko the Sane

Reputation: 10823

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>

Upvotes: 7

Related Questions