填写StackPanel中的所有可用空间

时间:2012-02-18 14:13:50

标签: wpf xaml

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

我希望Button填充StackPanel上的所有可用空间。我该怎么办?

1 个答案:

答案 0 :(得分:40)

如果您的意思是填充所有水平和垂直空间,则应使用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>