次の方法で共有


方法 : StackPanel を作成する

更新 : 2007 年 11 月

次の例では、StackPanel オブジェクトを作成する方法を示します。

使用例

StackPanel を使用すると、指定した方向に要素をスタックできます。StackPanel で定義されているプロパティを使用すると、コンテンツを垂直方向 (既定の設定) または水平方向にフローさせることができます。

次の例では、StackPanel を使用して、それぞれに異なる BorderBackground が設定されている 5 つの TextBlock コントロールを垂直方向にスタックします。Width が指定されていない子要素は親ウィンドウ全体に引き伸ばされますが、Width が指定されている子要素はウィンドウの中央に配置されます。

StackPanel の既定のスタック方向は垂直方向です。StackPanel でコンテンツ フローを制御するには、Orientation プロパティを使用します。水平方向の配置は、HorizontalAlignment プロパティを使用して制御できます。

<Page xmlns="https://schemas.microsoft.com/winfx/2006/xaml/presentation" WindowTitle="StackPanel Sample">
  <StackPanel>
    <Border Background="SkyBlue" BorderBrush="Black" BorderThickness="1">
      <TextBlock Foreground="Black" FontSize="12">Stacked Item #1</TextBlock>
    </Border>
    <Border Width="400" Background="CadetBlue" BorderBrush="Black" BorderThickness="1">
      <TextBlock Foreground="Black" FontSize="14">Stacked Item #2</TextBlock>
    </Border>
    <Border Background="LightGoldenRodYellow" BorderBrush="Black" BorderThickness="1">
      <TextBlock Foreground="Black" FontSize="16">Stacked Item #3</TextBlock>
    </Border>
    <Border Width="200" Background="PaleGreen" BorderBrush="Black" BorderThickness="1">
      <TextBlock Foreground="Black" FontSize="18">Stacked Item #4</TextBlock>
    </Border>
    <Border Background="White" BorderBrush="Black" BorderThickness="1">
      <TextBlock Foreground="Black" FontSize="20">Stacked Item #5</TextBlock>
    </Border>
  </StackPanel>
</Page>

参照

概念

パネルの概要

参照

StackPanel

その他の技術情報

StackPanel に関する「方法」トピック

StackPanel のサンプル