1 Answer

0 votes
by

WPF comes with the following five built-in panels:

  • Canvas
  • DockPanel
  • Grid
  • StackPanel
  • WrapPanel
The purpose and use of these panels is different. Each panel has a different way to position and reposition child controls placed within that panel. The following articles in this series will summarise these panels and their usages.
 
Similar to any other WPF control, a Panel control may be represented in two ways. First, at design-time using XAML elements and attributes, and second, at run-time, using a WPF class and its properties.
 
The code snippet in Listing 2 creates a Grid panel at design-time using XAML.
  1. <Window x:Class="CanvasPanelSample.Window1"   
  2.    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"   
  3.    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"   
  4.    Title="Window1" Height="300" Width="300"   
  5.    Name="RootWindow">   
  6.    <Grid Name="GridPanel" Background="Blue"   
  7.       Width="250" Height="200"   
  8.       VerticalAlignment="Top"   
  9.       HorizontalAlignment="Left"   
  10.       FlowDirection="LeftToRight"   
  11.    />   
  12. </Window>   
Listing 2 generates Figure 2.
 
layout panels in WPF

Related questions

0 votes
    What is the Tab Control in WPF?...
asked Apr 9, 2021 in Education by JackTerrance
0 votes
    How can I clip or crop an image?...
asked Apr 9, 2021 in Education by JackTerrance
0 votes
0 votes
0 votes
    What is a WPF Child Window?...
asked Apr 9, 2021 in Education by JackTerrance
...