<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Umair&#039;s Blog &#187; .NET</title>
	<atom:link href="http://umairsaeed.com/tag/net/feed/" rel="self" type="application/rss+xml" />
	<link>http://umairsaeed.com</link>
	<description></description>
	<lastBuildDate>Fri, 20 Jan 2012 16:28:51 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='umairsaeed.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Umair&#039;s Blog &#187; .NET</title>
		<link>http://umairsaeed.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://umairsaeed.com/osd.xml" title="Umair&#039;s Blog" />
	<atom:link rel='hub' href='http://umairsaeed.com/?pushpress=hub'/>
		<item>
		<title>Creating a Custom XAML TypeConverter</title>
		<link>http://umairsaeed.com/2010/02/03/creating-a-custom-xaml-typeconverter/</link>
		<comments>http://umairsaeed.com/2010/02/03/creating-a-custom-xaml-typeconverter/#comments</comments>
		<pubDate>Wed, 03 Feb 2010 14:47:29 +0000</pubDate>
		<dc:creator>Umair</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[XAML]]></category>

		<guid isPermaLink="false">http://umairsd.wordpress.com/2010/02/03/creating-a-custom-xaml-typeconverter/</guid>
		<description><![CDATA[TypeConverters provide a means of converting a String to the appropriate .NET type or a new instance when XAML is processed. I&#8217;ve already looked at how the XAML parser searches for TypeConverters (XAML and TypeConverters ) Now let&#8217;s take a &#8230; <a href="http://umairsaeed.com/2010/02/03/creating-a-custom-xaml-typeconverter/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=umairsaeed.com&amp;blog=9333327&amp;post=90&amp;subd=umairsd&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>TypeConverters provide a means of converting a String to the appropriate .NET type or a new instance when XAML is processed. I&#8217;ve already looked at how the XAML parser searches for TypeConverters (<a href="http://umairsaeed.com/2010/01/20/xaml-and-typeconverters-2/">XAML and TypeConverters</a> ) Now let&#8217;s take a look at how to create our custom TypeConverter. </p>
<p>At a minimum, for a class to conform to the Silverlight implementation of TypeConverters it must be a subclass of the TypeConverter class and must contain the following two members for converting from strings for XAML processing: </p>
<p>1. The class must override the <font face="Courier New"><a href="http://msdn.microsoft.com/en-us/library/y5th8ef6%28VS.96%29.aspx">CanConvertFrom(&#8230;)</a></font> method: </p>
<pre>
<pre class="brush: csharp;">
public virtual bool CanConvertFrom(
    ITypeDescriptorContext context,
    Type sourceType
)
</pre>
</pre>
<p>It must return true when the <font face="Courier New">sourceType</font> parameter is String, and otherwise defer to the base implementation. </p>
<p>2. The class must provide an implementation of <font face="Courier New"><a href="http://msdn.microsoft.com/en-us/library/zb260h9b%28VS.96%29.aspx">ConvertFrom(&#8230;)</a></font> method: </p>
<pre>
<pre class="brush: csharp;">
public virtual Object ConvertFrom(
    ITypeDescriptorContext context,
    CultureInfo culture,
    Object value
)
</pre>
</pre>
<p>To be usable as a TypeConverter implementation that supports XAML, this method must accept a string as the value parameter. If the string is valid, the returned object must support a cast to the type expected by the property. Otherwise it must return null. </p>
<p>The .NET specification for TypeConverters also contains two more key methods, which are <font face="Courier New">ConvertTo</font> and <font face="Courier New">CanConvertTo</font>. However, Silverlight 3 (as well as Silverlight 4 Beta) does not use <font face="Courier New">ConvertTo</font> and <font face="Courier New">CanConvertTo</font>, so you can skip these if your TypeConverter is for Silverlight&#8217;s XAML processing. It&#8217;s still a good idea to implement these two as a best practice for completing the wider interoperation functionality of the converter class. </p>
<p>&#160;</p>
<p><strong>Putting it all together: An Example:</strong></p>
<p>Suppose I have a custom Silverlight control called WidgetControl, that has a property called WidgetHeight. If you need to see how to add custom controls to your project, please check out my post &quot;<a href="http://umairsaeed.com/2010/01/27/adding-a-custom-silverlight-control/">Adding a Custom Silverlight Control</a>&quot;. I use this control in my XAML file as follows: </p>
<pre>
<pre class="brush: xml; auto-links: false;">
&lt;Custom:WidgetControl x:Name=&quot;widget&quot; WidgetHeight=&quot;2 inches&quot;/&gt;
</pre>
</pre>
<p>Somehow I need to handle the case where the unit of length is specified for the value of WidgetHeight property. This is done via a custom XAML TypeConverter called <font face="Courier New">CustomLengthConverter</font>, which is shown below: </p>
<pre>
<pre class="brush: csharp; wrap-lines: true;">
    public class CustomLengthConverter : TypeConverter
    {
        public override bool CanConvertFrom(
            ITypeDescriptorContext context, Type sourceType)
        {
            if (sourceType == typeof(string))
            {
                return true;
            }
            return base.CanConvertFrom(context, sourceType);
        }


        public override object ConvertFrom(ITypeDescriptorContext
                context, CultureInfo culture, object value)
        {

            if (value == null)
            {
                return new Double();
            }
            if (value is string)
            {
                string s = (string)value;
                if (s.Length == 0)
                {
                    return new Double();
                }

                string[] arguments = s.Split(' ');
                if (arguments.Length != 2)
                {
                    throw new ArgumentException(&quot;Value must have the format &lt;number length_unit&gt;&quot;);
                }
                else
                {
                    return InternalParseInput(arguments[0]);
                }
            }

            return base.ConvertFrom(context, culture, value);
        }


        public Double InternalParseInput(String inputString)
        {
            Double doubleValue;

            try
            {
                doubleValue = Double.Parse(inputString);
            }
            catch(Exception){
                doubleValue = new Double();
            }

            return doubleValue;
        }
    }
</pre>
</pre>
<p>Finally, in my WidgetControl class, I explicitly specify that the WidgetHeight property should use the CustomLengthConverter defined above: </p>
<pre>
<pre class="brush: csharp;">
    public partial class WidgetControl : UserControl
    {
	...

        [TypeConverter(typeof(CustomLengthConverter))]
        public Double WidgetHeight
        {
	   ...
        }
    }
</pre>
</pre>
<p>So every time my XAML for WidgetControl&#8217;s WidgetHeight property is parsed, the parser uses the <font face="Courier New">CustomLengthConverter</font> to convert the property value from String to the appropriate .NET type (Double)</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/umairsd.wordpress.com/90/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/umairsd.wordpress.com/90/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/umairsd.wordpress.com/90/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/umairsd.wordpress.com/90/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/umairsd.wordpress.com/90/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/umairsd.wordpress.com/90/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/umairsd.wordpress.com/90/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/umairsd.wordpress.com/90/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/umairsd.wordpress.com/90/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/umairsd.wordpress.com/90/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/umairsd.wordpress.com/90/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/umairsd.wordpress.com/90/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/umairsd.wordpress.com/90/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/umairsd.wordpress.com/90/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=umairsaeed.com&amp;blog=9333327&amp;post=90&amp;subd=umairsd&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://umairsaeed.com/2010/02/03/creating-a-custom-xaml-typeconverter/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/3d8419a4ace3305d6791158454f7f874?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">umairsd</media:title>
		</media:content>
	</item>
		<item>
		<title>XAML and TypeConverters</title>
		<link>http://umairsaeed.com/2010/01/20/xaml-and-typeconverters-2/</link>
		<comments>http://umairsaeed.com/2010/01/20/xaml-and-typeconverters-2/#comments</comments>
		<pubDate>Wed, 20 Jan 2010 14:24:00 +0000</pubDate>
		<dc:creator>Umair</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[XAML]]></category>

		<guid isPermaLink="false">http://umairsd.wordpress.com/2010/01/20/xaml-and-typeconverters-2/</guid>
		<description><![CDATA[In a XAML document, every element maps to an instance of a Silverlight (.NET) class. The properties of this instance can be set through attributes in the XAML file. There is a bit of a catch though. These attribute values &#8230; <a href="http://umairsaeed.com/2010/01/20/xaml-and-typeconverters-2/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=umairsaeed.com&amp;blog=9333327&amp;post=72&amp;subd=umairsd&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In a XAML document, every element maps to an instance of a Silverlight (.NET) class. The properties of this instance can be set through attributes in the XAML file. There is a bit of a catch though. These attribute values (in the XAML file) are in text form, whereas the corresponding Silverlight property is a .NET type. There needs to be a way to convert these String attribute values into corresponding .NET types. This is where TypeConverters come in. </p>
<p>In the context of Silverlight, a TypeConverter is a class which knows how to convert between a String and a .NET type. For each attribute in XAML, the parser follows a two-step process to find the appropriate type converter: </p>
<p>1. The XAML parser checks the declaration of the property that corresponds to the XML attribute, and tries to see if the property contains a TypeConverter attribute. The TypeConverter attribute specifies the class that can perform the type conversion from String to the .NET type of the property. The parser then uses the TypeConverter class to convert the XML attribute into a .NET type. </p>
<p>2. If the property declaration does not contain a TypeConverter attribute, the XAML parser looks at the property&#8217;s Type, to see if it containts TypeConverter attribute declaration. </p>
<p>3. If neither the property declaration or type (class) declaration have an associated TypeConverter attribute, the XAML parser returns an error. </p>
<p>Let&#8217;s consider a couple of examples to better illustrate this. Suppose we have two .NET Types called a Widget and WidgetBox, which are defined as follows: </p>
<pre><pre class="brush: csharp; gutter: false;"> 
    public class Widget{
        public Brush Foreground
        {
        }
    }


    public class WidgetBox
    {
        [System.ComponentModel.TypeConverter(typeof(CustomLengthConverter)]
        public Double Height
        {
        }
    }

    public class CustomLengthConverter : System.ComponentModel.TypeConverter
    {
        ...
    }
</pre></pre>
<p><strong>Example-1:</strong> </p>
<p>Consider the following XML element in the XAML file. </p>
<pre><pre class="brush: xml; auto-links: false; gutter: false;">
	&lt;WidgetBox Height=&quot;1in&quot; /&gt;
</pre></pre>
<p>1. When the XAML parser encounters this code, it checks the property declaration for Height. In this case, it finds a TypeConverter attribute for the Height property, which tells the parser to use the CustomLengthConverter class to convert the string &quot;1in&quot; to Double. So, this snippet of XAML code is equivalent to: </p>
<pre><pre class="brush: csharp; gutter: false;"> 
	WidgetBox wb = new WidgetBox();
	wb.Height = new CustomLengthConverter().ConvertFrom(&quot;1in&quot;);
</pre></pre>
<p><strong>Example-2:<br />
    <br /></strong>Here&#8217;s another snippet of XAML code: </p>
<pre><pre class="brush: xml; auto-links: false; gutter: false;">
	&lt;Widget Foreground=&quot;Blue&quot; /&gt;
</pre></pre>
<p>1. When XAML parser encounters this code, it first checks the property declaration for Foreground. There&#8217;s no TypeConverter associated with the Foreground property, so the parser moves to step-2. </p>
<p>2. Now the XAML parser checks the class declaration of the Foreground&#8217;s Type. In our example, the type of Foreground is Brush, and it turns out that the Brush class is decorated with the [TypeConverter(typeof(BrushConverter))] attribute declaration: </p>
<pre><pre class="brush: csharp; gutter: false;"> 
	[TypeConverter(typeof(BrushConverter))]
	public class Brush
	{
	...
	}
</pre></pre>
<p>In this case, the parser uses the BrushConverter class to convert the string &quot;Blue&quot; into a Brush .NET type. So this snippet of XAML is equivalent to: </p>
<pre><pre class="brush: csharp; gutter: false;">  
	Widget w = new Widget();
	w.Foreground = new BrushConverter().ConvertFrom(&amp;quot;Blue&amp;quot;);
</pre></pre>
<p>For more information about TypeConverters, check out <a href="http://msdn.microsoft.com/en-us/library/system.componentmodel.typeconverter.aspx">MSDN</a>. There&#8217;s also a lot of great information at <a href="http://blogs.windowsclient.net/rob_relyea/archive/2008/04/10/strings-to-things-or-how-xaml-interprets-attribute-values.aspx">Rob Relyea&#8217;s blog post</a> about TypeConverters</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/umairsd.wordpress.com/72/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/umairsd.wordpress.com/72/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/umairsd.wordpress.com/72/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/umairsd.wordpress.com/72/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/umairsd.wordpress.com/72/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/umairsd.wordpress.com/72/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/umairsd.wordpress.com/72/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/umairsd.wordpress.com/72/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/umairsd.wordpress.com/72/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/umairsd.wordpress.com/72/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/umairsd.wordpress.com/72/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/umairsd.wordpress.com/72/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/umairsd.wordpress.com/72/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/umairsd.wordpress.com/72/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=umairsaeed.com&amp;blog=9333327&amp;post=72&amp;subd=umairsd&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://umairsaeed.com/2010/01/20/xaml-and-typeconverters-2/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/3d8419a4ace3305d6791158454f7f874?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">umairsd</media:title>
		</media:content>
	</item>
		<item>
		<title>Silverlight – Getting started with XAML</title>
		<link>http://umairsaeed.com/2010/01/17/silverlight-getting-started-with-xaml/</link>
		<comments>http://umairsaeed.com/2010/01/17/silverlight-getting-started-with-xaml/#comments</comments>
		<pubDate>Sun, 17 Jan 2010 21:57:00 +0000</pubDate>
		<dc:creator>Umair</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[XAML]]></category>

		<guid isPermaLink="false">http://umairsd.wordpress.com/2010/01/17/silverlight-getting-started-with-xaml/</guid>
		<description><![CDATA[XAML stands for eXtensible Application Markup Language (pronounced zamm-uhl). It is an XML based markup language used to instantiate .NET objects. XAML was initially designed as part of Windows Presentation Foundation (WPF), and allows developers to define rich user interfaces. &#8230; <a href="http://umairsaeed.com/2010/01/17/silverlight-getting-started-with-xaml/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=umairsaeed.com&amp;blog=9333327&amp;post=60&amp;subd=umairsd&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>XAML stands for e<strong>X</strong>tensible <strong>A</strong>pplication <strong>M</strong>arkup <strong>L</strong>anguage (pronounced<em> zamm-uhl</em>). It is an XML based markup language used to instantiate .NET objects. XAML was initially designed as part of Windows Presentation Foundation (WPF), and allows developers to define rich user interfaces. A XAML file defines the elements that make up a content region. This enables a clean separation between UI and the business logic code. One big advantage of this separation is that the UI designers can focus on creating the user-interface in XAML (using tools such as <a href="http://www.microsoft.com/expression/">Microsoft&#8217;s Expression</a>), and the developers can then create the business objects corresponding to the UI.</p>
<p>XAML document has the following properties:</p>
<p>- Every element in a XAML documents maps to an instance of a Silverlight (.NET) class, and its name exactly matches that of the class.<br />
- The properties of each class can be set through attributes in the XAML file.<br />
- Similar to any XML document, a XAML element can contain nested elements.</p>
<p>For example, when we create a new Silverlight application (called SampleApplication) in Visual Studio 2010 (beta), we get the following skeleton XAML document:</p>
<p><pre class="brush: xml; auto-links: false;">
&lt;UserControl x:Class=&quot;SampleApplication.MainPage&quot;
    xmlns=&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;
    xmlns:x=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;
    xmlns:d=&quot;http://schemas.microsoft.com/expression/blend/2008&quot;
    xmlns:mc=&quot;http://schemas.openxmlformats.org/markup-compatibility/2006&quot;
    mc:Ignorable=&quot;d&quot;
    d:DesignHeight=&quot;300&quot; d:DesignWidth=&quot;400&quot;&gt;

    &lt;Grid x:Name=&quot;LayoutRoot&quot; Background=&quot;White&quot;&gt;

    &lt;/Grid&gt;
&lt;/UserControl&gt;
</pre></p>
<p>As I&#8217;ve mentioned before, XAML allows us to create user-interfaces. However, for the interface to be useful, it needs to connect to code (typically written in C#). To accomplish this, we need a way to connect the event handlers with the UI. Usually, every XAML file has a corresponding class with client-side C# code. This class is generated by the Class attribute in the XAML namespace. This attribute tells the Silverlight parser to create a new class with the specified name that derives from the class represented by the XML element. When the XAML code above is parsed, the parser creates a new class named <span style="font-family:Courier New;">SampleApplication.MainPage</span>, which derives from the <span style="font-family:Courier New;">UserControl</span> class. This class is in the file called <span style="font-family:Courier New;">MainPage.xaml.cs</span>:</p>
<p><pre class="brush: csharp; gutter: false;">
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace SampleApplication
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();
        }

    }
}
</pre></p>
<p>The class is <a href="http://msdn.microsoft.com/en-us/library/wa80x488%28VS.80%29.aspx">partial</a> , as it is split across two files. The code that we write goes into <span style="font-family:Courier New;">MainPage.xaml.cs</span>. The rest of the class definition contains auto-generated code and goes into a file called <span style="font-family:Courier New;">MainPage.g.cs</span>. In the solution, this file is located in <span style="font-family:Courier New;">obj\Debug</span> folder. For the above XAML code, the contents of this auto-generated file are as follows:</p>
<p><pre class="brush: csharp; gutter: false;">
using System;
using System.Windows;
using System.Windows.Automation;
using System.Windows.Automation.Peers;
using System.Windows.Automation.Provider;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Interop;
using System.Windows.Markup;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Resources;
using System.Windows.Shapes;
using System.Windows.Threading;

namespace SampleApplication {

    public partial class MainPage : System.Windows.Controls.UserControl {

        internal System.Windows.Controls.Grid LayoutRoot;

        private bool _contentLoaded;

        /// &lt;summary&gt;
        /// InitializeComponent
        /// &lt;/summary&gt;
        [System.Diagnostics.DebuggerNonUserCodeAttribute()]
        public void InitializeComponent() {
            if (_contentLoaded) {
                return;
            }
            _contentLoaded = true;
            System.Windows.Application.LoadComponent(this, new System.Uri(&quot;/SampleApplication;component/MainPage.xaml&quot;, System.UriKind.Relative));
            this.LayoutRoot = ((System.Windows.Controls.Grid)(this.FindName(&quot;LayoutRoot&quot;)));
        }
    }
}
</pre></p>
<p>Finally, a quick note about the Name attribute. If we want to access and manipulate Silverlight elements programmatically, XAML must include the Name attribute. This is useful if we want to change properties or attach and detach event handlers on the fly. In the above example, line-9 of the XAML file tells the XAML parser to add the following field to the autogenerated portion of the <span style="font-family:Courier New;">MainPage</span> class</p>
<p><pre class="brush: csharp; gutter: false;">
private System.Windows.Controls.Grid LayoutRoot;
</pre></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/umairsd.wordpress.com/60/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/umairsd.wordpress.com/60/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/umairsd.wordpress.com/60/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/umairsd.wordpress.com/60/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/umairsd.wordpress.com/60/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/umairsd.wordpress.com/60/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/umairsd.wordpress.com/60/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/umairsd.wordpress.com/60/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/umairsd.wordpress.com/60/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/umairsd.wordpress.com/60/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/umairsd.wordpress.com/60/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/umairsd.wordpress.com/60/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/umairsd.wordpress.com/60/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/umairsd.wordpress.com/60/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=umairsaeed.com&amp;blog=9333327&amp;post=60&amp;subd=umairsd&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://umairsaeed.com/2010/01/17/silverlight-getting-started-with-xaml/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/3d8419a4ace3305d6791158454f7f874?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">umairsd</media:title>
		</media:content>
	</item>
	</channel>
</rss>
