填写StackPanel中的所有可用空间

dem*_*mas 17 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>
Run Code Online (Sandbox Code Playgroud)

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

Phi*_*hil 41

如果您的意思是填充所有水平和垂直空间,您应该使用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>
Run Code Online (Sandbox Code Playgroud)

  • Windows Store应用程序上没有更多的dockPanel :( (4认同)
  • @Teomanshipahi 您可以尝试使用带有“Rowdefinitions”的“Grid” (2认同)