SIGN UP MEMBER LOGIN:    
ARTICLE

Introduction of code-behind XAML Silverlight

Posted by Abhimanyu Kumar Vatsa Articles | Silverlight with C# April 11, 2011
In this post, you will learn about the code-behind of XAML page.
Reader Level:


Introduction

Usually every XAML file has a corresponding code-behind page and the code-behind language can be C# (it is the default) or VB. Initially when we create a new project, the project selection windows have the option to choose the development language. Here it is:

XSil1.gif

Well, look at the screenshot given below, recall the Visual Studio ASP.Net development, we create new project and project explorer lists the files and a file named Default.aspx is the default for our entire web project (in general), in Blend MainPage.xaml has the same role here (in general but both are very different stocks, will talk later). Also recall web.config file, app.xaml same role here (in general but both are very different stocks, will talk later). We start our editing or development in Blend from MainPage.xaml page and it is very important to understand the logics of both pages.

XSil2.gif

XSil3.gif

Both screenshots has the same page code-front (bottom one) and code-behind (just above the bottom one) shown.

As in Code-Front

x:Class="SilverlightApplication1.MainPage"

In the above code, 'SilverlightApplication1' is the namespace name of this project and 'MainPage' is the class name of this project. Remember, the namespace name should always be the same as the project title and the class name should always be same as the file name in which we are writing code-behind (no use of extension name here).


Why we use additional namespaces like 'using System; etc…'?

In almost every code-behind file we see an already declared list of namespaces, what's these? We see at first glance, namespaces represented in C++ as "include <iostream.h>" or in VB "import System" or in C# "using System" these all appear in the very top lines. A namespace is just a grouping of related classes. It's a method of putting or using classes inside code. In java we use it as "package". Namespaces are a logical grouping rather than a physical grouping. A "using" alias makes it easier to qualify or identify a namespace or class in C#. Look at the above image that has the list of namespaces; all those appear by default. There is a huge list of additional namespaces in the .Net library that we will use as required.

XSil4.gif

The InitializeComponent() method plays a very important role in Silverlight; we should never delete the InitializeComponent() call from the constructor.

Be tuned for the next article.

HAVE A HAPPY CODING...

Login to add your contents and source code to this article
share this article :
post comment
 
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor
PREMIUM SPONSORS
  • Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
    ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
Become a Sponsor