---
title: "StackPanel Control in WPF"  
description: "In WPF StackPanel control is also used to group controls either horizontally or vertically. We can use StackPanel control to arrange child elements in"  
author: "Anonymous User"  
published: 2011-04-02  
updated: 2019-09-07  
canonical: https://www.mindstick.com/articles/526/stackpanel-control-in-wpf  
category: "wpf"  
tags: ["wpf"]  
reading_time: 1 minute  

---

# StackPanel Control in WPF

In WPF StackPanel control is also used to group controls either horizontally or vertically. We can use StackPanel control to arrange child elements into a single line that is either horizontally or vertically. The <StackPanel /> element in XAML is used to represent a StackPanel.\

##### The following code snippet represents use of StackPanel in WPF

```
<StackPanel x:Name="panel1" Background="LightGoldenrodYellow" Width="300" Height="200">            <Button x:Name="btnPanelDemo" Width="250" Height="30" Margin="10"  Content="StackPanel With Button Control" /></StackPanel>
```

##### Output of the following code snippet is as follows

![StackPanel Control in WPF](https://www.mindstick.com/mindstickarticle/6d305c37-78f6-497b-ae8f-457227db510a/images/08f21056-cb45-4d5e-988c-f558ff9e2337.png)

The orientation property of StackPanel element represents direction of the child elements in stack panel that is either horizontally or vertically. The following code snippets represent use of Orientation property in StackPanel.

```
<StackPanel x:Name="panel1" Background="LightGoldenrodYellow" Width="300" Orientation="Horizontal" Height="200">            <Button x:Name="btnPanelDemo1" Width="130" Height="30" Margin="10" Content="Horizontal Orientation" />            <Button x:Name="btnPanelDemo2" Width="130" Height="30" Margin="10" Content="Horizontal Orientation" /></StackPanel>
```

##### Output of the above code snippet is as follows

![StackPanel Control in WPF](https://www.mindstick.com/mindstickarticle/6d305c37-78f6-497b-ae8f-457227db510a/images/6982a275-2d0b-4e30-a0bd-02ea938c4f1c.png)

When you have did not much more space in StackPanel when you arrange it then by implementing CanHorizontaScroll and CanVerticalScroll property you set to true to add scrolling functionality. To implement scrolling functionality you need to use ScrollViewer control.

---

Original Source: https://www.mindstick.com/articles/526/stackpanel-control-in-wpf

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
