Different Containers in WPF

 

In WPF, window cannot have multiple controls. WPF window must have only one control which is called container and container have multiple controls. 

There are different containers in WPF. Those are Grid, Stack Panel, Wrap Panel, Dock Panel and Canvas.

 

Grid Container: 

Grid container is the default container where we can arrange the elements in our own fashion. We can arrange the elements in table format by using Grid container in WPF.

 

Stack Panel: 

By using Stack Panel in WPF we can arrange the elements in Vertical or Horizontal format.

 

Wrap Panel: 

With the help of Wrap Panel we can arrange the elements in WPF Vertical and Horizontal format. Wrap Panel is same as Stack Panel but it wraps according to sizes of the form. That is the control in Wrap Panel is shifted to the next line automatically if the form size is getting changed.

 

Dock Panel: 

The container allows the user to place the control in exact location where ever we want like Top, Bottom, Left, Right or Fill entire container. If we specify the location as left control will located at left position or if Top is specified it placed in Top position. If we not specify any position then control will occupy entire space on the container.

 

Canvas: 

This container is used to place the control by specifying the position in pixel format. That means if you want to specify the control 50 pixel from the top just provide the value as 50 for Canvas.Top attribute. We can use Canvas.Left, Canvas.Right, Canavas.Bottom attributes also.