ARTICLE

StackPanel use in WPF Application

Posted by Sapna Malik Articles | WPF using VB.NET August 30, 2010
Tags: .NET, ASP.NET, VB.NET, WPF
In this article, We will see how to use StackPanel in WPF Application.
 
Reader Level:

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:-

stackpanel1.bmp

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:-

stackpanel2.bmp

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:-

 stackpanel3.bmp

I hope this article help you.

 

share this article :
post comment
 
Become a Sponsor
PREMIUM SPONSORS
  • ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
    The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor