Nasıl yapılır: StackPanel Oluşturma

Bu örnek, nasıl oluşturulacağını gösterir StackPanel .

Örnek

StackPanel, Öğeleri belirtilen yönde yığmanızı sağlar. Üzerinde tanımlanan özellikleri kullanarak, içerik, StackPanel varsayılan ayar olan dikey, ya da yatay olarak akabilir.

Aşağıdaki örnek, TextBlock her biri farklı ve kullanarak beş denetimi dikey olarak yığar Border Background StackPanel . WidthAna pencereyi dolduracak şekilde, belirtilen genişlemesiz alt öğeler; ancak, belirtilen alt öğeler Width pencere içinde ortalanır.

A içindeki varsayılan yığın yönü StackPanel dikeydir. İçindeki içerik akışını denetlemek için StackPanel Orientation özelliğini kullanın. Özelliğini kullanarak yatay hizalamayı kontrol edebilirsiniz HorizontalAlignment .

<Page xmlns="http://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>  

Ayrıca bkz.