TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

WPF StackPanel Arranges Controls

This WPF article uses the StackPanel control. In the StackPanel, each control is stacked upon another, in horizontal lines.

StackPanel arranges its sub-controls in horizontal lines.

It stacks them, one upon another. It is easy to use and helps solve some user interface problems. We explore in brief this WPF control.

Example. To begin, please drag a StackPanel to your WPF window. The StackPanel accepts sub-controls. In this example, I added four CheckBox controls to it. Other controls, such as Buttons, are also accepted.

CheckBoxButton

Here: I added four CheckBox controls and changed their Content attributes. They each indicate a breakfast food.

So: The StackPanel contains all sorts of items you could eat for breakfast, such as eggs, pancakes, muffins and toast.

Based on:

.NET 4.5

Example markup: XAML

<Window x:Class="WpfApplication22.MainWindow"
	xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
	Title="Breakfast" Height="350" Width="525">
    <Grid>
	<StackPanel HorizontalAlignment="Left"
		    Height="100"
		    Margin="10,10,0,0"
		    VerticalAlignment="Top"
		    Width="100">
	    <CheckBox Content="Eggs"/>
	    <CheckBox Content="Pancakes"/>
	    <CheckBox Content="Muffins"/>
	    <CheckBox Content="Toast"/>
	    <CheckBox Content="Bacon"/>
	</StackPanel>
    </Grid>
</Window>

Discussion. A StackPanel is similar to a WrapPanel, except each element occupies an entire "line" in the StackPanel. The WrapPanel may be preferred in certain programs. If your program has little horizontal space, a StackPanel is a better idea.

However: When controls should fill the entire horizontal area, the WrapPanel will lead to a better use of space.

WrapPanel

Summary. With StackPanel, we stack controls one after another. It is possible to arrange controls in this way without StackPanel. But StackPanel enforces this arrangement, and makes it easier to maintain, less error-prone.


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf