Friday, 27 May 2011

Creating Custom Cache Dependency

ASP.NET 2.0 offers you several ways to set a dependency between a cached item and a file(s), another cached item(s) or SQL Server database table. No doubt they satisfy most of the real world needs. However, at times the features offered by these dependencies are not sufficient. In such cases you can create your own dependency and use it instead of inbuilt ones.

Coding style


The program should be easy to read and to understand when you need to refer back to
it. Follow these guidelines while coding:
§ Always use "Option Explicit" to catch any undeclared or misspelled
variables. Also, the use of "Option Explicit" makes the Web pages run
fast. The "Option Explicit" option forces the explicit declaration of
variables.
§ Declare one variable per line. This avoids confusion about datatypes.
§ Use comments wherever possible to document a difficult code section.
§ Use blank lines in the code for clarity.
§ Use proper code block indenting.

Programmability


The ADO.NET model uses typed programming to manipulate objects. In typed
programming, the programming environment or programming language itself recognizes
the types of things that are important to users. To take full advantage of typed
programming, you must know the things that are of interest to programmers and to end
users. Consider the following code using typed programming in ADO.NET:
If TotalQty > DataSet1.ProductInfo("Baby Food").QtyAvailable
This code is equivalent to a line using non-typed programming and is easier to read by
end users. An end user who has little or no programming experience can easily grasp
the meaning of the condition being tested. Also, in non-typed programming, if the
developer makes a spelling mistake by chance (for example, ProductInfo is spelled as
ProdcutInfo), a run-time error will get generated. On the other hand, in typed datasets,
errors in the syntax caused by misspellings are detected at compile time rather than at
run time.

Maintainability


After an application is deployed, there might be a need for changes in the application.
For example, the application might need substantial architectural changes to improve its
performance. As the performance load on a deployed application server grows, system
resources can become inadequate, resulting in higher response times. As a solution to
these problems, the application might need to undergo architectural changes by adding
tiers. Here, the problem is not the multitier application design, but rather the problem lies
in increasing the number of tiers after an application is deployed. This transformation
becomes easier if the original application is implemented in ADO.NET using datasets. In
ADO.NET, the communication between tiers is relatively easy, because the tiers can
transmit data through XML-formatted datasets.

Interoperability


The ADO.NET model is designed to take maximum advantage of the flexibility provided
by the large industry acceptance of XML. ADO.NET uses XML for transmitting datasets
among components and across tiers. Any component that is capable of reading the XML
format can process the data. It is not necessary for the receiving component to be an
ADO.NET component. The component that is sending or transmitting the dataset can
simply transmit the dataset to its destination without bothering with how the receiving
component is implemented. The component asking for the dataset, the destination
component, can be implemented as a Visual Studio application or any other application.
However, the important point to be considered is that the receiving component should be
capable of accepting the XML file formatted as a dataset.

Scalability


The Web-based, data-centric applications require multiple users to access data
simultaneously. This increases the demand on data to be accessed, making scalability
one of the most critical features. Applications that use resources, such as database
connections and database locks, cannot support more users to access data
simultaneously, because eventually the user demand for the limited resources will
exceed their supply. Because ADO.NET uses disconnected data access, applications do
not retain database locks or active database connections for long durations. Hence,
ADO.NET accommodates scalability by encouraging programmers to conserve limited
resources, and allows more users to access data simultaneously.

ADO.NET Object Model


The .NET Framework is designed to change dramatically the developer's current style of
developing applications, including the data access features. For the .NET applications,
the primary data access technology to be used would be ADO.NET — the latest addition
to the ADO model.
The ADO.NET Object Model is primarily divided into two levels:
§ Connected Layer: Consists of the classes that comprise the Managed
Providers
§ Disconnected Layer: Is rooted in the DataSet
This section describes both the Managed Providers and the DataSet.

Microsoft HailStorm


With the creation of such an important and far-reaching technology as Web services, it is
not surprising that major software vendors are planning to deliver a horizontal set of
useful Web services that will be needed by many next-generation Web-based
applications.
Microsoft itself has announced that it will deliver a set of Web services based on the
.NET technologies codenamed "HailStorm." These services collect and store personal
information that can be shared with other applications and services based entirely on
your consent and control.
Nearly all of us have dealt with the frustration of having multiple usernames, passwords,
and profiles for the myriad sites and services that we visit on the Web. What's more,
each site that retains this personal information has differing privacy policies and
procedures for sharing this information with partners.
HailStorm promises to eliminate this frustration and lack of control over your personal
information and replace it with a single source for this data that is under your complete
control with respect to accessing this information.
Microsoft has announced that it will release the following sets of HailStorm services
initially:
§ MyAddress: Electronic and geographic address for an identity. For example,
your mailing address and/or your e-mail address can be managed by this
service.
§ MyProfile: Name, nickname, special dates, pictures, and other more personal
information about yourself.
§ MyContacts: Electronic relationships/address book that maintains names, email
addresses, and other information about your personal contacts.
§ MyLocation: Electronic and geographical location and rendezvous. This
service provides information to help locate you electronically.
§ MyNotifications: Notification subscription, management, and routing provide
services that let you control automatic notifications via e-mail, paging, etc
for items that are important to you.
§ MyInbox: Inbox items like e-mail and voice mail, including existing mail
systems enables you to centrally manage your e-mail and related
information.

Add ASP.Net DataColumn to DataTable


we learnt the C# code for setting the properties of DataColumn. There we also learnt how to create an AutoIncrement Identity column with DataType as integer and other column with DataType as string. Here we will learn how to Add ASP.Net DataColumn to a DataTable.

Initializing ASP.Net DataTable Class Object


DataTable myDataTable = new DataTable();

Above C# code line shows how to initialize an instance for DataTable class object to create an in-memory table schema.


C# Code to Add ASP.Net DataColumn to a DataTable


// Initialize a DataTableDataTable myDataTable = new DataTable();

// Initialize DataColumn
DataColumn myDataColumn = new DataColumn();

// Add First DataColumn// AllowDBNull propertymyDataColumn.AllowDBNull = false;
// set AutoIncrement property to truemyDataColumn.AutoIncrement = true;
// set AutoIncrementSeed property equal to 1myDataColumn.AutoIncrementSeed = 1;
// set AutoIncrementStep property equal to 1myDataColumn.AutoIncrementStep = 1;
// set ColumnName property to specify the column namemyDataColumn.ColumnName = "auto_ID";
// set DataType property of the column as IntegermyDataColumn.DataType = System.Type.GetType("System.Int32");
// set Unique property of DataColumn to true to allow unqiue value for this column in each rowmyDataColumn.Unique = true;
// Add and Create a first DataColumnmyDataTable.Columns.Add(myDataColumn);
Above C# code will add and create a new auto incrementing DataColumn to the DataTable.


// Add second DataColumn
// initialize a new instance of DataColumn to add another column with different properties.
myDataColumn = new DataColumn();
myDataColumn.ColumnName = "firstName";

// set DataType property of the column as StringmyDataColumn.DataType = System.Type.GetType("System.String");

// Add and Create a Second DataColumn
myDataTable.Columns.Add(myDataColumn);


// Add third DataColumn
// initialize a new instance of DataColumn to add another column with different properties.
myDataColumn = new DataColumn();
myDataColumn.ColumnName = "lastName";

// set DataType property of the column as StringmyDataColumn.DataType = System.Type.GetType("System.String");
// Add and Create a Third DataColumnmyDataTable.Columns.Add(myDataColumn);
Note: ASP.Net DataTable creates the schema for DataColumn in the same order in which they are added to the table. For example in the above sample code DataTable will create DataColumn in the order of auto_ID, firstName, lastName.

Using ASP.Net DataColumn Properties


we discussed about the commonly used properties of DataColumn that allows you to create a data column with specific behavior to store data in each row of DataTable. You can create the DataTable schema similar to the tables in SQL database using the different properties of DataColumn. After the initialization step of ASP.Net DataColumn you can access its properties to specify the columnName, auto increment etc.

C# Code for Using ASP.Net DataColumn Properties


// Initialize DataColumnDataColumn myDataColumn = new DataColumn();

// AllowDBNull propertymyDataColumn.AllowDBNull = false;
// set AutoIncrement property to truemyDataColumn.AutoIncrement = true;
// set AutoIncrementSeed property equal to 1myDataColumn.AutoIncrementSeed = 1;
// set AutoIncrementStep property equal to 1myDataColumn.AutoIncrementStep = 1;
// set ColumnName property to specify the column namemyDataColumn.ColumnName = "auto_ID";
// set DataType property of the columnmyDataColumn.DataType = System.Type.GetType("System.Int32");
// set Unique property of DataColumn to true to allow unqiue value for this column in each rowmyDataColumn.Unique = true;

Above C# code shows the use of properties of DataColumn. It also shows how to create an AutoIncrement identity column using DataColumn properties. For AutoIncrement column you must specify theDataType as integer type as shown in above sample code. To store the string type data in DataColumn field you can use System.String as a value of DataType property.

For example:
myDataColumn = new DataColumn();

myDataColumn.ColumnName = "firstName";

myDataColumn.DataType = System.Type.GetType("System.String");

How to use ASP.Net DataColumn Class Properties


In ASP.NetDataColumn class enables you to add a new column inDataTable to create in-memory structure of table populated with records dynamically. ASP.Net DataColumn allows you to define the columnName, DataType, unique and auto increment properties for new column. Using DataRow class object you can add new records under different DataColumns of DataTable by creating new row dynamically. In this tutorial we will discuss the commonly used properties of ASP.Net DataColumn class object.

Creating ASP.Net DataColumn Class Object


DataColumn myDataColumn = new DataColumn();

Above C# code shows the simplest code line to create the DataColumn class object. While initializing the new instance of DataColumn object using "new" keyword it supports 4 additional constructor overloads that accept different sets of parameters to initialize the instance of DataColumn. Following are the DataColumn initialization overloads:
  1. public DataColumn(string columnName);

  2. public DataColumn(string columnName, Type dataType);

  3. public DataColumn(string columnName, Type dataType,string expr);

  4. public DataColumn(string columnName, Type dataType,string expr, MappingType type);


First ASP.Net C# DataColumn class constructor accepts 1 parameter of string type as columnName that initializes a new column with specified column name. Second overloaded constructor accepts 2 parameters, 1st parameter is same as in the previous constructor but 2nd parameter supports System.Type value that specifies the DataType for new column. Third overload accepts 3 parameters among them first two parameters are same as in second overloaded constructor that accepts 2 parameters. 3rd parameter of third overloaded constructor of DataColumn class accepts string type expression to calculate the value for the data column. Last overloaded constructor accepts 1 extra parameter than third type of constructor as MappingType. MappingType is an enum type value that specifies the type of mapping for the new column. These constructors of ASP.Net DataColumn class allows you to specify some of the properties in a single initialization C# code but instead of them there are some other properties of DataColumn that allows you to get or set their values after the creation and initialization of DataColumn class object.

ASP.Net DataColumn Class Properties


  1. AllowDBNull: Accepts bool type value (true/false) that specifies whether null values are allowed in this data column or not.

  2. AutoIncrement: Accepts bool type (true/false) that specified whether this column will increment the value automatically or not while adding a new row to the data table.

  3. AutoIncrementSeed: Accepts the number value to specify the starting value for auto increment supporting column.

  4. AutoIncrementStep: Accepts the number value to specify the increment step for auto increment supporting column.

  5. ColumnName: Accepts the string value to specify the name of column.

  6. DataType: Accepts the System.Type value to specify the data type for column to store the specified type of data in it.

  7. DefaultValue: Accepts the default value for the column, incase no value passed to the column in a new row.

  8. MaxLength: Accepts the integer type value to specify the maximum length for the text column.

  9. Unique: Accepts the bool type value to specify that the column must contain a unique in each row of datatable.

