15

次のコードは、2 番目のテキスト要素が「下」とマークされていても、2 つのテキスト要素を上に配置します。背景色が一番下まで伸びているため、DockPanel が一番下まで伸びているように見えます。

DockPanel について理解していないことは何ですか?

<Window x:Class="TestIndexer934.Views.MainView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:c="clr-namespace:TestIndexer934.Commands"
    Title="Main Window" Height="400" Width="800">
    <DockPanel HorizontalAlignment="Left" Background="Beige">
        <TextBlock DockPanel.Dock="Top" Text="Testing top"/>
        <TextBlock DockPanel.Dock="Bottom" Text="Testing bottom"/>
    </DockPanel>
</Window>
4

1 に答える 1

33

デフォルトは、DockPanel の最後の項目は、使用可能な残りのコンテンツ領域を埋めます。

DockPanel で設定LastChildFill="False"すると、期待どおりの動作が表示されます。VerticalAlignment="Bottom"TextBlock に設定することもできます。

于 2009-06-17T08:02:46.310 に答える