articles

StackPanel Control in WPF

Anonymous User11066 02-Apr-2011

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

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

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.

 


Updated 07-Sep-2019
I am a content writter !

Leave Comment

Comments

Liked By