我只是想流动在左边的文本,以及一个帮助框权利。

帮助框应当延伸到底。

如果你采取出来的外在这种情况下,它下面伟大工程。

但这不是因为布局(我插入UserControls动态),我需要有包装在这种情况下.

我怎么得到该组框延长下到底部在这种情况下,你可以看到,我已经试过:

  • 方式(="延伸"
  • VerticalContentAlignment="延伸"
  • Height="自动"

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

回答:

谢谢标记,使用DockPanel而不是在这种情况下,清除它。在一般情况下,我发现自己使用DockPanel现在越来越多WPF布局,这是固定的键

<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" MinHeight="200">
    <DockPanel 
        VerticalAlignment="Stretch" 
        Height="Auto">

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

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

                Padding="5"/>
                </Border>
            </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>
    </DockPanel>
</Window>
有帮助吗?

解决方案

它听起来像是你想要一个 StackPanel 这里的最后一个元件采用了所有剩余空间。但是,为什么不用 DockPanel?装点中的其他元素 DockPanelDockPanel.Dock="Top", ,然后你的帮助控制可以填补剩余空间。

<DockPanel Width="200" Height="200" Background="PowderBlue">
    <TextBlock DockPanel.Dock="Top">Something</TextBlock>
    <TextBlock DockPanel.Dock="Top">Something else</TextBlock>
    <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>
</DockPanel>

如果你是在一个平台没有 DockPanel 提供(例如WindowsStore),您可以创造同样的效果与一个电网。这里是上述的例子通过使用网代替:

<Grid Width="200" Height="200" Background="PowderBlue">
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>
    <StackPanel Grid.Row="0">
        <TextBlock>Something</TextBlock>
        <TextBlock>Something else</TextBlock>
    </StackPanel>
    <Grid Height="Auto" Grid.Row="1" Margin="10">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="100"/>
        </Grid.ColumnDefinitions>
        <GroupBox
            Width="100"
            Height="Auto"
            Grid.Column="1"
            Background="Beige"
            Header="Help">
            <TextBlock Text="This is the help that is available on the news screen." 
              TextWrapping="Wrap"/>
        </GroupBox>
        <StackPanel Width="Auto" Margin="10" DockPanel.Dock="Left">
            <TextBlock Text="Here is the news that should wrap around." 
              TextWrapping="Wrap"/>
        </StackPanel>
    </Grid>
</Grid>

其他提示

原因,这是发生是因为堆小组的措施,每个孩子元件与正无穷作为约束的轴线,这是堆叠元。孩子控制必须返回多大他们想要的是(正无穷不是一个有效的返回 MeasureOverride 在任何一个轴),以便他们返回最小尺寸在哪里的一切都将配合。他们有没有办法知道有多少空间,他们真的有到填补。

如果你查看并不需要有一个滚动的特征和以上的答案并不适合你需要,我建议实现自己的小组。你也许可以得出直接从属性和随后所有你需要做的是变化的 ArrangeOverride 方法,以便它把剩余的空间之间其子元件(给他们每个相同数量的额外空间)。元素应该呈现好的,如果给他们更多的空间,比他们想要的,但是如果你给他们你就会开始看到故障。

如果你想要能够滚动整件事情然后我很害怕事情会有相当多的困难,因为ScrollViewer给你无限的空间量的工作,这将把你放在同一位置的儿童要素。在这种情况下,你可能希望创建一个新酒店上你的新小组,它可以让你指定的视窗的大小,你应该能够结合这ScrollViewer的大小。理想的情况是你就会实现 IScrollInfo, 但这开始变得复杂,如果要实现所有正确。

一种替代方法是使用网格中的一个列和 n 排。设置的所有行高度 Auto, 和最底层的行高度 1*.

我喜欢这种方法,因为我找到网格有更好的布局的性能比DockPanels,StackPanels,并WrapPanels.但是,除非你使用他们在一个ItemTemplate(在那里的布局正在进行大量的项目),你可能从来没有注意到。

你可以使用 修改后的版本 对在这种情况下:

<st:StackPanel Orientation="Horizontal" MarginBetweenChildren="10" Margin="10">
   <Button Content="Info" HorizontalAlignment="Left" st:StackPanel.Fill="Fill"/>
   <Button Content="Cancel"/>
   <Button Content="Save"/>
</st:StackPanel>

第一个按钮将会填补。

你可以安装经Nuget:

Install-Package SpicyTaco.AutoGrid

我还建议采取一看 wpf autogrid.这是非常有用的形式在WPF而不是DockPanel,在这种情况下,网格和解决问题的拉伸非常容易和优雅。只要看看自述在想.

<st:AutoGrid Columns="160,*" ChildMargin="3">
    <Label Content="Name:"/>
    <TextBox/>

    <Label Content="E-Mail:"/>
    <TextBox/>

    <Label Content="Comment:"/>
    <TextBox/>
</st:AutoGrid>

几件事情你可以这样做:

1:设置 Orientation垂直的:

<StackPanel Orientation="Vertical"></StackPanel>
  1. 设置 HeightStackPanel 以相同的窗口:

当然,你可以结合这些 性能:

<StackPanel Orientation="Vertical" Height="600"></StackPanel>

你不需要做一大堆的额外工作与安NuGets和诸如此类的东西。...

编辑

你也可以放在这种情况下,内部的一个ScrollViewer.这会让你控制的高度组框在不牺牲内容可见性。

<GroupBox>
    <ScrollViewer>
        <StackPanel Orientation="Vertical>
              <!-- Place Children Objects here-->
        <StackPanel>
    <ScrollViewer>
<GroupBox>
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top