Wednesday, 30 January 2013

Conatainer Panels in XAML

Container Panels for XAML:

a. Canvas
b. Stack Panel
c. Grid

The above containers can be used both in Windows 8 and Windows 8 Phones as well.
If you are a Silverlight/WPF developer , you will not find these new , but in case you are into xaml development for the first time. Here is a brief description of these panels for you.

Canvas :


Defines an area within which you can explicitly position child objects by using coordinates that are relative to the area.
A Canvas is one of the Panel elements that enable layout. Each child object is rendered within the Canvas area.
The controls are specified inside a canvas using the x and y positions.
The positions are defined in logical pixels.
The x and y coordinates are often specified by using the Canvas.Left and Canvas.Top attached properties.
A Canvas can contain nested objects.
When objects are placed inside the canvas they are positioned relative to the canvas.Only UIElements can be put inside the canvas tags.
You can nest Canvas objects, because a Canvas is a type of UIElement.
In many cases, a Canvas is used solely as a container for other objects and does not have any visible properties.
You can control the visibility of a canavas by using height/width/Background/Opcaity/Visibility/Ancestor Objects.


Stack Panel :


StackPanel is one of the Panel elements that enable layout.
Stack panels help arranging child elements into a single line that can be oriented horizontally or vertically.
Stack panels are useful when you have a menu kind of application / browser kind of application.
The default for both HorizontalAlignment and VerticalAlignment of content in a StackPanel is Stretch.


Grid :

Grid defines a flexible grid area that consists of columns and rows.
Grid enables complex layout.You can define rows and columns inside a grid. By default the grid has one row and one column.
You can position objects in specific cells of the Grid by using the Grid.Column and Grid.Row attached properties.Instead of giving definite sizes to the grid you can specify start sizing/
Star sizing to distributes space proportionally.

Conclusion


Grids are used mostly for almost all kinds of apps.
If you are developing a gaming or a animation app , canvas is the best.
For menus and a hide and show type of controls stack panels are best.

 

No comments:

Post a Comment