StackPanel use in WPF using VB.NET
In this article, We will see how to use StackPanel in WPF Application.
In this article, We will see how to use StackPanel in WPF Application.
The StackPanel is simple and useful element in XAML. StackPanel is a layout panel. We can use Horizontal and Vertical. The StackPanel shows your elements according to the order you declared them in XAML file.
All WPF Item control
like ComboBox
, ListBox
or Menu
use a StackPanel as their internal layout panel.
Example:-
<Window x:Class="Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300">
<Grid>
<StackPanel>
<TextBox Background="Red">
Background Of Red Color
</TextBox>
<TextBox Background="White">
Background Of White Color
</TextBox>
<TextBox Background="Pink">
Background Of Pink Color
</TextBox>
<TextBox Background="White">
Background Of White Color
</TextBox>
<TextBox Background="Red">
Background Of Red Color
</TextBox>
</StackPanel>
</Grid>
</Window>
Output:-
We will use 'Width="175"' in this example with StackPanel.
Example:-
<Window x:Class="Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300">
<Grid>
<StackPanel Width="175">
<TextBox Background="Red">
Background Of Red Color
</TextBox>
<TextBox Background="White">
Background Of White Color
</TextBox>
<TextBox Background="Pink">
Background Of Pink Color
</TextBox>
<TextBox Background="White">
Background Of White Color
</TextBox>
<TextBox Background="Red">
Background Of Red Color
</TextBox>
</StackPanel>
</Grid>
</Window>
Output:-
We will use 'Orientation="Horizontal"' in this example with StackPanel.
Example:-
<Window x:Class="Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300">
<Grid>
<StackPanel Orientation="Horizontal">
<TextBox Background="Red">
Red
</TextBox>
<TextBox Background="White">
White
</TextBox>
<TextBox Background="Pink">
Pink
</TextBox>
<TextBox Background="White">
White
</TextBox>
<TextBox Background="Red">
Red
</TextBox>
</StackPanel>
</Grid>
</Window>
Output:-
I hope this article help you.