22
<Window x:Class="DataBinding_01.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <StackPanel Height="Auto" Name="stackPanel1" Width="Auto">        
        <TextBox Height="23" Name="textBox1" Width="Auto" />
        <TextBox Height="23" Name="textBox2" Width="Auto" />
        <Button Content="Button" Name="button1" Width="Auto" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" />
    </StackPanel>
</Window>

I want the Button fill all available space on the StackPanel. How can I do it?

ceth
  • 44,198
  • 62
  • 180
  • 289
  • 1
    possible duplicate of [How to get StackPanel's children to fill maximum space downward?](http://stackoverflow.com/questions/569095/how-to-get-stackpanels-children-to-fill-maximum-space-downward) – H.B. Feb 19 '12 at 01:23
  • 1
    (Seriously, that's the very first question in the related section, you should see that even *before* posting; third suggestion would work as well (along with probably even more)) – H.B. Feb 19 '12 at 01:24
  • I read that question. It sounds like it describes a situation where you want a horizontally oriented stackpanel to fill all vertical space. Not the same thing. – Kyle Delaney Apr 10 '17 at 14:16

1 Answers1

47

If you mean fill all horizontal and vertical space you should use a DockPanel.

    <DockPanel Height="Auto" Name="stackPanel1" Width="Auto" LastChildFill="True">
        <TextBox DockPanel.Dock="Top" Height="23" Name="textBox1" Width="Auto" />
        <TextBox DockPanel.Dock="Top" Height="23" Name="textBox2" Width="Auto" />
        <Button Content="Button" Name="button1" Width="Auto" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" />
    </DockPanel>
Phil
  • 42,255
  • 9
  • 100
  • 100