What Is .Net Framework


The .NET Framework is a vital component of Windows that serves as a great platform to develop and execute the next generation of applications and XML Web services. The .NET Framework is designed with number of functions to fulfill some important needs of programming world. Following are some of the functions on which .Net Framework is based upon:
  • It provides object-oriented programming environment whether object code is stored and executed locally or via internet, executed remotely.
  • It has code-execution environment that reduces the problem of software deployment and versioning.
  • Code-execution environment provides safe execution of code even if it is being created by semi-trusted third party.
  • .Net Framework’s code-execution environment has eliminated the performance problems of scripted or interpreted environments.
  • It provides consistent environment and developer experience across different types of applications, such as Windows-based applications and Web-based applications.
  • .NET Framework tries to ensure that it can be integrated with any other code. 

The .NET Framework has 2 main components:
  • The common language runtime
  • .NET Framework class library

Common Language Runtime

.Net Framework provides a run-time environment that executes the code and provides services for making the process of development easier. The common language runtime works as an agent that manages code at execution time, providing key services such as memory management, thread management, and remoting. .Net Framework compilers and tools help the developers to target the principle of runtime environment by providing managed code approach for developing applications. Benefits of managed code targeting runtime include cross-language integration, exception handling, enhanced security, versioning support, and debugging and profiling services.
Other features of common language runtime:
  • Cross Language Inheritance
  • Garbage Collection and automatic memory allocation and release
  • Self describing objects
  • Ability to run once compiled version on any CPU or Operating system that supports the runtime.

.Net Framework Class Library

The .Net Framework includes classes, interfaces, value types that facilitate the development environment to integrate with system functionality. .Net Framework components, controls and applications all are built upon using these class libraries. Functions of Class Library types include:
  • Represent base data types and exceptions.
  • Encapsulate data structures.
  • Perform Input/Output (I/O).
  • Access information about loaded types.
  • .NET Framework security checks.
  • Provide data access and provide rich and controlled GUI.

Definition of Web Services


Web Services are defined as reusable web based applications that can be accessed through different hardware platforms and operating systems. XML and HTTP is the basic platform of web services. It is a standardized way of integrating web applications using web service standards and protocols for accessing and developing web services such as XML, SOAP, WSDL and UDDI. XML is used to format the data retrieved by the protocol, SOAP is used to transfer the data, WSDL describes the availability of web service and UDDI provides the list of available services.

Web Service Design Patterns

Basic aspects of Web service design pattern are:
  • Understanding web services
  • Web services management and their interoperability
  • Understand the lower level transport model
  • Provide appropriate Security
  • Provide Specific functionality and User Friendly GUI
  • Plan for deployment issues


Use of Web Services

Web Services do not provide the user with any interface to show data in well defined web pages. Instead, web services just share data tagged with XML across the network. Developers process this data by connecting web services to a GUI such as Web Pages and provide it user friendly interface to offer useful functionality to the user.

Advantages of using Web Services

Create reusable web based applications as Web Services. Sometimes different applications need same code very often. Web Services has overcome this problem of developing same applications again and again. For example currency conversion, weather report and country locations services. Web Services reduce the time consuming custom coding by providing reusable functions to develop applications with specific functionality. Web Services are platform independent because all communication in XML. JAVA can communicate with Perl; LINUX applications can communicate with Windows applications easily.

Web Services Applications

There are number of example of using web services applications like selling products of your business affiliate partner by creating ecommerce web site accessing the products catalog through Web Services. This helps in revenue sharing by tracking visitors of your site. Other example of web service: Weather report web service provides temperature of different locations; its web based widgets can be used to be placed on your web site to show the live weather report.

Future of Web Services

Web Service is a simple, interoperable, messaging framework. Today it has proved itself as a quick and efficient way of increasing business revenue if your business is capable of creating web services available to other people. Web Services SOAP is becoming more advanced and trying to overcome the issue of security and routing.

Shared Assemblies


Shared assemblies are intended to be common libraries that any other application can use. Because any other software can access a shared assembly, more precautions need to be taken against the following risks:


❑ Name collisions, where another company ’ s shared assembly implements types that have the
same names as those in your shared assembly. Because client code can theoretically have access to both assemblies simultaneously, this could be a serious problem.


❑ The risk of an assembly being overwritten by a different version of the same assembly — the
new version being incompatible with some existing client code.


The solution to these problems is placing shared assemblies in a special directory subtree in the file system, known as the global assembly cache (GAC). Unlike with private assemblies, this cannot be done by simply copying the assembly into the appropriate folder — it needs to be specifically installed into the cache. This process can be performed by a number of .NET utilities and requires certain checks on the assembly, as well as the set up of a small folder hierarchy within the assembly cache that is used to ensure assembly integrity.
To prevent name collisions, shared assemblies are given a name based on private key cryptography (private assemblies are simply given the same name as their main file name). This name is known as a strong name ; it is guaranteed to be unique and must be quoted by applications that reference a shared assembly.
Problems associated with the risk of overwriting an assembly are addressed by specifying version information in the assembly manifest and by allowing side - by - side installations.

Private Assemblies

Private assemblies are the simplest type. They normally ship with software and are intended to be used
only with that software. The usual scenario in which you will ship private assemblies is when you are
supplying an application in the form of an executable and a number of libraries, where the libraries
contain code that should be used only with that application.
The system guarantees that private assemblies will not be used by other software because an application
may load only private assemblies that are located in the same folder that the main executable is loaded
in, or in a subfolder of it.
Because you would normally expect that commercial software would always be installed in its own
directory, there is no risk of one software package overwriting, modifying, or accidentally loading
private assemblies intended for another package. And, because private assemblies can be used only by
the software package that they are intended for, you have much more control over what software uses
them. There is, therefore, less need to take security precautions because there is no risk, for example, of
some other commercial software overwriting one of your assemblies with some new version of it (apart
from software that is designed specifically to perform malicious damage). There are also no problems
with name collisions. If classes in your private assembly happen to have the same name as classes in
someone else ’ s private assembly, that does not matter, because any given application will be able to see
only the one set of private assemblies.
Because a private assembly is entirely self - contained, the process of deploying it is simple. You simply
place the appropriate file(s) in the appropriate folder in the file system (no registry entries need to be
made). This process is known as zero impact (xcopy) installation .

Assemblies

An assembly is the logical unit that contains compiled code targeted at the .NET Framework. Assemblies
are not covered in detail in this chapter because they are covered thoroughly in Chapter 17 ,
“ Assemblies, ” but we summarize the main points here.
An assembly is completely self - describing and is a logical rather than a physical unit, which means that
it can be stored across more than one file (indeed, dynamic assemblies are stored in memory, not on file
at all). If an assembly is stored in more than one file, there will be one main file that contains the entry
point and describes the other files in the assembly.
Note that the same assembly structure is used for both executable code and library code. The only real
difference is that an executable assembly contains a main program entry point, whereas a library
assembly does not.
An important characteristic of assemblies is that they contain metadata that describes the types and
methods defined in the corresponding code. An assembly, however, also contains assembly metadata
that describes the assembly itself. This assembly metadata, contained in an area known as the manifest ,
allows checks to be made on the version of the assembly, and on its integrity.


The fact that an assembly contains program metadata means that applications or other assemblies that
call up code in a given assembly do not need to refer to the registry, or to any other data source, to find
out how to use that assembly. This is a significant break from the old COM way of doing things, in which
the GUIDs of the components and interfaces had to be obtained from the registry, and in some cases, the
details of the methods and properties exposed would need to be read from a type library.
Having data spread out in up to three different locations meant there was the obvious risk of something
getting out of synchronization, which would prevent other software from being able to use the
component successfully. With assemblies, there is no risk of this happening, because all the metadata is
stored with the program executable instructions. Note that even though assemblies are stored across
several files, there are still no problems with data going out of synchronization. This is because the file
that contains the assembly entry point also stores details of, and a hash of, the contents of the other files,
which means that if one of the files gets replaced, or in any way tampered with, this will almost certainly
be detected and the assembly will refuse to load.

Namespaces

Namespaces are the way that .NET avoids name clashes between classes. They are designed to prevent
situations in which you define a class to represent a customer, name your class Customer , and then someone else does the same thing (a likely scenario — the proportion of businesses that have customers seems to be quite high).
A namespace is no more than a grouping of data types, but it has the effect that the names of all data
types within a namespace are automatically prefixed with the name of the namespace. It is also possible
to nest namespaces within each other. For example, most of the general - purpose .NET base classes are in a namespace called System . The base class Array is in this namespace, so its full name is System.Array.
.NET requires all types to be defined in a namespace; for example, you could place your Customer class
in a namespace called YourCompanyName . This class would have the full name:

YourCompanyName.Customer 

If a namespace is not explicitly supplied, the type will be added to a nameless global namespace.
Microsoft recommends that for most purposes you supply at least two nested namespace names: the first
one represents the name of your company, and the second one represents the name of the technology or
software package of which the class is a member, such as YourCompanyName.SalesServices.Customer.

 This protects, in most situations, the classes in your application from possible name clashes with classes
written by other organizations.

Windows Presentation Foundation ( WPF )

One of the newest technologies to hit the block is the Windows Presentation Foundation (WPF). WPF
makes use of XAML in building applications. XAML stands for Extensible Application Markup
Language. This new way of creating applications within a Microsoft environment is something that was
introduced in 2006 and is part of the .NET Framework 3.0 and 3.5. This means that to run any WPF
application, you need to make sure that the .NET Framework 3.0 or 3.5 is installed on the client machine.
WPF applications are available for Windows Vista, Windows XP, Windows Server 2003, and Windows
Server 2008 (the only operating systems that allow for the installation of the .NET Framework 3.0 or 3.5).
XAML is the XML declaration that is used to create a form that represents all the visual aspects and
behaviors of the WPF application. Though it is possible to work with a WPF application programmatically, WPF is a step in the direction of declarative programming, which the industry is moving to. Declarative programming means that instead of creating objects through programming in a compiled language such as C#, VB, or Java, you declare everything through XML - type programming.

Windows Communication Foundation ( WCF )

Looking at how you move data and services from one point to another using Microsoft - based
technologies, you will find that there are a lot of choices at your disposal. For instance, you can use
ASP.NET Web services, .NET Remoting, Enterprise Services, and MSMQ for starters. What technology
should you use? Well, it really comes down to what you are trying to achieve, because each technology is
better used in a particular situation.

With that in mind, Microsoft brought all of these technologies together, and with the release of the .NET
Framework 3.0 as well as it s inclusion in the .NET Framework 3.5, you now have a single way to move
data — the Windows Communication Foundation (WCF). WCF provides you with the ability to build your
service one time and then expose this service in a multitude of ways (under different protocols even) by
just making changes within a configuration file. You will find that WCF is a powerful new way of
connecting disparate systems. Chapter 42, “ Windows Communication Foundation, ” covers this in detail.

An Introduction to Silverlight and its Features


The Silverlight Framework introduced by Microsoft provides a cross-browser and platform independent approach to implement the .Net framework for developing media and rich internet applications (RIA). The Silverlight enables to create the applications that can be installed on desktop and the Windows phone as well. It includes lots of new features such as Extensible Application Markup language (XAML) that can be used to design the application UI layouts. You can use any dynamic language to develop the application logics and functionality.

Features of Silverlight

Here is a list of features that the Silverlight serves to develop the rich media applications:
1. Rich user interface controls to design the interactive layouts by adding animations and cool effects.
2. It enables to implement cross-browser and cross-platform applications that run on almost all popular web browsers.
3. It supports video and audio streaming. It provides their quality enhancement features also such scaling video quality.
4. Deep image zooming enables to play with graphics that the users can zoom-in, zoom-out and turn their positions in the web browser directly.
5. The out-of-browser feature of Silverlight enables the users to install the application on their desktop instead of running it in web browser they can run it on their own computers.
6. Silverlight for Windows Phone provides a platform for developing the applications for windows phone.
7. It fetches and updates the data from any data source onto the web page without refreshing the whole page that provides better user friendly environment.

What is a Silverlight Plug-in?

Likewise Adobe flash player plugin for web browsers, Microsoft also provides a free Silverlight plugin for web browsers. If the user's computer does not already have the Silverlight plugin installed on it, then the browser prompts for installing the required plugin. When user allows installing it, the plugin automatically downloads and installs on the machine within a few seconds. After refreshing the web page, the Silverlight application starts running instantly.

Installing and Configuring Silverlight


The Silverlight is a new platform provided by the Microsoft as a part of .Net Framework and its SDK is freely available that can be installed and configured on the development machine. Its small applications can be developed by using a notepad but for efficient and faster productivity it is necessary to install proper development tools for building better Silverlight applications rapidly.
There are two categories of tools provided by the Microsoft such as for developing and designing the Silverlight applications. The development tools include Visual Studio 2010 or Visual Web Developer 2010 Express Edition. Additionally you can install Silverlight 4 Toolkit that includes ready to use interactive Silverlight controls. Apart from development there is one more tool meant for designing purposes isMicrosoft Expression Blend. It serves as a WYSIWYG designer tool that enables to design and apply animation effects flawlessly.

Silverlight Layouts and Panel Controls


The Layout means positioning of UI elements on the form. TheSilverlight provides an advanced of position the elements in the application. You can position the controls using absolute positioning method or dynamic layout system. The Absolute position enables to place the controls specified with their exact locations with respect to their parent container control. The Dynamic position of elements is based on the arrangement of controls wrapped inside relative to the parent container control. Both types of Silverlight layout systems are based on the position of child controls with respect to their container elements.  The Silverlight framework provides a set of Panel controls which serve as container controls to provide a well-defined layout to the Silverlight application forms or user controls. Following are the Silverlight Panel controls:
  1. Canvas
  2. Grid
  3. StackPanel

Silverlight Panel Controls and their Layout Behaviors

The Panel controls available in Silverlight enable to design complex layouts that may contain the stacked elements, absolute positioned elements or row/column based layout. Based on your UI design requirements you can choose one of the following container control:
1. Canvas: It defines container area within which you can place the controls by specifying their location with respect to top and left boundary of the parent canvas control. Almost each Silverlight control consists of properties such as Canvas.Top and Canvas.Left which accept integer type value to specify the distance between the associated control and the boundaries of the canvas panel control.

2. Grid: It defines a tabular layout containing a set of rows and columns. You can place the controls by specifying the row and column number of the Grid in which you want to display it. When controls are placed inside the Grid container, they inherit some Grid properties such asGrid.Column and Grid.Row. Both the properties accept integer type values as a zero based index of the respective column and the row as well.

3. StackPanel: It defines a stack based container for placing the controls in horizontally or vertically aligned pattern. You can set the value for Orientation property of StackPanel as Horizontal to arrange the child elements in a linear horizontal direction or can set its value toVertical for displaying them in vertical manner. Additionally a Marginproperty of child elements can be used to add the spacing between individual child controls.