--- title: "How to: Horizontally or Vertically Align Content in a StackPanel" description: Learn how to adjust content orientation in a Windows Presentation Foundation StackPanel and the HorizontalAlignment and VerticalAlignment of child content. ms.date: "03/30/2017" dev_langs: - "csharp" - "vb" helpviewer_keywords: - "StackPanel control [WPF], content alignment [WPF]" - "content alignment [WPF]" - "aligning [WPF], content" ms.assetid: c1e8f962-72c8-4e7a-8670-7a2d7e021791 --- # How to: Horizontally or Vertically Align Content in a StackPanel This example shows how to adjust the of content within a element, and also how to adjust the and of child content. ## Example The following example creates three elements in [!INCLUDE[TLA#tla_xaml](../../../includes/tlasharptla-xaml-md.md)]. Each represents the possible values of the , , and properties of a . When a user selects a value in any of the elements, the associated property of the and its child elements change. [!code-xaml[StackPanelIntroSamp#1](~/samples/snippets/csharp/VS_Snippets_Wpf/StackPanelIntroSamp/CSharp/Window1.xaml#1)] The following code-behind file defines the changes to the events that are associated with the selection changes. is identified by the `sp1`. [!code-csharp[StackPanelIntroSamp#2](~/samples/snippets/csharp/VS_Snippets_Wpf/StackPanelIntroSamp/CSharp/Window1.xaml.cs#2)] [!code-vb[StackPanelIntroSamp#2](~/samples/snippets/visualbasic/VS_Snippets_Wpf/StackPanelIntroSamp/VisualBasic/Window1.xaml.vb#2)] ## See also - - - - - [Panels Overview](panels-overview.md)