相关疑难解决方法(0)

如何让StackPanel的孩子向下填充最大空间?

我只想在左边流动文本,在右边有一个帮助框.

帮助框应该一直延伸到底部.

如果您取出下面的外部StackPanel,它的效果很好.

但由于布局的原因(我正在动态插入UserControl),我需要包装StackPanel.

如何让GroupBox扩展到StackPanel的底部,你可以看到我已经尝试过:

  • VerticalAlignment = "弹力"
  • VerticalContentAlignment = "弹力"
  • 身高="自动"

XAML:

<Window x:Class="TestDynamic033.Test3"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Test3" Height="300" Width="600">
    <StackPanel 
        VerticalAlignment="Stretch" 
        Height="Auto">

        <DockPanel 
            HorizontalAlignment="Stretch" 
            VerticalAlignment="Stretch" 
            Height="Auto" 
            Margin="10">

            <GroupBox 
                DockPanel.Dock="Right" 
                Header="Help" 
                Width="100" 
                Background="Beige" 
                VerticalAlignment="Stretch" 
                VerticalContentAlignment="Stretch" 
                Height="Auto">
                <TextBlock Text="This is the help that is available on the news screen." TextWrapping="Wrap" />
            </GroupBox>

            <StackPanel DockPanel.Dock="Left" Margin="10" Width="Auto" HorizontalAlignment="Stretch">
                <TextBlock Text="Here is the news that should wrap around." TextWrapping="Wrap"/>
            </StackPanel>

        </DockPanel>
    </StackPanel>
</Window>
Run Code Online (Sandbox Code Playgroud)

回答:

谢谢Mark,使用DockPanel而不是StackPanel清理它.一般来说,我发现自己现在越来越多地使用DockPanel进行WPF布局,这里是固定的XAML:

<Window x:Class="TestDynamic033.Test3"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Test3" Height="300" Width="600" MinWidth="500" …
Run Code Online (Sandbox Code Playgroud)

wpf xaml dockpanel autoresize autolayout

338
推荐指数
4
解决办法
33万
查看次数

标签 统计

autolayout ×1

autoresize ×1

dockpanel ×1

wpf ×1

xaml ×1