1

如何正确安装这些停靠面板?

<DockPanel Grid.Row="1" LastChildFill="True" HorizontalAlignment="Stretch">
    <DockPanel Width="400" LastChildFill="False" HorizontalAlignment="Left">
            <DockPanel>
                <TextBlock Width="400" />
            </DockPanel>
            <DockPanel  Height="35" DockPanel.Dock="Bottom" LastChildFill="False">
                <Button x:Name="btnRefresh" Content="Refersh" />
            </DockPanel>
    </DockPanel>

带有 TextBlock 的 DockPanel 跨越停靠在底部的 DockPanel,我希望它适合它。有任何想法吗?

好的,事实证明:停靠在底部的面板必须在 xaml 声明中位于其上方的停靠面板之前。LastChildFill="True" 适用于代码中最后声明的控件。

<DockPanel Grid.Row="1" LastChildFill="True" HorizontalAlignment="Stretch">
    <DockPanel Width="400" LastChildFill="False" HorizontalAlignment="Left">
        <DockPanel  Height="35" DockPanel.Dock="Bottom" LastChildFill="False">
            <Button x:Name="btnRefresh" Content="Refersh" />
        </DockPanel>
        <DockPanel>
            <TextBlock Width="400" />
        </DockPanel>
    </DockPanel>
4

2 回答 2

4

请参阅 MSDN 上的DockPanel 类页面,其中包含您需要的所有帮助。链接页面中的 XAML 示例:

<DockPanel LastChildFill="True">
    <Border Height="25" Background="SkyBlue" BorderBrush="Black" BorderThickness="1" 
        DockPanel.Dock="Top">
        <TextBlock Foreground="Black">Dock = "Top"</TextBlock>
    </Border>
    <Border Height="25" Background="Blue" BorderBrush="Black" BorderThickness="1" 
        DockPanel.Dock="Top">
        <TextBlock Foreground="White">Dock = "Top"</TextBlock>
    </Border>
    <Border Height="25" Background="Yellow" BorderBrush="Black" BorderThickness="1" 
        DockPanel.Dock="Bottom">
        <TextBlock Foreground="Black">Dock = "Bottom"</TextBlock>
    </Border>
    <Border Width="200" Background="PaleGreen" BorderBrush="Black" BorderThickness="1" 
        DockPanel.Dock="Left">
        <TextBlock Foreground="Black">Dock = "Left"</TextBlock>
    </Border>
    <Border Background="White" BorderBrush="Black" BorderThickness="1">
        <TextBlock Foreground="Black">This will fill the remaining space</TextBlock>
    </Border>
</DockPanel>

请注意DockPanel.Dock附加属性的使用。

在此处输入图像描述

于 2013-10-08T15:47:03.677 回答
2
<DockPanel Grid.Row="1" LastChildFill="True" HorizontalAlignment="Stretch">
   <DockPanel Width="400" LastChildFill="False" HorizontalAlignment="Left">
       <Button x:Name="btnRefresh" Content="Refersh" 
               Height="35" DockPanel.Dock="Bottom" />

       <TextBlock Width="400" />
   </DockPanel>

   <!-- Other UI Elements here? -->

<DockPanel>
于 2013-10-08T15:46:45.950 回答