Files
docs-desktop/dotnet-desktop-guide/framework/wpf/controls/how-to-horizontally-or-vertically-align-content-in-a-stackpanel.md
Andy (Steve) De George be103da07e Replace various WPF include files with content (#1335)
* net-current-v30plus-md.md

* net-current-v40plus-md.md

* tla2sharptla-ui-md.md

* tla2sharptla-uiautomation-md.md

* tla2sharptla-winclient-md.md

* tla2sharptla-xaml-md.md

* tlasharptla-ui-md.md

* tlasharptla-uiautomation-md.md

* tlasharptla-winclient-md.md

* tlasharptla-xaml-md.md

* fix warnings
2022-03-16 12:14:11 -04:00

2.5 KiB

title, description, ms.date, dev_langs, helpviewer_keywords, ms.assetid
title description ms.date dev_langs helpviewer_keywords ms.assetid
How to: Horizontally or Vertically Align Content in a StackPanel Learn how to adjust content orientation in a Windows Presentation Foundation StackPanel and the HorizontalAlignment and VerticalAlignment of child content. 03/30/2017
csharp
vb
StackPanel control [WPF], content alignment [WPF]
content alignment [WPF]
aligning [WPF], content
c1e8f962-72c8-4e7a-8670-7a2d7e021791

How to: Horizontally or Vertically Align Content in a StackPanel

This example shows how to adjust the xref:System.Windows.Controls.StackPanel.Orientation%2A of content within a xref:System.Windows.Controls.StackPanel element, and also how to adjust the xref:System.Windows.FrameworkElement.HorizontalAlignment%2A and xref:System.Windows.FrameworkElement.VerticalAlignment%2A of child content.

Example

The following example creates three xref:System.Windows.Controls.ListBox elements in Extensible Application Markup Language (XAML). Each xref:System.Windows.Controls.ListBox represents the possible values of the xref:System.Windows.Controls.StackPanel.Orientation%2A, xref:System.Windows.FrameworkElement.HorizontalAlignment%2A, and xref:System.Windows.FrameworkElement.VerticalAlignment%2A properties of a xref:System.Windows.Controls.StackPanel. When a user selects a value in any of the xref:System.Windows.Controls.ListBox elements, the associated property of the xref:System.Windows.Controls.StackPanel and its child xref:System.Windows.Controls.Button elements change.

[!code-xamlStackPanelIntroSamp#1]

The following code-behind file defines the changes to the events that are associated with the xref:System.Windows.Controls.ListBox selection changes. xref:System.Windows.Controls.StackPanel is identified by the xref:System.Windows.FrameworkElement.Name%2A sp1.

[!code-csharpStackPanelIntroSamp#2] [!code-vbStackPanelIntroSamp#2]

See also