Layout Controls
The use of layout controls is both straight-forward and essential to the creation of Silverlight applications. Layout controls are used to manage the placement of other controls (including other layout controls!) in your Silverlight application. You can think of the layout controls as "containers."Silverlight and WPF support a flexible layout management system that enables developers and designers to easily coordinate how controls are positioned within a UI surface. This layout system supports both a fixed position model where controls are positioned using explicit coordinates, as well as a more dynamic position model where layout and controls can be automatically sized and flowed as the browser resizes.
The three Layout controls you'll use most often are:
- Grid - essentially a table used for positioning objects in rows and columns.
- StackPanel - used to position objects next to one another, or atop one another.
- Canvas - used for absolute positioning (and unchanged from Silverlight 1.0)
They are listed in the order of how frequently they are used. And to be honest, if you learn Grid and StackPanel, you can probably program for a long time on just those two.
Grids
Grids (not to be confused with DataGrids) offer easy and exact placement by providing a table-like structure. You declare rows and columns, and then place controls into a specific row/column location (spanning across rows or columns as needed).
The Grid control is the most flexible layout panel, and supports arranging controls in multi-row and multi-column layouts. It is conceptually similar to an HTML Table element.
Unlike an HTML Table, you don't embed controls within column and row elements. Instead you specify a Grid's Row and Column definitions using
While you can tweak your grids to achieve very precise placement, the basic use of grids is extremely straight forward.
For example, we could declare a Grid layout has three rows and three columns, and then position 4 buttons within it using XAML like below:
The Grid layout panel would then position the Button elements for us like so:
StackPanel
The StackPanel control is a simple layout panel that supports positioning its contained controls in either a row or column layout. StackPanels are typically used in scenarios where you want to arrange a small subsection of the UI on your page.
StackPanels are typically combined with other layout controls. They allow you to stack objects one on top of the other, or next to each other (like books on a shelf).
One convenience of a StackPanel is that you do not have to provide the position of the objects held by a StackPanel, they are positioned relative to the object declared earlier in the Stack.
For example, we could use the StackPanel to vertically arrange three buttons on our page using XAML markup like below:
At runtime the StackPanel would then automatically arrange the Button controls in a vertical stack for us like below:
Canvas Panel
The Canvas panel is a pretty basic layout panel that supports positioning controls contained within it using explicit coordinates.You position elements in a Canvas using a XAML feature called "Attached Properties" - which allow you to specify a control's position relative to its immediate parent Canvas control's Left, Top, Right or Bottom coordinates. Attached properties are useful as they allow a parent panel to extend the property set of a control contained within it. Canvas, by defining an attached property for “Top” and ”Left” basically adds the ability to define left and top attachment on Button (or any other UI element that is added to the Canvas), without any need to actually add a property to the Button class, or modify the Button class in any way.
We could add two buttons to a Canvas container, and position them both 50 pixels from the left of the Canvas, and 50 and 150 pixels from the top using XAML like below (the Canvas.Left and Canvas.Top attributes are examples of the attached property syntax):
This would then render our buttons like below:
References:
http://www.silverlight.net/learn/tutorials/controls-cs/
http://weblogs.asp.net/scottgu/pages/silverlight-tutorial-part-2-using-layout-management.aspx
Books:
Silverlight 4 Lab Intensive Skills Training
Professional Visual Studio 2010 (Paperback)
C Sharp 4.0 in a Nutshell
Hello!
ReplyDeleteI am trying to resize an stack panel with the same size as its parent but i can;t, It is always as big as its necessary to content its children.
I need a vertical/horizontal layout which can have it-s parent's size... any help?
Good blog! For more tutorials and queries Check this site for indepth Silverlight tutorials. Go here if you’re looking for tutorials on Silverlight.
ReplyDelete
ReplyDeleteIt fun to have a content like this really worth to read it
Pega Training
PlSQL Training
AWS Training
Teradata Training
Qlikview Training
Informatica MDM Training
Hello!
ReplyDeleteI am trying to resize an stack panel with the same size as its parent.thanks a lot.
C and C++ Training Institute in chennai | C and C++ Training Institute in anna nagar | C and C++ Training Institute in omr | C and C++ Training Institute in porur | C and C++ Training Institute in tambaram | C and C++ Training Institute in velachery
This is really amazing post in this blog and its really useful one to looking into coding and creating a applications.
ReplyDeletePython Training in Chennai | Certification | Online Course Training | Python Training in Bangalore | Certification | Online Course Training | Python Training in Hyderabad | Certification | Online Course Training | Python Training in Coimbatore | Certification | Online Course Training | Python Training in Online | Certification | Online Course Training
Nice post.. Thankyou so much for sharing this article..
ReplyDeleteAndroid Training in Bangalore
Android Training
Android Online Training
Android Training in Hyderabad
Android Training in Chennai
Android Training in Coimbatore
Nice post.. Thankyou so much for sharing this article..
ReplyDeleteIELTS Coaching in chennai
German Classes in Chennai
GRE Coaching Classes in Chennai
TOEFL Coaching in Chennai
spoken english classes in chennai | Communication training
Good blog! For more tutorials and queries Check this site for indepth Silverlight tutorials. Go here if you’re looking for tutorials on Silverlight.
ReplyDelete| Certification | Cyber Security Online Training Course|
Ethical Hacking Training Course in Chennai | Certification | Ethical Hacking Online Training Course|
CCNA Training Course in Chennai | Certification | CCNA Online Training Course|
RPA Robotic Process Automation Training Course in Chennai | Certification | RPA Training Course Chennai|
SEO Training in Chennai | Certification | SEO Online Training Course
Good blog
ReplyDeletehadoop training in bangalore
oracle training in bangalore
hadoop training in acte.in/oracle-certification-training">oracle training
oracle online training
oracle training in hyderabad
hadoop training in chennai
Nice post.. Thankyou so much for sharing this article..DevOps Training in Bangalore
ReplyDeleteDevOps Training
DevOps Online Training
DevOps Training in Hyderabad
DevOps Online Training in Chennai
DevOps Training in Coimbatore