开发者

How to automatically size TabControl in a DockPanel - WPF

开发者 https://www.devze.com 2023-01-19 13:19 出处:网络
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, an

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>


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>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号