We will add a few buttons to StackPanel and learn how StackPanel works:
To see how it works, let's go ahead and add a new window to our project, and let's name it
StackPanelLayout.xaml
. Go to the Assets panel and search for StackPanel. Then, drag and drop it onto LayoutRoot.Now, search for the buttons in the Assets panel, and drop three of them onto StackPanel. You will see that, as you add these buttons onto StackPanel, they are added vertically one after another. You can set a height, width, and color for these buttons. Make sure that your code looks similar to the one shown in the following screenshot:
We can also arrange the elements with StackPanel horizontally by setting the Orientation property of StackPanel to Horizontal, as shown here: