<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://msmvps.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>LA.NET [EN] : Silverlight</title><link>http://msmvps.com/blogs/luisabreu/archive/tags/Silverlight/default.aspx</link><description>Tags: Silverlight</description><dc:language>en</dc:language><generator>CommunityServer 2008.5 SP2 (Build: 40407.4157)</generator><item><title>Markup extensions</title><link>http://msmvps.com/blogs/luisabreu/archive/2009/11/23/markup-extensions.aspx</link><pubDate>Mon, 23 Nov 2009 12:26:41 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1741745</guid><dc:creator>luisabreu</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/luisabreu/rsscomments.aspx?PostID=1741745</wfw:commentRss><comments>http://msmvps.com/blogs/luisabreu/archive/2009/11/23/markup-extensions.aspx#comments</comments><description>&lt;p&gt;Markup extensions allows you to extend the expressibility of XAML. You use markup extensions to escape the general treatment that attribute values get (by default, we’ve seen that they are treated as strings or that a &lt;a href="http://msmvps.com/blogs/luisabreu/archive/2009/11/18/type-converter-on-silverlight.aspx"&gt;type converter&lt;/a&gt; is used to convert them to the adequate type). Markup extension expressions are always delimited by the pair { }.&lt;/p&gt;  &lt;p&gt;Currently, the Silverlight’s XAML parser understands only four markup extensions:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Binding: used in data bound scenarios for getting the value of an object at run time. This extension is implemented by the &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.data.binding(VS.95).aspx"&gt;Binding&lt;/a&gt; class and you can set several of its property from XAML (ie, from the markup extension expression itself). We’ll return to this class in future posts, when we talk about data binding operations; &lt;/li&gt;    &lt;li&gt;StaticResource: used for setting the value of a property to a resource&amp;#160; already defined in a resource dictionary (resource dictionaries are used for saving objects by key and it can be used in both XAML and code). The current release of Silverlight does not have any managed code class for supporting this type of markup extension (in other words, this is implemented in unmanaged code); &lt;/li&gt;    &lt;li&gt;TemplateBinding: another binding which is implemented in unmanaged code only. You’ll use this binding in your templates when you want to link the value of a control’s property to the value of another object’s property of the templated control (once again, this is only intro stuff and we’ll come back to this topic in future posts); &lt;/li&gt;    &lt;li&gt;Null: used for setting the value of a property to null. You might find this markup extension odd at first, but the truth is that there’s no other way to set a property to null in XAML (don’t forget that passing string would probably result in using a type converter). Another interesting thing you should keep in mind is that not all properties have a default value of null (to understand this, we’ll need to go into dependency properties – and yes, that will be the topic of a future post). &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;If you’ve been doing some WPF development, you’ll probably be thinking that Silverlight is not as extensible as WPF. For starters, there is no &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.markup.markupextension.aspx"&gt;MarkupExtension&lt;/a&gt; base class (which is extended by all markup extensions). In practice, this means that you cannot create your own markup extensions. Finally, you should also notice that unlike WPF, you can only use markup extensions with the attribute value syntax. Again, this is happening due to the limitations I’ve mentioned before (Silverlight must be small and we can’t forget that it runs across several platforms/browsers)&lt;/p&gt;  &lt;p&gt;I guess that it’s time to see an example. We’ll get started with the StaticResource markup extension:&lt;/p&gt;  &lt;pre style="background-color:black;" class="code"&gt;&lt;span style="color:#a1b070;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#d6d694;"&gt;Canvas&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color:#d6d694;"&gt;Canvas.Resources&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;&amp;gt;
        &amp;lt;&lt;/span&gt;&lt;span style="color:#d6d694;"&gt;SolidColorBrush &lt;/span&gt;&lt;span style="color:#009b00;"&gt;x&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;:&lt;/span&gt;&lt;span style="color:#009b00;"&gt;Key&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;=&lt;/span&gt;&lt;span style="color:#44b1e3;"&gt;&amp;quot;brush&amp;quot; &lt;/span&gt;&lt;span style="color:#009b00;"&gt;Color&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;=&lt;/span&gt;&lt;span style="color:#44b1e3;"&gt;&amp;quot;Green&amp;quot; &lt;/span&gt;&lt;span style="color:#a1b070;"&gt;/&amp;gt;
    &amp;lt;/&lt;/span&gt;&lt;span style="color:#d6d694;"&gt;Canvas.Resources&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color:#d6d694;"&gt;Button &lt;/span&gt;&lt;span style="color:#009b00;"&gt;Content&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;=&lt;/span&gt;&lt;span style="color:#44b1e3;"&gt;&amp;quot;Say hi&amp;quot;
        &lt;/span&gt;&lt;span style="color:#009b00;"&gt;Background&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color:cyan;"&gt;StaticResource &lt;/span&gt;&lt;span style="color:#ff80c0;"&gt;brush&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;}&lt;/span&gt;&lt;span style="color:#44b1e3;"&gt;&amp;quot; &lt;/span&gt;&lt;span style="color:#a1b070;"&gt;/&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="color:#d6d694;"&gt;Canvas&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;In the previous snippet, I’ve started by creating a new Canvas resource brush and I’ve identified it with the name brush. This is all you need to be able to reuse that resource in all the Canvas’ children objects’ properties that expect a brush (in the previous example, I’ve used that resource to fill the background color of a button). Resource dictionary usage has some gotchas, but I’ll leave that for a future post (after all, the main objective of this post is to look at markup extensions).&lt;/p&gt;

&lt;p&gt;StaticResource and Binding markup extensions expect only a single value. However, Binding is implemented through a managed class and if you check its definition, you’ll see that it has several properties which you can also set from XAML. In this case, the syntax is simple: you can specify a value for the “default” property (which is &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.data.binding.path(VS.95).aspx"&gt;Path&lt;/a&gt;, in the case of the Binding markup extension) and you should indicate all the other properties through the key=value pair entries (separated by comma). For instance, here’s an example of how you can set a binding:&lt;/p&gt;

&lt;pre style="background-color:black;" class="code"&gt;&lt;span style="color:#a1b070;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#d6d694;"&gt;TextBlock &lt;/span&gt;&lt;span style="color:#009b00;"&gt;Text&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color:cyan;"&gt;Binding &lt;/span&gt;&lt;span style="color:#ff80c0;"&gt;Content&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;, &lt;/span&gt;&lt;span style="color:#ff80c0;"&gt;ElementName&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;=&lt;/span&gt;&lt;span style="color:#e8e8e8;"&gt;origin&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;}&lt;/span&gt;&lt;span style="color:#44b1e3;"&gt;&amp;quot; &lt;/span&gt;&lt;span style="color:#a1b070;"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;In the previous snippet, I’m binding the value of the Text property to another element defined through XAML which is named origin (I guess it could be a button since it has&amp;#160; a Content property). There’s lot of things to say about bindings but for now I’m only worried in showing you how to use them from XAML (through the markup extension syntax).&lt;/p&gt;

&lt;p&gt;Before ending up, there’s still time for one more topic: escaping the { } in attributes. By default, whenever you pass the pair { } to an attribute value, the XAML parser will interpret it as a markup extension. If you need to set the value of an attribute to a value which contains that { } pair, you’ll need to escape it. Here’s how:&lt;/p&gt;

&lt;pre style="background-color:black;" class="code"&gt;&lt;span style="color:#a1b070;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#d6d694;"&gt;TextBlock &lt;/span&gt;&lt;span style="color:#009b00;"&gt;Text&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;=&lt;/span&gt;&lt;span style="color:#44b1e3;"&gt;&amp;quot;{}{Binding Content, ElementName=origin}&amp;quot; &lt;/span&gt;&lt;span style="color:#a1b070;"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;As you can see, using the {} pair at the beginning of the attribute’s value is all that it takes to escape the rest of the expression. If you put the previous XAML in a user control, you’ll see the {Binding….} text on the browser when you load that&amp;#160; control.&lt;/p&gt;

&lt;p&gt;I’ve only been playing with Silverlight for a few days (and I really haven’t done any real work with it). Even though it has lots of potentials, I must confess that I’m a little disappointed with the gotchas I’ve already found. I guess that they won’t matter much if you’re using a tool like Blend for creating the interface, but I must say that all these little things which don’t always work as expected are starting to make me think that I should probably be working with WPF instead where everything makes sense and works as expected…&lt;/p&gt;

&lt;p&gt;And that’s it for now. Stay tuned for more on Silverlight.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1741745" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/luisabreu/archive/tags/Silverlight/default.aspx">Silverlight</category><category domain="http://msmvps.com/blogs/luisabreu/archive/tags/XAML/default.aspx">XAML</category></item><item><title>XAML: what about events?</title><link>http://msmvps.com/blogs/luisabreu/archive/2009/11/19/xaml-what-about-events.aspx</link><pubDate>Thu, 19 Nov 2009 12:54:45 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1740755</guid><dc:creator>luisabreu</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/luisabreu/rsscomments.aspx?PostID=1740755</wfw:commentRss><comments>http://msmvps.com/blogs/luisabreu/archive/2009/11/19/xaml-what-about-events.aspx#comments</comments><description>&lt;p&gt;A friend of mine asked me about events and XAML: can we setup event handlers in XAML? And the answer is, yes, you can. Here’s a quick example of how you can handle the click event of a button:&lt;/p&gt;  &lt;pre style="background-color:black;" class="code"&gt;&lt;span style="color:#a1b070;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#d6d694;"&gt;Button &lt;/span&gt;&lt;span style="color:#009b00;"&gt;Click&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;=&lt;/span&gt;&lt;span style="color:#44b1e3;"&gt;&amp;quot;Button_Click&amp;quot;&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#d6d694;"&gt;Button&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;And yes, you must define the Button_Click method in your code-behind file (note that you could do it inline – ie, in the XAML file – if you’re using WPF). I must confess that I’m not really a fan of this approach since I prefer to put all my code in the code-behind file. For making it work, I’ll need to change the previous code slightly by adding a name to the button:&lt;/p&gt;

&lt;pre style="background-color:black;" class="code"&gt;&lt;span style="color:#a1b070;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#d6d694;"&gt;Button &lt;/span&gt;&lt;span style="color:#009b00;"&gt;x&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;:&lt;/span&gt;&lt;span style="color:#009b00;"&gt;Name&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;=&lt;/span&gt;&lt;span style="color:#44b1e3;"&gt;&amp;quot;bt&amp;quot;&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#d6d694;"&gt;Button&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;And now, from within the constructor, I can setup my event handler like this:&lt;/p&gt;

&lt;pre style="background-color:black;" class="code"&gt;&lt;span style="color:#e8e8e8;"&gt;bt&lt;/span&gt;&lt;span style="color:#80ff00;"&gt;.&lt;/span&gt;&lt;span style="color:#e8e8e8;"&gt;Click &lt;/span&gt;&lt;span style="color:#80ff00;"&gt;+= &lt;/span&gt;&lt;span style="color:#e8e8e8;"&gt;Button_Click&lt;/span&gt;&lt;span style="color:#a79a86;"&gt;;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Final note: in the real world, I’ll probably end up with a Lambda expression for simple handlers. As you can see, setting up handlers from the XAML is possible (the syntax is the same as you’ve got for props) but I don’t really recommend it. And that’s it for now. In the next post, we’ll talk about Silverlight’s markup extension support. Stay tuned.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1740755" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/luisabreu/archive/tags/Silverlight/default.aspx">Silverlight</category><category domain="http://msmvps.com/blogs/luisabreu/archive/tags/XAML/default.aspx">XAML</category></item><item><title>How to build types that can be consumed from XAML</title><link>http://msmvps.com/blogs/luisabreu/archive/2009/11/19/how-to-build-types-that-can-be-consumed-from-xaml.aspx</link><pubDate>Thu, 19 Nov 2009 10:32:43 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1740713</guid><dc:creator>luisabreu</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/luisabreu/rsscomments.aspx?PostID=1740713</wfw:commentRss><comments>http://msmvps.com/blogs/luisabreu/archive/2009/11/19/how-to-build-types-that-can-be-consumed-from-xaml.aspx#comments</comments><description>&lt;p&gt;Now that you &lt;a href="http://msmvps.com/blogs/luisabreu/archive/2009/11/19/associating-xaml-namespaces-to-clr-namespaces.aspx"&gt;know&lt;/a&gt; how to use custom types in XAML, you might be wondering if there are any thing you should keep in mind when designing new types that should be consumed from XAML. I’ve already &lt;a href="http://msmvps.com/blogs/luisabreu/archive/2009/11/18/xaml-and-collections.aspx"&gt;said&lt;/a&gt; before that collection properties need to have a getter that return a valid instance of an object. But there’s more. Here are a few things you should consider when designing types for being consumed from XAML:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Elements can only be public classes which have a public parameterless constructor (notice that nested classes aren’t supported);&lt;/li&gt;    &lt;li&gt;structs are usable from XAML too (consider using a type converter in some scenarios where you don’t want to use the default constructor to initialize the struct)&lt;/li&gt;    &lt;li&gt;non-collections properties which reference objects (ie, not primitive types) should ensure that the type has a default constructor (or that the type or property that is being defined has an adequate type converter);&lt;/li&gt;    &lt;li&gt;you should use type converters when you’re using a reference type which does not have a default constructor (or when you’ve used an abstract type as the type of a property).&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Regarding collections, you’ve already &lt;a href="http://msmvps.com/blogs/luisabreu/archive/2009/11/18/xaml-and-collections.aspx"&gt;seen&lt;/a&gt; the requisites for using them from XAML: the type should implement the IList or the IDictionary/IDictionary&amp;lt;TKey, TValue&amp;gt; interfaces.&lt;/p&gt;  &lt;p&gt;And I guess this sums it up quite nicely. Stay tuned for more on Silverlight.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1740713" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/luisabreu/archive/tags/Silverlight/default.aspx">Silverlight</category><category domain="http://msmvps.com/blogs/luisabreu/archive/tags/XAML/default.aspx">XAML</category></item><item><title>Associating XAML namespaces to CLR namespaces</title><link>http://msmvps.com/blogs/luisabreu/archive/2009/11/19/associating-xaml-namespaces-to-clr-namespaces.aspx</link><pubDate>Thu, 19 Nov 2009 10:10:51 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1740708</guid><dc:creator>luisabreu</dc:creator><slash:comments>2</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/luisabreu/rsscomments.aspx?PostID=1740708</wfw:commentRss><comments>http://msmvps.com/blogs/luisabreu/archive/2009/11/19/associating-xaml-namespaces-to-clr-namespaces.aspx#comments</comments><description>&lt;p&gt;Take a look at the following (simple) XAML:&lt;/p&gt;  &lt;pre style="background-color:black;" class="code"&gt;&lt;span style="color:#a1b070;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#d6d694;"&gt;UserControl &lt;/span&gt;&lt;span style="color:#009b00;"&gt;x&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;:&lt;/span&gt;&lt;span style="color:#009b00;"&gt;Class&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;=&lt;/span&gt;&lt;span style="color:#44b1e3;"&gt;&amp;quot;SilverlightApplication1.MainPage&amp;quot;
    &lt;/span&gt;&lt;span style="color:#009b00;"&gt;xmlns&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;=&lt;br /&gt;&lt;/span&gt;&lt;span style="color:#44b1e3;"&gt;&amp;quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&amp;quot;
    &lt;/span&gt;&lt;span style="color:#009b00;"&gt;xmlns&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;:&lt;/span&gt;&lt;span style="color:#009b00;"&gt;x&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;=&lt;/span&gt;&lt;span style="color:#44b1e3;"&gt;&amp;quot;http://schemas.microsoft.com/winfx/2006/xaml&amp;quot;&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color:#d6d694;"&gt;Canvas &lt;/span&gt;&lt;span style="color:#009b00;"&gt;x&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;:&lt;/span&gt;&lt;span style="color:#009b00;"&gt;Name&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;=&lt;/span&gt;&lt;span style="color:#44b1e3;"&gt;&amp;quot;myCanvas&amp;quot;&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;&amp;gt;
    &amp;lt;/&lt;/span&gt;&lt;span style="color:#d6d694;"&gt;Canvas&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="color:#d6d694;"&gt;UserControl&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;When I started talking about XAML, I &lt;a href="http://msmvps.com/blogs/luisabreu/archive/2009/11/16/introducing-xaml.aspx"&gt;said&lt;/a&gt; that the default XAML namespace is associated to several controls. You might be a little curious on how this is done. By using Reflector, you’ll see that many of the Silverlight assemblies associate CLR namespaces to XAML namespaces through the &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.markup.xmlnsdefinitionattribute(VS.95).aspx"&gt;XmlnsDefinitionAttribute&lt;/a&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://msmvps.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/luisabreu.metablogapi/4722.xmlnsdefinitionattribute_5F00_6FA6D7C8.jpg"&gt;&lt;img style="border-right-width:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" title="xmlnsdefinitionattribute" border="0" alt="xmlnsdefinitionattribute" src="http://msmvps.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/luisabreu.metablogapi/0020.xmlnsdefinitionattribute_5F00_thumb_5F00_05411066.jpg" width="322" height="296" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;You’ll typically find this attribute in most assemblies that have been thought with Silverlight and WPF in mind. Notice, though, that its use isn’t mandatory to map a CLR namespace to XAML namespace because Silverlight (and WPF) supports a special mechanism for doing that. For instance, suppose you’ve got a type called BeautifulGrid, defined in the CLR Test namespace, in a Dumb assembly. Now, when you build the assembly, you didn’t knew anything about the &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.markup.xmlnsdefinitionattribute(VS.95).aspx"&gt;XmlnDefinitionAttribute&lt;/a&gt;. How can you use the BeautifulGrid in your XAML file? Here’s the answer:&lt;/p&gt;

&lt;pre style="background-color:black;" class="code"&gt;&lt;span style="color:#a1b070;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#d6d694;"&gt;UserControl &lt;/span&gt;&lt;span style="color:#009b00;"&gt;x&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;:&lt;/span&gt;&lt;span style="color:#009b00;"&gt;Class&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;=&lt;/span&gt;&lt;span style="color:#44b1e3;"&gt;&amp;quot;SilverlightApplication1.MainPage&amp;quot;
    &lt;/span&gt;&lt;span style="color:#009b00;"&gt;xmlns&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;=&lt;br /&gt;&lt;/span&gt;&lt;span style="color:#44b1e3;"&gt;&amp;quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&amp;quot;
    &lt;/span&gt;&lt;span style="color:#009b00;"&gt;xmlns&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;:&lt;/span&gt;&lt;span style="color:#009b00;"&gt;x&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;=&lt;/span&gt;&lt;span style="color:#44b1e3;"&gt;&amp;quot;http://schemas.microsoft.com/winfx/2006/xaml&amp;quot;
    &lt;/span&gt;&lt;span style="color:#009b00;"&gt;xmlns&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;:&lt;/span&gt;&lt;span style="color:#009b00;"&gt;my&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;=&lt;/span&gt;&lt;span style="color:#44b1e3;"&gt;&amp;quot;clr-namespace:Test;assembly=Dumb&amp;quot;&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color:#d6d694;"&gt;Canvas &lt;/span&gt;&lt;span style="color:#009b00;"&gt;x&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;:&lt;/span&gt;&lt;span style="color:#009b00;"&gt;Name&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;=&lt;/span&gt;&lt;span style="color:#44b1e3;"&gt;&amp;quot;myCanvas&amp;quot;&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;&amp;gt;
        &amp;lt;&lt;/span&gt;&lt;span style="color:#d6d694;"&gt;my&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;:&lt;/span&gt;&lt;span style="color:#d6d694;"&gt;BeautifulGrid&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;&amp;gt;            
        &amp;lt;/&lt;/span&gt;&lt;span style="color:#d6d694;"&gt;my&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;:&lt;/span&gt;&lt;span style="color:#d6d694;"&gt;BeautifulGrid&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;&amp;gt;
    &amp;lt;/&lt;/span&gt;&lt;span style="color:#d6d694;"&gt;Canvas&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="color:#d6d694;"&gt;UserControl&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;There are some interesting gotchas&amp;#160; you should keep in mind when using this syntax:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;the clr-namespace key is separated from its associated value by a semi-colon (:) while the assembly part of the expression uses an equal sign (=)&lt;/li&gt;

  &lt;li&gt;this is one of those places where you *can’t* use white spaces for improved readability;&lt;/li&gt;

  &lt;li&gt;you can omit the assembly part if the namespace you want to use is in the same assembly as the “current” XAML file.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Even though Silverlight supports the &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.markup.xmlnsdefinitionattribute(VS.95).aspx"&gt;XmlnsDefinitionAttribute&lt;/a&gt;, the truth is that it doesn’t really play an important role for using custom types in Silverlight. The recommended approach for using custom types in XAML is to use the clr-namespace approach I’ve showed above.&lt;/p&gt;

&lt;p&gt;And that’s it for now. Stay tuned for more in Silverlight.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1740708" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/luisabreu/archive/tags/Silverlight/default.aspx">Silverlight</category><category domain="http://msmvps.com/blogs/luisabreu/archive/tags/XAML/default.aspx">XAML</category></item><item><title>XAML languages features</title><link>http://msmvps.com/blogs/luisabreu/archive/2009/11/18/xaml-languages-features.aspx</link><pubDate>Wed, 18 Nov 2009 15:15:15 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1740495</guid><dc:creator>luisabreu</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/luisabreu/rsscomments.aspx?PostID=1740495</wfw:commentRss><comments>http://msmvps.com/blogs/luisabreu/archive/2009/11/18/xaml-languages-features.aspx#comments</comments><description>&lt;p&gt;As I’ve &lt;a href="http://msmvps.com/blogs/luisabreu/archive/2009/11/18/xaml-and-collections.aspx"&gt;said&lt;/a&gt; before, Silverlight supports only a subset of the existing XAML keywords you can use in WPF. Here’s the list of keywords you can use in your Silverlight:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;x:Class: you can apply this attribute to the root element of the XAML file (or object tree) that is going to be “compiled”. When you apply this attribute, you’ll end up creating a partial class (named after the value you’ve passed to the attribute) which is joined with the associated code-behind file. Even though you don’t really have to use this attribute, the truth is that you’ll probably use them in 99% of your XAML files; &lt;/li&gt;    &lt;li&gt;x:Key: as you’ve seen in the previous &lt;a href="http://msmvps.com/blogs/luisabreu/archive/2009/11/18/xaml-and-collections.aspx"&gt;post&lt;/a&gt;, you can use this attribute to set the key of a dictionary’s entry of a resource dictionary; &lt;/li&gt;    &lt;li&gt;x:Name: used for identifying an object so that it can be easily recovered from the code-behind file. The “practical effect” of using this attribute is that you’ll end up having a field in the code-behind file which references the element you’ve defined on the XAML file. As you can see on the &lt;a href="http://msdn.microsoft.com/en-us/library/cc189028(VS.95).aspx"&gt;docs&lt;/a&gt;, you’re limited in the values you can pass to this attribute. It goes without saying that you must ensure uniqueness through the names you give to the elements; &lt;/li&gt;    &lt;li&gt;x:Null: this *extension* is used for setting the value of a property to null. You can use this extension with the property element or attribute syntax. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;The best way to understand these attributes is to build a demo user control and see what happens after everything is compiled. For instance, lets assume that we’re adding a new Silverlight User Control to an existing Silverlight application (this will let me show what happens when you use the x:Class and x:Name attributes). By doing that, we end up with two files: a XAML and its corresponding code-behind CS file (shown in the next figure).&lt;/p&gt;  &lt;p&gt;&lt;a href="http://msmvps.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/luisabreu.metablogapi/5305.xamlandcodebehind_5F00_1DE403E0.jpg"&gt;&lt;img style="border-right-width:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" title="xamlandcodebehind" border="0" alt="xamlandcodebehind" src="http://msmvps.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/luisabreu.metablogapi/4401.xamlandcodebehind_5F00_thumb_5F00_1DB45420.jpg" width="244" height="53" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Here’s the default generated XAML (I’ve removed the unnecessary namespaces):&lt;/p&gt;  &lt;pre style="background-color:black;" class="code"&gt;&lt;span style="color:#a1b070;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#d6d694;"&gt;UserControl 
 &lt;/span&gt;&lt;span style="color:#009b00;"&gt;x&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;:&lt;/span&gt;&lt;span style="color:#009b00;"&gt;Class&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;=&lt;/span&gt;&lt;span style="color:#44b1e3;"&gt;&amp;quot;SilverlightApplication1.SilverlightControl1&amp;quot;
 &lt;/span&gt;&lt;span style="color:#009b00;"&gt;xmlns&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;=&lt;br /&gt;&lt;/span&gt;&lt;span style="color:#44b1e3;"&gt;&amp;quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&amp;quot;
 &lt;/span&gt;&lt;span style="color:#009b00;"&gt;xmlns&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;:&lt;/span&gt;&lt;span style="color:#009b00;"&gt;x&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;=&lt;/span&gt;&lt;span style="color:#44b1e3;"&gt;&amp;quot;http://schemas.microsoft.com/winfx/2006/xaml&amp;quot;&lt;/span&gt;&lt;span style="color:#44b1e3;"&gt;
 &lt;/span&gt;&lt;span style="color:#009b00;"&gt;mc&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;:&lt;/span&gt;&lt;span style="color:#009b00;"&gt;Ignorable&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;=&lt;/span&gt;&lt;span style="color:#44b1e3;"&gt;&amp;quot;d&amp;quot;
 &lt;/span&gt;&lt;span style="color:#009b00;"&gt;d&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;:&lt;/span&gt;&lt;span style="color:#009b00;"&gt;DesignHeight&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;=&lt;/span&gt;&lt;span style="color:#44b1e3;"&gt;&amp;quot;300&amp;quot; &lt;/span&gt;&lt;span style="color:#009b00;"&gt;d&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;:&lt;/span&gt;&lt;span style="color:#009b00;"&gt;DesignWidth&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;=&lt;/span&gt;&lt;span style="color:#44b1e3;"&gt;&amp;quot;400&amp;quot;&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;&amp;gt;    
 &amp;lt;&lt;/span&gt;&lt;span style="color:#d6d694;"&gt;Grid &lt;/span&gt;&lt;span style="color:#009b00;"&gt;x&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;:&lt;/span&gt;&lt;span style="color:#009b00;"&gt;Name&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;=&lt;/span&gt;&lt;span style="color:#44b1e3;"&gt;&amp;quot;LayoutRoot&amp;quot; &lt;/span&gt;&lt;span style="color:#009b00;"&gt;Background&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;=&lt;/span&gt;&lt;span style="color:#44b1e3;"&gt;&amp;quot;White&amp;quot;&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;&amp;gt;
 &amp;lt;/&lt;/span&gt;&lt;span style="color:#d6d694;"&gt;Grid&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="color:#d6d694;"&gt;UserControl&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;If you look at the properties of the XAML file, you’ll see that it looks like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://msmvps.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/luisabreu.metablogapi/1185.xamlprops_5F00_693381D7.jpg"&gt;&lt;img style="border-right-width:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" title="xamlprops" border="0" alt="xamlprops" src="http://msmvps.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/luisabreu.metablogapi/3821.xamlprops_5F00_thumb_5F00_12E6D6FE.jpg" width="244" height="167" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;The default configuration ends up embedding the XAML file in the assembly (check the next image):&lt;/p&gt;

&lt;p&gt;&lt;a href="http://msmvps.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/luisabreu.metablogapi/7127.xamlresources_5F00_11DEC154.jpg"&gt;&lt;img style="border-right-width:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" title="xamlresources" border="0" alt="xamlresources" src="http://msmvps.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/luisabreu.metablogapi/6560.xamlresources_5F00_thumb_5F00_0F558F96.jpg" width="281" height="161" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;You’ll also get a new C# file (.g.cs) from the XAML “compilation” (onde again, I’ve edited the code before pasting it here):&lt;/p&gt;

&lt;pre style="background-color:black;" class="code"&gt;&lt;span style="color:#d6d694;"&gt;namespace &lt;/span&gt;&lt;span style="color:#e8e8e8;"&gt;SilverlightApplication1 &lt;/span&gt;&lt;span style="color:#a79a86;"&gt;{
 &lt;/span&gt;&lt;span style="color:#d6d694;"&gt;public partial class &lt;/span&gt;&lt;span style="color:#009b00;"&gt;SilverlightControl1 &lt;/span&gt;&lt;span style="color:#a79a86;"&gt;: &lt;br /&gt;                   &lt;/span&gt;&lt;span style="color:#e8e8e8;"&gt;System&lt;/span&gt;&lt;span style="color:#80ff00;"&gt;.&lt;/span&gt;&lt;span style="color:#e8e8e8;"&gt;Windows&lt;/span&gt;&lt;span style="color:#80ff00;"&gt;.&lt;/span&gt;&lt;span style="color:#e8e8e8;"&gt;Controls&lt;/span&gt;&lt;span style="color:#80ff00;"&gt;.&lt;/span&gt;&lt;span style="color:#e8e8e8;"&gt;UserControl &lt;/span&gt;&lt;span style="color:#a79a86;"&gt;{
  &lt;/span&gt;&lt;span style="color:#d6d694;"&gt;internal &lt;/span&gt;&lt;span style="color:#e8e8e8;"&gt;System&lt;/span&gt;&lt;span style="color:#80ff00;"&gt;.&lt;/span&gt;&lt;span style="color:#e8e8e8;"&gt;Windows&lt;/span&gt;&lt;span style="color:#80ff00;"&gt;.&lt;/span&gt;&lt;span style="color:#e8e8e8;"&gt;Controls&lt;/span&gt;&lt;span style="color:#80ff00;"&gt;.&lt;/span&gt;&lt;span style="color:#e8e8e8;"&gt;Grid LayoutRoot&lt;/span&gt;&lt;span style="color:#a79a86;"&gt;;
  &lt;/span&gt;&lt;span style="color:#d6d694;"&gt;private bool &lt;/span&gt;&lt;span style="color:#e8e8e8;"&gt;_contentLoaded&lt;/span&gt;&lt;span style="color:#a79a86;"&gt;;
  [&lt;/span&gt;&lt;span style="color:#e8e8e8;"&gt;System&lt;/span&gt;&lt;span style="color:#80ff00;"&gt;.&lt;/span&gt;&lt;span style="color:#e8e8e8;"&gt;Diagnostics&lt;/span&gt;&lt;span style="color:#80ff00;"&gt;.&lt;/span&gt;&lt;span style="color:#009b00;"&gt;DebuggerNonUserCodeAttribute&lt;/span&gt;&lt;span style="color:#a79a86;"&gt;()]
  &lt;/span&gt;&lt;span style="color:#d6d694;"&gt;public void &lt;/span&gt;&lt;span style="color:#e8e8e8;"&gt;InitializeComponent&lt;/span&gt;&lt;span style="color:#a79a86;"&gt;() {
     &lt;/span&gt;&lt;span style="color:#d6d694;"&gt;if &lt;/span&gt;&lt;span style="color:#a79a86;"&gt;(&lt;/span&gt;&lt;span style="color:#e8e8e8;"&gt;_contentLoaded&lt;/span&gt;&lt;span style="color:#a79a86;"&gt;) {
                &lt;/span&gt;&lt;span style="color:#d6d694;"&gt;return&lt;/span&gt;&lt;span style="color:#a79a86;"&gt;;
     }
     &lt;/span&gt;&lt;span style="color:#e8e8e8;"&gt;_contentLoaded &lt;/span&gt;&lt;span style="color:#80ff00;"&gt;= &lt;/span&gt;&lt;span style="color:#d6d694;"&gt;true&lt;/span&gt;&lt;span style="color:#a79a86;"&gt;;
     &lt;/span&gt;&lt;span style="color:#e8e8e8;"&gt;System&lt;/span&gt;&lt;span style="color:#80ff00;"&gt;.&lt;/span&gt;&lt;span style="color:#e8e8e8;"&gt;Windows&lt;/span&gt;&lt;span style="color:#80ff00;"&gt;.&lt;/span&gt;&lt;span style="color:#e8e8e8;"&gt;Application&lt;/span&gt;&lt;span style="color:#80ff00;"&gt;.&lt;/span&gt;&lt;span style="color:#e8e8e8;"&gt;LoadComponent&lt;/span&gt;&lt;span style="color:#a79a86;"&gt;(&lt;br /&gt;         &lt;/span&gt;&lt;span style="color:#d6d694;"&gt;this&lt;/span&gt;&lt;span style="color:#a79a86;"&gt;, &lt;/span&gt;&lt;span style="color:#d6d694;"&gt;new &lt;/span&gt;&lt;span style="color:#e8e8e8;"&gt;System&lt;/span&gt;&lt;span style="color:#80ff00;"&gt;.&lt;/span&gt;&lt;span style="color:#e8e8e8;"&gt;Uri&lt;/span&gt;&lt;span style="color:#a79a86;"&gt;(&lt;br /&gt;                     &lt;/span&gt;&lt;span style="color:#44b1e3;"&gt;&amp;quot;/SilverlightApplication1;” + &lt;br /&gt;                     “component/SilverlightControl1.xaml&amp;quot;&lt;/span&gt;&lt;span style="color:#a79a86;"&gt;, &lt;br /&gt;&lt;/span&gt;&lt;span style="color:#e8e8e8;"&gt;                     System&lt;/span&gt;&lt;span style="color:#80ff00;"&gt;.&lt;/span&gt;&lt;span style="color:#e8e8e8;"&gt;UriKind&lt;/span&gt;&lt;span style="color:#80ff00;"&gt;.&lt;/span&gt;&lt;span style="color:#e8e8e8;"&gt;Relative&lt;/span&gt;&lt;span style="color:#a79a86;"&gt;));
      &lt;/span&gt;&lt;span style="color:#d6d694;"&gt;this&lt;/span&gt;&lt;span style="color:#80ff00;"&gt;.&lt;/span&gt;&lt;span style="color:#e8e8e8;"&gt;LayoutRoot &lt;/span&gt;&lt;span style="color:#80ff00;"&gt;= &lt;/span&gt;&lt;span style="color:#a79a86;"&gt;((&lt;/span&gt;&lt;span style="color:#e8e8e8;"&gt;System&lt;/span&gt;&lt;span style="color:#80ff00;"&gt;.&lt;/span&gt;&lt;span style="color:#e8e8e8;"&gt;Windows&lt;/span&gt;&lt;span style="color:#80ff00;"&gt;.&lt;/span&gt;&lt;span style="color:#e8e8e8;"&gt;Controls&lt;/span&gt;&lt;span style="color:#80ff00;"&gt;.&lt;/span&gt;&lt;span style="color:#e8e8e8;"&gt;Grid&lt;/span&gt;&lt;span style="color:#a79a86;"&gt;)&lt;br /&gt;                             (&lt;/span&gt;&lt;span style="color:#d6d694;"&gt;this&lt;/span&gt;&lt;span style="color:#80ff00;"&gt;.&lt;/span&gt;&lt;span style="color:#e8e8e8;"&gt;FindName&lt;/span&gt;&lt;span style="color:#a79a86;"&gt;(&lt;/span&gt;&lt;span style="color:#44b1e3;"&gt;&amp;quot;LayoutRoot&amp;quot;&lt;/span&gt;&lt;span style="color:#a79a86;"&gt;)));
  }
 }
}&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;There are several interesting things going on here:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;the x:Class attribute is responsible for the creation of the partial class defined in the .g.cs file; &lt;/li&gt;

  &lt;li&gt;all the named elements (ie, all the elements that use the x:Name attribute) get added to this partial class as fields. Notice that the FindName method is used for grabbing a reference to an element that is defined through the XAML file; &lt;/li&gt;

  &lt;li&gt;the LoadComponent method is used for loading the XAML defined in the XAML file. In this case, the generated code is getting the embedded XAML file from the SiverlightApplication 1 assembly. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;by now, you should be able to understand why you can use the same name you’ve used for the x:Name attribute to access that element from a code-behind file.&amp;#160; &lt;/p&gt;

&lt;p&gt;As you’ve seen, you can access the XAML elements from your code behind because building a Silverlight project ends up generating a partial class which introduces fields with the same name as the ones you used for the elements defined through XAML. THis is only possible due to the use of the x:Class and x:Name attributes.&lt;/p&gt;

&lt;p&gt;And that’s it for now. Stay tuned for more on Silverlight.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1740495" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/luisabreu/archive/tags/Silverlight/default.aspx">Silverlight</category><category domain="http://msmvps.com/blogs/luisabreu/archive/tags/XAML/default.aspx">XAML</category></item><item><title>XAML and collections</title><link>http://msmvps.com/blogs/luisabreu/archive/2009/11/18/xaml-and-collections.aspx</link><pubDate>Wed, 18 Nov 2009 12:13:35 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1740476</guid><dc:creator>luisabreu</dc:creator><slash:comments>2</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/luisabreu/rsscomments.aspx?PostID=1740476</wfw:commentRss><comments>http://msmvps.com/blogs/luisabreu/archive/2009/11/18/xaml-and-collections.aspx#comments</comments><description>&lt;p&gt;We’ve already talked about several features related to XAML. In this post, we’ll keep going and we’ll see how to specify collections in XAML. There are two basic types of collections you can use in XAML: lists and dictionaries. Before going on, it’s important to understand that you’re not really creating new collections in XAML; instead, we’re adding items to existing collections (in other words, if you’re building an object which has a collection like property and you want it to be set from XAML, then don’t forget to make sure that the getter returns a valid reference to a collection object).&lt;/p&gt;  &lt;p&gt;“List collections” are collections which expose an Add method (generally, we’re speaking about objects which implement the IList interface). In these cases, you’ll typically put the elements within the collection property and the XAML parser will create an object that represents each item before adding them to that collection through the Add method:&lt;/p&gt;  &lt;pre style="background-color:black;" class="code"&gt;&lt;span style="color:#a1b070;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#d6d694;"&gt;Rectangle &lt;/span&gt;&lt;span style="color:#009b00;"&gt;Width&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;=&lt;/span&gt;&lt;span style="color:#44b1e3;"&gt;&amp;quot;300&amp;quot; &lt;/span&gt;&lt;span style="color:#009b00;"&gt;Height&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;=&lt;/span&gt;&lt;span style="color:#44b1e3;"&gt;&amp;quot;150&amp;quot;&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color:#d6d694;"&gt;Rectangle.Fill&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;&amp;gt;
      &amp;lt;&lt;/span&gt;&lt;span style="color:#d6d694;"&gt;LinearGradientBrush &lt;/span&gt;&lt;span style="color:#009b00;"&gt;StartPoint&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;=&lt;/span&gt;&lt;span style="color:#44b1e3;"&gt;&amp;quot;0,0&amp;quot; &lt;/span&gt;&lt;span style="color:#009b00;"&gt;EndPoint&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;=&lt;/span&gt;&lt;span style="color:#44b1e3;"&gt;&amp;quot;1,1&amp;quot;&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;&amp;gt;
        &amp;lt;&lt;/span&gt;&lt;span style="color:#d6d694;"&gt;LinearGradientBrush.GradientStops&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;&amp;gt;
          &amp;lt;&lt;/span&gt;&lt;span style="color:#d6d694;"&gt;GradientStop &lt;/span&gt;&lt;span style="color:#009b00;"&gt;Color&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;=&lt;/span&gt;&lt;span style="color:#44b1e3;"&gt;&amp;quot;White&amp;quot; &lt;/span&gt;&lt;span style="color:#009b00;"&gt;Offset&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;=&lt;/span&gt;&lt;span style="color:#44b1e3;"&gt;&amp;quot;0&amp;quot; &lt;/span&gt;&lt;span style="color:#a1b070;"&gt;/&amp;gt;
          &amp;lt;&lt;/span&gt;&lt;span style="color:#d6d694;"&gt;GradientStop &lt;/span&gt;&lt;span style="color:#009b00;"&gt;Color&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;=&lt;/span&gt;&lt;span style="color:#44b1e3;"&gt;&amp;quot;Black&amp;quot; &lt;/span&gt;&lt;span style="color:#009b00;"&gt;Offset&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;=&lt;/span&gt;&lt;span style="color:#44b1e3;"&gt;&amp;quot;1&amp;quot; &lt;/span&gt;&lt;span style="color:#a1b070;"&gt;/&amp;gt;
        &amp;lt;/&lt;/span&gt;&lt;span style="color:#d6d694;"&gt;LinearGradientBrush.GradientStops&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;&amp;gt;
      &amp;lt;/&lt;/span&gt;&lt;span style="color:#d6d694;"&gt;LinearGradientBrush&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;&amp;gt;
    &amp;lt;/&lt;/span&gt;&lt;span style="color:#d6d694;"&gt;Rectangle.Fill&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="color:#d6d694;"&gt;Rectangle&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Btw, we could have simplified the XAML because GradientStops is the content property for the LinearGradientBrush object:&lt;/p&gt;

&lt;pre style="background-color:black;" class="code"&gt;&lt;span style="color:#a1b070;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#d6d694;"&gt;Rectangle &lt;/span&gt;&lt;span style="color:#009b00;"&gt;Width&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;=&lt;/span&gt;&lt;span style="color:#44b1e3;"&gt;&amp;quot;300&amp;quot; &lt;/span&gt;&lt;span style="color:#009b00;"&gt;Height&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;=&lt;/span&gt;&lt;span style="color:#44b1e3;"&gt;&amp;quot;150&amp;quot;&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color:#d6d694;"&gt;Rectangle.Fill&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;&amp;gt;
      &amp;lt;&lt;/span&gt;&lt;span style="color:#d6d694;"&gt;LinearGradientBrush &lt;/span&gt;&lt;span style="color:#009b00;"&gt;StartPoint&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;=&lt;/span&gt;&lt;span style="color:#44b1e3;"&gt;&amp;quot;0,0&amp;quot; &lt;/span&gt;&lt;span style="color:#009b00;"&gt;EndPoint&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;=&lt;/span&gt;&lt;span style="color:#44b1e3;"&gt;&amp;quot;1,1&amp;quot;&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;&amp;gt;
       &amp;lt;&lt;/span&gt;&lt;span style="color:#d6d694;"&gt;GradientStop &lt;/span&gt;&lt;span style="color:#009b00;"&gt;Color&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;=&lt;/span&gt;&lt;span style="color:#44b1e3;"&gt;&amp;quot;White&amp;quot; &lt;/span&gt;&lt;span style="color:#009b00;"&gt;Offset&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;=&lt;/span&gt;&lt;span style="color:#44b1e3;"&gt;&amp;quot;0&amp;quot; &lt;/span&gt;&lt;span style="color:#a1b070;"&gt;/&amp;gt;
       &amp;lt;&lt;/span&gt;&lt;span style="color:#d6d694;"&gt;GradientStop &lt;/span&gt;&lt;span style="color:#009b00;"&gt;Color&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;=&lt;/span&gt;&lt;span style="color:#44b1e3;"&gt;&amp;quot;Black&amp;quot; &lt;/span&gt;&lt;span style="color:#009b00;"&gt;Offset&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;=&lt;/span&gt;&lt;span style="color:#44b1e3;"&gt;&amp;quot;1&amp;quot; &lt;/span&gt;&lt;span style="color:#a1b070;"&gt;/&amp;gt;
      &amp;lt;/&lt;/span&gt;&lt;span style="color:#d6d694;"&gt;LinearGradientBrush&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;&amp;gt;
    &amp;lt;/&lt;/span&gt;&lt;span style="color:#d6d694;"&gt;Rectangle.Fill&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="color:#d6d694;"&gt;Rectangle&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;You can always write the previous code in C# (assume rect is a reference to the rectangle):&lt;/p&gt;

&lt;pre style="background-color:black;" class="code"&gt;&lt;span style="color:#e8e8e8;"&gt;rect&lt;/span&gt;&lt;span style="color:#80ff00;"&gt;.&lt;/span&gt;&lt;span style="color:#e8e8e8;"&gt;Fill &lt;/span&gt;&lt;span style="color:#80ff00;"&gt;= &lt;/span&gt;&lt;span style="color:#d6d694;"&gt;new &lt;/span&gt;&lt;span style="color:#009b00;"&gt;LinearGradientBrush&lt;/span&gt;&lt;span style="color:#a79a86;"&gt;()
{
    &lt;/span&gt;&lt;span style="color:#e8e8e8;"&gt;StartPoint &lt;/span&gt;&lt;span style="color:#80ff00;"&gt;= &lt;/span&gt;&lt;span style="color:#d6d694;"&gt;new &lt;/span&gt;&lt;span style="color:#ff8080;"&gt;Point&lt;/span&gt;&lt;span style="color:#a79a86;"&gt;(&lt;/span&gt;&lt;span style="color:cyan;"&gt;0&lt;/span&gt;&lt;span style="color:#a79a86;"&gt;, &lt;/span&gt;&lt;span style="color:cyan;"&gt;0&lt;/span&gt;&lt;span style="color:#a79a86;"&gt;),
    &lt;/span&gt;&lt;span style="color:#e8e8e8;"&gt;EndPoint &lt;/span&gt;&lt;span style="color:#80ff00;"&gt;= &lt;/span&gt;&lt;span style="color:#d6d694;"&gt;new &lt;/span&gt;&lt;span style="color:#ff8080;"&gt;Point&lt;/span&gt;&lt;span style="color:#a79a86;"&gt;(&lt;/span&gt;&lt;span style="color:cyan;"&gt;1&lt;/span&gt;&lt;span style="color:#a79a86;"&gt;, &lt;/span&gt;&lt;span style="color:cyan;"&gt;1&lt;/span&gt;&lt;span style="color:#a79a86;"&gt;),
    &lt;/span&gt;&lt;span style="color:#e8e8e8;"&gt;GradientStops &lt;/span&gt;&lt;span style="color:#80ff00;"&gt;= &lt;/span&gt;&lt;span style="color:#a79a86;"&gt;{
             &lt;/span&gt;&lt;span style="color:#d6d694;"&gt;new &lt;/span&gt;&lt;span style="color:#009b00;"&gt;GradientStop&lt;/span&gt;&lt;span style="color:#a79a86;"&gt;()
            {
                &lt;/span&gt;&lt;span style="color:#e8e8e8;"&gt;Color &lt;/span&gt;&lt;span style="color:#80ff00;"&gt;= &lt;/span&gt;&lt;span style="color:#009b00;"&gt;Colors&lt;/span&gt;&lt;span style="color:#80ff00;"&gt;.&lt;/span&gt;&lt;span style="color:#e8e8e8;"&gt;White&lt;/span&gt;&lt;span style="color:#a79a86;"&gt;,
                &lt;/span&gt;&lt;span style="color:#e8e8e8;"&gt;Offset &lt;/span&gt;&lt;span style="color:#80ff00;"&gt;= &lt;/span&gt;&lt;span style="color:cyan;"&gt;0
            &lt;/span&gt;&lt;span style="color:#a79a86;"&gt;}
            ,
            &lt;/span&gt;&lt;span style="color:#d6d694;"&gt;new &lt;/span&gt;&lt;span style="color:#009b00;"&gt;GradientStop&lt;/span&gt;&lt;span style="color:#a79a86;"&gt;()
            {
                &lt;/span&gt;&lt;span style="color:#e8e8e8;"&gt;Color &lt;/span&gt;&lt;span style="color:#80ff00;"&gt;= &lt;/span&gt;&lt;span style="color:#009b00;"&gt;Colors&lt;/span&gt;&lt;span style="color:#80ff00;"&gt;.&lt;/span&gt;&lt;span style="color:#e8e8e8;"&gt;Black&lt;/span&gt;&lt;span style="color:#a79a86;"&gt;,
                &lt;/span&gt;&lt;span style="color:#e8e8e8;"&gt;Offset &lt;/span&gt;&lt;span style="color:#80ff00;"&gt;= &lt;/span&gt;&lt;span style="color:cyan;"&gt;1
            &lt;/span&gt;&lt;span style="color:#a79a86;"&gt;}
    }
};&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Dictionaries are a different kind of collection: in these cases, each entry is a pair composed by a key and a value. The important thing here is understanding that you specify the key through the x:key attribute:&lt;/p&gt;

&lt;pre style="background-color:black;" class="code"&gt;&lt;span style="color:#a1b070;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#d6d694;"&gt;UserControl.Resources&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color:#d6d694;"&gt;Color &lt;/span&gt;&lt;span style="color:#009b00;"&gt;x&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;:&lt;/span&gt;&lt;span style="color:#009b00;"&gt;Key&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;=&lt;/span&gt;&lt;span style="color:#44b1e3;"&gt;&amp;quot;Black&amp;quot; &lt;/span&gt;&lt;span style="color:#009b00;"&gt;A&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;=&lt;/span&gt;&lt;span style="color:#44b1e3;"&gt;&amp;quot;0&amp;quot; &lt;/span&gt;&lt;span style="color:#009b00;"&gt;B&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;=&lt;/span&gt;&lt;span style="color:#44b1e3;"&gt;&amp;quot;0&amp;quot; &lt;/span&gt;&lt;span style="color:#009b00;"&gt;G&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;=&lt;/span&gt;&lt;span style="color:#44b1e3;"&gt;&amp;quot;0&amp;quot; &lt;/span&gt;&lt;span style="color:#a1b070;"&gt;/&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="color:#d6d694;"&gt;UserControl.Resources&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;For now, lets forget that we’re specifying resources and we’ll only concentrate on the syntax. As you can see, we added a tag which identifies the resource as a color and we’re identifying it with the word Black (ie, Black is the key that identifies this entry). Once again, you could translate the previous code into C# (Resources is an object of type ResourceDictionary), but I’ll leave it to you (if you don’t have anything better to do, that is :) )&lt;/p&gt;

&lt;p&gt;Notice x:Key is one of the few XAML keywords Silverlight supports. Besides it, there’s also the x:Class, the x:Name and x:Null attributes (we’ll come back to them in a future post). If you’re coming from WPF, then this might seem limited at first, but it’s all we have in Silverlight.&lt;/p&gt;

&lt;p&gt;And I guess this sums it up for now. Stay tuned for more on Silverlight.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1740476" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/luisabreu/archive/tags/Silverlight/default.aspx">Silverlight</category><category domain="http://msmvps.com/blogs/luisabreu/archive/tags/XAML/default.aspx">XAML</category></item><item><title>Type converter on Silverlight</title><link>http://msmvps.com/blogs/luisabreu/archive/2009/11/18/type-converter-on-silverlight.aspx</link><pubDate>Wed, 18 Nov 2009 11:09:17 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1740465</guid><dc:creator>luisabreu</dc:creator><slash:comments>2</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/luisabreu/rsscomments.aspx?PostID=1740465</wfw:commentRss><comments>http://msmvps.com/blogs/luisabreu/archive/2009/11/18/type-converter-on-silverlight.aspx#comments</comments><description>&lt;p&gt;Today we’ll talk a little bit about the role played by type converters in “transforming” XAML into C# objects. Here’s a quick example:&lt;/p&gt;  &lt;pre style="background-color:black;" class="code"&gt;&lt;span style="color:#a1b070;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#d6d694;"&gt;Button &lt;/span&gt;&lt;span style="color:#009b00;"&gt;xmlns&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;=&lt;br /&gt;&lt;/span&gt;&lt;span style="color:#44b1e3;"&gt;&amp;quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&amp;quot;
    &lt;/span&gt;&lt;span style="color:#009b00;"&gt;xmlns&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;:&lt;/span&gt;&lt;span style="color:#009b00;"&gt;x&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;=&lt;/span&gt;&lt;span style="color:#44b1e3;"&gt;&amp;quot;http://schemas.microsoft.com/winfx/2006/xaml&amp;quot;    
    &lt;/span&gt;&lt;span style="color:#009b00;"&gt;x&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;:&lt;/span&gt;&lt;span style="color:#009b00;"&gt;Name&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;=&lt;/span&gt;&lt;span style="color:#44b1e3;"&gt;&amp;quot;bt&amp;quot; &lt;/span&gt;&lt;span style="color:#009b00;"&gt;Click&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;=&lt;/span&gt;&lt;span style="color:#44b1e3;"&gt;&amp;quot;bt_Click&amp;quot; &lt;/span&gt;&lt;span style="color:#009b00;"&gt;Width&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;=&lt;/span&gt;&lt;span style="color:#44b1e3;"&gt;&amp;quot;100&amp;quot;
    &lt;/span&gt;&lt;span style="color:#009b00;"&gt;Content&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;=&lt;/span&gt;&lt;span style="color:#44b1e3;"&gt;&amp;quot;Say Hi&amp;quot; &lt;/span&gt;&lt;span style="color:#009b00;"&gt;Background&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;=&lt;/span&gt;&lt;span style="color:#44b1e3;"&gt;&amp;quot;Red&amp;quot; &lt;/span&gt;&lt;span style="color:#a1b070;"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;If you look carefully, you’ll see that &lt;a href="http://msdn.microsoft.com/en-us/library/bb979650(VS.95).aspx"&gt;Background&lt;/a&gt; expects a &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.media.brush(VS.95).aspx"&gt;Brush&lt;/a&gt; object. All XAML attribute are strings by default. In&amp;#160; other words, you’d need the following C# code to set the background of the button:&lt;/p&gt;

&lt;pre style="background-color:black;" class="code"&gt;&lt;span style="color:#e8e8e8;"&gt;bt&lt;/span&gt;&lt;span style="color:#80ff00;"&gt;.&lt;/span&gt;&lt;span style="color:#e8e8e8;"&gt;Background &lt;/span&gt;&lt;span style="color:#80ff00;"&gt;= &lt;/span&gt;&lt;span style="color:#d6d694;"&gt;new &lt;/span&gt;&lt;span style="color:#009b00;"&gt;SolidColorBrush&lt;/span&gt;&lt;span style="color:#a79a86;"&gt;(&lt;/span&gt;&lt;span style="color:#009b00;"&gt;Colors&lt;/span&gt;&lt;span style="color:#80ff00;"&gt;.&lt;/span&gt;&lt;span style="color:#e8e8e8;"&gt;Yellow&lt;/span&gt;&lt;span style="color:#a79a86;"&gt;);&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;So, what’s going on here? Well, it’s simple: the parser uses a type converter to convert the string into the correct object. In practice, type converters are objects which inherit from &lt;a href="http://msdn.microsoft.com/en-us/library/system.componentmodel.typeconverter(VS.95).aspx"&gt;TypeConverter&lt;/a&gt; class. You can associate a type converter to a type or to a property by using the &lt;a href="http://msdn.microsoft.com/en-us/library/system.componentmodel.typeconverterattribute(VS.95).aspx"&gt;TypeConverterAttribute&lt;/a&gt;. The parser will respect that option and will use the indicated type converter to translate the string into the expected object type.&lt;/p&gt;

&lt;p&gt;Now, unlike WPF, where everything is really based on managed type converters, in Silverlight, there is an *unmanaged* type converter which is used for performing most of the common conversions you’d expect to happen (take a look at the internal SilverlightTypeConverter class and you’ll notice that you’ll end up using the “unmanaged” XcpImports type).&lt;/p&gt;

&lt;p&gt;So, don’t expect to find many type converters by firing up .NET Reflector. Btw, you should keep in mind that you can still build and use your own type converters for your types. The XAML parser will always check the current property and/or type and if it’s associated with a managed type converter, it will honor that relationship and your converter will be used.&lt;/p&gt;

&lt;p&gt;And I guess it’s all for now. Stay tuned for more on Silverlight.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1740465" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/luisabreu/archive/tags/Silverlight/default.aspx">Silverlight</category><category domain="http://msmvps.com/blogs/luisabreu/archive/tags/XAML/default.aspx">XAML</category></item><item><title>XAML: using content properties</title><link>http://msmvps.com/blogs/luisabreu/archive/2009/11/17/xaml-using-content-properties.aspx</link><pubDate>Tue, 17 Nov 2009 12:06:51 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1740219</guid><dc:creator>luisabreu</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/luisabreu/rsscomments.aspx?PostID=1740219</wfw:commentRss><comments>http://msmvps.com/blogs/luisabreu/archive/2009/11/17/xaml-using-content-properties.aspx#comments</comments><description>&lt;p&gt;In the previous &lt;a href="http://msmvps.com/blogs/luisabreu/archive/2009/11/17/xaml-and-property-elements.aspx"&gt;post&lt;/a&gt;, we’ve seen that we can use one of two approaches for setting the value of a property: we can use the property element or the attribute syntax (and, as we’ve seen in the previous &lt;a href="http://msmvps.com/blogs/luisabreu/archive/2009/11/17/xaml-and-property-elements.aspx"&gt;post&lt;/a&gt;, you can’t use them both interchangeably). In this &lt;a href="http://msmvps.com/blogs/luisabreu/archive/2009/11/17/xaml-and-property-elements.aspx"&gt;post&lt;/a&gt;, we’ll keep going and we’ll see how content properties simplify even more the markup we need to write to setup the value of a property.&lt;/p&gt;  &lt;p&gt;For instance, here’s how I’d set the Content of a button to an image:&lt;/p&gt;  &lt;pre style="background-color:black;" class="code"&gt;&lt;span style="color:#a1b070;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#d6d694;"&gt;Button &lt;/span&gt;&lt;span style="color:#009b00;"&gt;xmlns&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;=&lt;br /&gt;&lt;/span&gt;&lt;span style="color:#44b1e3;"&gt;&amp;quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&amp;quot;
    &lt;/span&gt;&lt;span style="color:#009b00;"&gt;xmlns&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;:&lt;/span&gt;&lt;span style="color:#009b00;"&gt;x&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;=&lt;/span&gt;&lt;span style="color:#44b1e3;"&gt;&amp;quot;http://schemas.microsoft.com/winfx/2006/xaml&amp;quot;    
    &lt;/span&gt;&lt;span style="color:#009b00;"&gt;x&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;:&lt;/span&gt;&lt;span style="color:#009b00;"&gt;Name&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;=&lt;/span&gt;&lt;span style="color:#44b1e3;"&gt;&amp;quot;bt&amp;quot; &lt;/span&gt;&lt;span style="color:#009b00;"&gt;Click&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;=&lt;/span&gt;&lt;span style="color:#44b1e3;"&gt;&amp;quot;bt_Click&amp;quot; &lt;/span&gt;&lt;span style="color:#009b00;"&gt;Width&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;=&lt;/span&gt;&lt;span style="color:#44b1e3;"&gt;&amp;quot;100&amp;quot;&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;&amp;gt;
   &amp;lt;&lt;/span&gt;&lt;span style="color:#d6d694;"&gt;Image &lt;/span&gt;&lt;span style="color:#009b00;"&gt;Source&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;=&lt;/span&gt;&lt;span style="color:#44b1e3;"&gt;&amp;quot;/p52.jpg&amp;quot; &lt;/span&gt;&lt;span style="color:#009b00;"&gt;Stretch&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;=&lt;/span&gt;&lt;span style="color:#44b1e3;"&gt;&amp;quot;UniformToFill&amp;quot; &lt;/span&gt;&lt;span style="color:#a1b070;"&gt;/&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="color:#d6d694;"&gt;Button&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;If you compare this snippet with the one we had &lt;a href="http://msmvps.com/blogs/luisabreu/archive/2009/11/17/xaml-and-property-elements.aspx"&gt;before&lt;/a&gt;, you’ll notice that we’re not using the &amp;lt;Button.Content&amp;gt; markup element to specify that we’re setting the Content property. Why? &lt;/p&gt;

&lt;p&gt;To understand what’s going on, we need to talk a little bit about content properties. Any class can designate a property that should be set to whatever content is inside the XML element. As you’ve probably guessed, these properties are called content properties. &lt;/p&gt;

&lt;p&gt;In the case of the Button class, its content property is the Content property. Specifying a content property is done through the ContentPropertyAttribute. For instance, in the case of the Button element, we need to look at the ContentControl class (used as base) to see how the content property is defined:&lt;/p&gt;

&lt;pre style="background-color:black;" class="code"&gt;&lt;span style="color:#a79a86;"&gt;[&lt;/span&gt;&lt;span style="color:#009b00;"&gt;ContentProperty&lt;/span&gt;&lt;span style="color:#a79a86;"&gt;(&lt;/span&gt;&lt;span style="color:#44b1e3;"&gt;&amp;quot;Content&amp;quot;&lt;/span&gt;&lt;span style="color:#a79a86;"&gt;, &lt;/span&gt;&lt;span style="color:#d6d694;"&gt;true&lt;/span&gt;&lt;span style="color:#a79a86;"&gt;)]
&lt;/span&gt;&lt;span style="color:#d6d694;"&gt;public class &lt;/span&gt;&lt;span style="color:#009b00;"&gt;ContentControl &lt;/span&gt;&lt;span style="color:#a79a86;"&gt;: &lt;/span&gt;&lt;span style="color:#009b00;"&gt;Control
&lt;/span&gt;&lt;span style="color:#a79a86;"&gt;{&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Whenever you see this attribute, you know that the content of element is directly “transformed” and copied to the indicated property. And that’s it for now. Stay tuned for more on Silverlight.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1740219" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/luisabreu/archive/tags/Silverlight/default.aspx">Silverlight</category><category domain="http://msmvps.com/blogs/luisabreu/archive/tags/XAML/default.aspx">XAML</category></item><item><title>XAML and property elements</title><link>http://msmvps.com/blogs/luisabreu/archive/2009/11/17/xaml-and-property-elements.aspx</link><pubDate>Tue, 17 Nov 2009 10:20:11 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1740205</guid><dc:creator>luisabreu</dc:creator><slash:comments>2</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/luisabreu/rsscomments.aspx?PostID=1740205</wfw:commentRss><comments>http://msmvps.com/blogs/luisabreu/archive/2009/11/17/xaml-and-property-elements.aspx#comments</comments><description>&lt;p&gt;In the previous &lt;a href="http://msmvps.com/blogs/luisabreu/archive/2009/11/16/introducing-xaml.aspx"&gt;post&lt;/a&gt;, we’ve started looking at same basic XAML. At the time, we’ve defined a simple button by using the following syntax:&lt;/p&gt;  &lt;pre style="background-color:black;" class="code"&gt;&lt;span style="color:#a1b070;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#d6d694;"&gt;Button &lt;/span&gt;&lt;span style="color:#009b00;"&gt;xmlns&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;=&lt;br /&gt;&lt;/span&gt;&lt;span style="color:#44b1e3;"&gt;&amp;quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&amp;quot;
    &lt;/span&gt;&lt;span style="color:#009b00;"&gt;xmlns&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;:&lt;/span&gt;&lt;span style="color:#009b00;"&gt;x&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;=&lt;/span&gt;&lt;span style="color:#44b1e3;"&gt;&amp;quot;http://schemas.microsoft.com/winfx/2006/xaml&amp;quot;    
    &lt;/span&gt;&lt;span style="color:#009b00;"&gt;x&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;:&lt;/span&gt;&lt;span style="color:#009b00;"&gt;Name&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;=&lt;/span&gt;&lt;span style="color:#44b1e3;"&gt;&amp;quot;bt&amp;quot; &lt;/span&gt;&lt;span style="color:#009b00;"&gt;Content&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;=&lt;/span&gt;&lt;span style="color:#44b1e3;"&gt;&amp;quot;Say hi&amp;quot; &lt;/span&gt;&lt;span style="color:#009b00;"&gt;Click&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;=&lt;/span&gt;&lt;span style="color:#44b1e3;"&gt;&amp;quot;bt_Click&amp;quot; &lt;/span&gt;&lt;span style="color:#a1b070;"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;In the previous snippet, we’re setting the Content property and the Click event. Btw, and in case you’re wondering, events are set up before the properties. This is the only thing you can take for granted (you can’t really depend on the order of the attributes in your XAML to influence the order by which properties are set). This makes sense because it means that eventual handlers will be called if an event is generated by setting a property to a specific value. &lt;/p&gt;

&lt;p&gt;If you look at Content’s definition, you’ll see that it expects an object. That means we can, for instance, pass it an image instead of setting it to text:&lt;/p&gt;

&lt;pre style="background-color:black;" class="code"&gt;&lt;span style="color:#a1b070;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#d6d694;"&gt;Button &lt;/span&gt;&lt;span style="color:#009b00;"&gt;xmlns&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;=&lt;br /&gt;&lt;/span&gt;&lt;span style="color:#44b1e3;"&gt;&amp;quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&amp;quot;
    &lt;/span&gt;&lt;span style="color:#009b00;"&gt;xmlns&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;:&lt;/span&gt;&lt;span style="color:#009b00;"&gt;x&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;=&lt;/span&gt;&lt;span style="color:#44b1e3;"&gt;&amp;quot;http://schemas.microsoft.com/winfx/2006/xaml&amp;quot;    
    &lt;/span&gt;&lt;span style="color:#009b00;"&gt;x&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;:&lt;/span&gt;&lt;span style="color:#009b00;"&gt;Name&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;=&lt;/span&gt;&lt;span style="color:#44b1e3;"&gt;&amp;quot;bt&amp;quot; &lt;/span&gt;&lt;span style="color:#009b00;"&gt;Click&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;=&lt;/span&gt;&lt;span style="color:#44b1e3;"&gt;&amp;quot;bt_Click&amp;quot; &lt;/span&gt;&lt;span style="color:#009b00;"&gt;Width&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;=&lt;/span&gt;&lt;span style="color:#44b1e3;"&gt;&amp;quot;100&amp;quot;&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color:#d6d694;"&gt;Button.Content&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;&amp;gt;
        &amp;lt;&lt;/span&gt;&lt;span style="color:#d6d694;"&gt;Image &lt;/span&gt;&lt;span style="color:#009b00;"&gt;Source&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;=&lt;/span&gt;&lt;span style="color:#44b1e3;"&gt;&amp;quot;/p52.jpg&amp;quot; &lt;/span&gt;&lt;span style="color:#009b00;"&gt;Stretch&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;=&lt;/span&gt;&lt;span style="color:#44b1e3;"&gt;&amp;quot;UniformToFill&amp;quot; &lt;/span&gt;&lt;span style="color:#a1b070;"&gt;/&amp;gt;
    &amp;lt;/&lt;/span&gt;&lt;span style="color:#d6d694;"&gt;Button.Content&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;&amp;gt;            
&amp;lt;/&lt;/span&gt;&lt;span style="color:#d6d694;"&gt;Button&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;The previous snippet is showing the property element syntax. You should use it whenever you can’t use a simple string to define the value of a property. Property element syntax is really simple: you define a property by combining the name of the element with the name of the property. Property element syntax and attribute syntax are the two options you’ve got for setting the value of a property in XAML (sort of: we’ll leave content properties and collection properties to a future post).&lt;/p&gt;

&lt;p&gt;In case you’re wondering, you can’t use something like this in Silverlight:&lt;/p&gt;

&lt;pre style="background-color:black;" class="code"&gt;&lt;span style="color:#a1b070;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#d6d694;"&gt;Button &lt;/span&gt;&lt;span style="color:#009b00;"&gt;xmlns&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;=&lt;br /&gt;&lt;/span&gt;&lt;span style="color:#44b1e3;"&gt;&amp;quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&amp;quot;
    &lt;/span&gt;&lt;span style="color:#009b00;"&gt;xmlns&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;:&lt;/span&gt;&lt;span style="color:#009b00;"&gt;x&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;=&lt;/span&gt;&lt;span style="color:#44b1e3;"&gt;&amp;quot;http://schemas.microsoft.com/winfx/2006/xaml&amp;quot;    
    &lt;/span&gt;&lt;span style="color:#009b00;"&gt;x&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;:&lt;/span&gt;&lt;span style="color:#009b00;"&gt;Name&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;=&lt;/span&gt;&lt;span style="color:#44b1e3;"&gt;&amp;quot;bt&amp;quot; &lt;/span&gt;&lt;span style="color:#009b00;"&gt;Click&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;=&lt;/span&gt;&lt;span style="color:#44b1e3;"&gt;&amp;quot;bt_Click&amp;quot; &lt;/span&gt;&lt;span style="color:#009b00;"&gt;Width&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;=&lt;/span&gt;&lt;span style="color:#44b1e3;"&gt;&amp;quot;100&amp;quot;&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color:#d6d694;"&gt;Button.Content&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;&amp;gt;
        &lt;/span&gt;&lt;span style="color:#44b1e3;"&gt;Say Hi&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;
    &amp;lt;/&lt;/span&gt;&lt;span style="color:#d6d694;"&gt;Button.Content&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;&amp;gt;            
&amp;lt;/&lt;/span&gt;&lt;span style="color:#d6d694;"&gt;Button&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;If you try loading the previous XAML, you should get an exception which says something like “Say Hi isn’t allowed as the button’s content”. In case you’re wondering, this does work in WPF. Unfortunately, in Silverlight you’ll have to use the attribute syntax for setting the value of the Content to a string.&lt;/p&gt;

&lt;p&gt;In this cases, you do need to use another element. Here’s the code you can use for setting the Content’s property to text through the property element syntax:&lt;/p&gt;

&lt;pre style="background-color:black;" class="code"&gt;&lt;span style="color:#a1b070;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#d6d694;"&gt;Button &lt;/span&gt;&lt;span style="color:#009b00;"&gt;xmlns&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;=&lt;br /&gt;&lt;/span&gt;&lt;span style="color:#44b1e3;"&gt;&amp;quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&amp;quot;
    &lt;/span&gt;&lt;span style="color:#009b00;"&gt;xmlns&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;:&lt;/span&gt;&lt;span style="color:#009b00;"&gt;x&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;=&lt;/span&gt;&lt;span style="color:#44b1e3;"&gt;&amp;quot;http://schemas.microsoft.com/winfx/2006/xaml&amp;quot;    
    &lt;/span&gt;&lt;span style="color:#009b00;"&gt;x&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;:&lt;/span&gt;&lt;span style="color:#009b00;"&gt;Name&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;=&lt;/span&gt;&lt;span style="color:#44b1e3;"&gt;&amp;quot;bt&amp;quot; &lt;/span&gt;&lt;span style="color:#009b00;"&gt;Click&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;=&lt;/span&gt;&lt;span style="color:#44b1e3;"&gt;&amp;quot;bt_Click&amp;quot; &lt;/span&gt;&lt;span style="color:#009b00;"&gt;Width&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;=&lt;/span&gt;&lt;span style="color:#44b1e3;"&gt;&amp;quot;100&amp;quot;&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color:#d6d694;"&gt;Button.Content&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;&amp;gt;
        &amp;lt;&lt;/span&gt;&lt;span style="color:#d6d694;"&gt;TextBlock&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color:#44b1e3;"&gt;Say Hi&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#d6d694;"&gt;TextBlock&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;&amp;gt;
    &amp;lt;/&lt;/span&gt;&lt;span style="color:#d6d694;"&gt;Button.Content&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;&amp;gt;            
&amp;lt;/&lt;/span&gt;&lt;span style="color:#d6d694;"&gt;Button&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Fair enough: this isn’t really similar to what we had before, but it’s really the only way to set the button’s Content property to something that looks like text (notice that in this case, the Content is set to another FrameworkElement and not to a simple string).&lt;/p&gt;

&lt;p&gt;Understanding why something works in WPF and not in Silverlight is not complicated: you just need to keep in mind that all the features considered not essential were removed in order to control the size of the Silverlight framework. And it looks like this was one of them…&lt;/p&gt;

&lt;p&gt;You must be wondering which syntax you should use when you want to set the value of a property. Sometimes, the answer is simple since we’ve seen a case where you can’t use both syntaxes for setting a specific value. When both approaches are supported, I’ll tend to use the one which is more compact (typically, this means going with the attribute syntax whenever possible).&lt;/p&gt;

&lt;p&gt;And I guess this wraps it up for now. Stay tuned for more on Silverlight.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1740205" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/luisabreu/archive/tags/Silverlight/default.aspx">Silverlight</category><category domain="http://msmvps.com/blogs/luisabreu/archive/tags/XAML/default.aspx">XAML</category></item><item><title>Introducing XAML</title><link>http://msmvps.com/blogs/luisabreu/archive/2009/11/16/introducing-xaml.aspx</link><pubDate>Mon, 16 Nov 2009 21:16:53 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1740066</guid><dc:creator>luisabreu</dc:creator><slash:comments>4</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/luisabreu/rsscomments.aspx?PostID=1740066</wfw:commentRss><comments>http://msmvps.com/blogs/luisabreu/archive/2009/11/16/introducing-xaml.aspx#comments</comments><description>&lt;p&gt;You can’t really do it any other way: we must understand XAML before going on (at least, its basic features). In this post, we’ll start looking at XAML and at how we can use it to define the UI of our Silverlight user controls. So, the big question: what is XAML? To me, XAML (which, btw, means Extensible Application Markup Language) is a declarative language which you can use to define and initialize objects. Notice that XAML isn’t Silverlight specific. If my memory is correct, it was introduced with .NET 3.0 and its new frameworks (WPF and WF). In Silverlight, we’ll be using it to define the looks of our UIs. As we’ll see, it really saves us lots of code. &lt;/p&gt;  &lt;p&gt;Ok, since this is a an intro post, we’ll start simple. In this post, we’ll talk about how we can create objects and set its properties. Here’s a simple XAML snippet:&lt;/p&gt;  &lt;pre style="background-color:black;" class="code"&gt;&lt;span style="color:#a1b070;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#d6d694;"&gt;Button &lt;/span&gt;&lt;span style="color:#009b00;"&gt;xmlns&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;=&lt;/span&gt;&lt;span style="color:#44b1e3;"&gt;&amp;quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&amp;quot;
    &lt;/span&gt;&lt;span style="color:#009b00;"&gt;xmlns&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;:&lt;/span&gt;&lt;span style="color:#009b00;"&gt;x&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;=&lt;/span&gt;&lt;span style="color:#44b1e3;"&gt;&amp;quot;http://schemas.microsoft.com/winfx/2006/xaml&amp;quot;    
    &lt;/span&gt;&lt;span style="color:#009b00;"&gt;x&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;:&lt;/span&gt;&lt;span style="color:#009b00;"&gt;Name&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;=&lt;/span&gt;&lt;span style="color:#44b1e3;"&gt;&amp;quot;bt&amp;quot; &lt;/span&gt;&lt;span style="color:#009b00;"&gt;Content&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;=&lt;/span&gt;&lt;span style="color:#44b1e3;"&gt;&amp;quot;Say hi&amp;quot; &lt;/span&gt;&lt;span style="color:#009b00;"&gt;Click&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;=&lt;/span&gt;&lt;span style="color:#44b1e3;"&gt;&amp;quot;bt_Click&amp;quot; &lt;/span&gt;&lt;span style="color:#a1b070;"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;XAML is an XML language. That also means that XAML is case sensitive. Notice that we’re talking about element and attribute names here. Values are a special case: sometimes they are case sensitive; others, they aren’t (more about this in future posts). The previous example already introduces two important concepts: it shows us how to declare an element in XAML&amp;#160; and how to set its one of its properties.&lt;/p&gt;

&lt;p&gt;Btw, the previous code is equivalent to the following C# code:&lt;/p&gt;

&lt;pre style="background-color:black;" class="code"&gt;&lt;span style="color:#d6d694;"&gt;var &lt;/span&gt;&lt;span style="color:#e8e8e8;"&gt;bt &lt;/span&gt;&lt;span style="color:#80ff00;"&gt;= &lt;/span&gt;&lt;span style="color:#d6d694;"&gt;new &lt;/span&gt;&lt;span style="color:#009b00;"&gt;Button&lt;/span&gt;&lt;span style="color:#a79a86;"&gt;();
&lt;/span&gt;&lt;span style="color:#e8e8e8;"&gt;bt&lt;/span&gt;&lt;span style="color:#80ff00;"&gt;.&lt;/span&gt;&lt;span style="color:#e8e8e8;"&gt;Content &lt;/span&gt;&lt;span style="color:#80ff00;"&gt;= &lt;/span&gt;&lt;span style="color:#44b1e3;"&gt;&amp;quot;Say hi&amp;quot;&lt;/span&gt;&lt;span style="color:#a79a86;"&gt;;
&lt;/span&gt;&lt;span style="color:#e8e8e8;"&gt;bt&lt;/span&gt;&lt;span style="color:#80ff00;"&gt;.&lt;/span&gt;&lt;span style="color:#e8e8e8;"&gt;Click &lt;/span&gt;&lt;span style="color:#80ff00;"&gt;+= &lt;/span&gt;&lt;span style="color:#a79a86;"&gt;(&lt;/span&gt;&lt;span style="color:#e8e8e8;"&gt;s&lt;/span&gt;&lt;span style="color:#a79a86;"&gt;, &lt;/span&gt;&lt;span style="color:#e8e8e8;"&gt;args&lt;/span&gt;&lt;span style="color:#a79a86;"&gt;) &lt;/span&gt;&lt;span style="color:#80ff00;"&gt;=&amp;gt; &lt;/span&gt;&lt;span style="color:#a79a86;"&gt;{ };&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Ok, there’s a slight difference between both snippets: in the XAML snippet, we’re saying that the Click event will be handled by a method named bt_Click, while on the C# example, we’re using a Lambda expression. &lt;/p&gt;

&lt;p&gt;I’m not sure if you’ve noticed, but we had to use a couple of namespaces when we wrote the XAML. The default namespace (&lt;a href="http://schemas.microsoft.com/winfx/2006/xaml/presentation"&gt;http://schemas.microsoft.com/winfx/2006/xaml/presentation&lt;/a&gt;) is hardcoded to several CLR namespaces (notice that I haven’t found the list, but I assumed this behavior because that was what happened with WPF 1.0). The other namespace (the XAML one that is associated to prefix x) is used for defining some directives which are interpreted by the XAML parser (notice that the directives really look like attributes, but they are, in fact, directives). In the previous XAML snippet, the x:Name directive ends up creating a new Button object named bt (in a future post, we’ll see how this is done). &lt;/p&gt;

&lt;p&gt;The x:class directive is another XAML directive that is used often when you need to associate a XAML file to a class defined in a code-behind file (oh yes, Silverlight does support code-behind files too :) ).&lt;/p&gt;

&lt;p&gt;We’ve just started scratching XAML. As we’ll see in future posts, there are several interesting things we can do. For now, the main thing to keep in mind is that all that you can do through XAML, you can also do from C# code (though, as I’ve discovered recently, XAML code might be more performant than writing C# code – at least, when you think about rendering). And that’s it for now. In the next post, we’ll talk about the options we have for setting the properties of an object. Stay tuned for more on Silverlight.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1740066" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/luisabreu/archive/tags/Silverlight/default.aspx">Silverlight</category></item><item><title>Getting started with Silverlight</title><link>http://msmvps.com/blogs/luisabreu/archive/2009/11/16/getting-started-with-silverlight.aspx</link><pubDate>Mon, 16 Nov 2009 11:08:05 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1739978</guid><dc:creator>luisabreu</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/luisabreu/rsscomments.aspx?PostID=1739978</wfw:commentRss><comments>http://msmvps.com/blogs/luisabreu/archive/2009/11/16/getting-started-with-silverlight.aspx#comments</comments><description>&lt;p&gt;Last Friday, I’ve decided to start looking at &lt;a href="http://www.silverlight.net/"&gt;Silverlight&lt;/a&gt;. This time, I’ve opted for starting with a &lt;a href="http://www.amazon.com/Essential-Silverlight-3-Ashraf-Michail/dp/0321554167/ref=sr_1_1?ie=UTF8&amp;amp;s=books&amp;amp;qid=1258368575&amp;amp;sr=8-1"&gt;book&lt;/a&gt; (generally, I prefer to go through the source code and run some tests along the way;). As usual, I’ll be writing a couple of posts to describe my experiences with this platform. Even though I don’t have much to say yet, I thought I’d better start writing about my experiences so that I don’t forget to mention anything along the way.&lt;/p&gt;  &lt;p&gt;The first thing I noticed after writing&amp;#160; the “Hello, world!” app was that the contents of my Silverlight app are packaged into a xap file.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://msmvps.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/luisabreu.metablogapi/0020.xapdeploy_5F00_48496E0F.jpg"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="xapdeploy" border="0" alt="xapdeploy" src="http://msmvps.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/luisabreu.metablogapi/1777.xapdeploy_5F00_thumb_5F00_19178278.jpg" width="208" height="51" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;A xap package is just a zipped file with the contents of your Silverlight application. If you open the file with an app like &lt;a href="http://www.rarlab.com/"&gt;winrar&lt;/a&gt;, this is what you’ll see:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://msmvps.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/luisabreu.metablogapi/6153.xapcontent_5F00_1EF22611.jpg"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="xapcontent" border="0" alt="xapcontent" src="http://msmvps.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/luisabreu.metablogapi/0513.xapcontent_5F00_thumb_5F00_2E458820.jpg" width="336" height="227" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;As you can see, the xap file contains all the resources of your app +&amp;#160; a manifest file (besides assemblies, you’ll typically end up with other resources like xaml files, images, etc.). Besides simplifying deployment, xap files end up improving the performance of an app. To understand why, just think that with xap, you end up compressing stuff and you’ll get all the stuff your Silverlight app needs in one request. And i guess this is all for this intro post. Stay tuned for more on Silverlight.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1739978" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/luisabreu/archive/tags/Silverlight/default.aspx">Silverlight</category></item><item><title>Silverlight 3 is out</title><link>http://msmvps.com/blogs/luisabreu/archive/2009/07/09/silverlight-3-is-out.aspx</link><pubDate>Thu, 09 Jul 2009 20:32:24 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1699088</guid><dc:creator>luisabreu</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/luisabreu/rsscomments.aspx?PostID=1699088</wfw:commentRss><comments>http://msmvps.com/blogs/luisabreu/archive/2009/07/09/silverlight-3-is-out.aspx#comments</comments><description>&lt;p&gt;Incredible…&lt;a href="http://www.microsoft.com/silverlight/resources/install.aspx"&gt;version 3&lt;/a&gt; is out and I still didn’t had the time to look at version 2. I guess I’ll jump write into 3 (or 4, if things keep going this way :) ). btw, here’s the link for the &lt;a href="http://www.microsoft.com/downloads/details.aspx?familyid=9442b0f2-7465-417a-88f3-5e7b5409e9dd&amp;amp;displaylang=en"&gt;VS tools&lt;/a&gt;.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1699088" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/luisabreu/archive/tags/Silverlight/default.aspx">Silverlight</category></item><item><title>Silverlight 2.0 is out</title><link>http://msmvps.com/blogs/luisabreu/archive/2008/10/14/silverlight-2-0-is-out.aspx</link><pubDate>Tue, 14 Oct 2008 14:38:36 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1650785</guid><dc:creator>luisabreu</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/luisabreu/rsscomments.aspx?PostID=1650785</wfw:commentRss><comments>http://msmvps.com/blogs/luisabreu/archive/2008/10/14/silverlight-2-0-is-out.aspx#comments</comments><description>&lt;p&gt;I’ve just seen &lt;a href="http://feeds.feedburner.com/~r/ScottHanselman/~3/420376816/Silverlight2IsOut.aspx"&gt;this on Scott Hanselman’s blog&lt;/a&gt;. I’ll make an effort to look at it, though I’m still not convinced about it…&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1650785" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/luisabreu/archive/tags/Silverlight/default.aspx">Silverlight</category></item><item><title>Silverlight 2 RC is out</title><link>http://msmvps.com/blogs/luisabreu/archive/2008/09/28/silverlight-2-rc-is-out.aspx</link><pubDate>Sun, 28 Sep 2008 13:40:07 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1649092</guid><dc:creator>luisabreu</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/luisabreu/rsscomments.aspx?PostID=1649092</wfw:commentRss><comments>http://msmvps.com/blogs/luisabreu/archive/2008/09/28/silverlight-2-rc-is-out.aspx#comments</comments><description>&lt;p&gt;I was keen on Silverlight more than a year ago, but unfortunately I&amp;#39;ve stopped studying it since I just had to work in other areas. It seems like now is the time to pick up where I left since &lt;a href="http://weblogs.asp.net/scottgu/"&gt;Scott&lt;/a&gt; has &lt;a href="http://weblogs.asp.net/scottgu/archive/2008/09/25/silverlight-2-release-candidate-now-available.aspx"&gt;announced&lt;/a&gt; the release of SL 2.0 R.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1649092" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/luisabreu/archive/tags/Silverlight/default.aspx">Silverlight</category></item><item><title>Silverlight 2.0 beta 1 is out</title><link>http://msmvps.com/blogs/luisabreu/archive/2008/03/05/silverlight-2-0-beta-1-is-out.aspx</link><pubDate>Wed, 05 Mar 2008 22:30:54 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1534592</guid><dc:creator>luisabreu</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/luisabreu/rsscomments.aspx?PostID=1534592</wfw:commentRss><comments>http://msmvps.com/blogs/luisabreu/archive/2008/03/05/silverlight-2-0-beta-1-is-out.aspx#comments</comments><description>&lt;p&gt;So, while I was busy playing with my new &lt;a href="http://www.htctouch.com/"&gt;HTC Touch&lt;/a&gt;, it seems like MS has presented &lt;a href="http://silverlight.net/default.aspx"&gt;Silverlight 2.0 beta 1&lt;/a&gt;. Now, this is really a tough choice...&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1534592" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/luisabreu/archive/tags/Trivia/default.aspx">Trivia</category><category domain="http://msmvps.com/blogs/luisabreu/archive/tags/Silverlight/default.aspx">Silverlight</category></item><item><title>Xaml and Media controls: giving them a new chance</title><link>http://msmvps.com/blogs/luisabreu/archive/2007/11/20/xaml-and-media-controls-giving-them-a-new-chance.aspx</link><pubDate>Tue, 20 Nov 2007 21:35:36 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1342408</guid><dc:creator>luisabreu</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/luisabreu/rsscomments.aspx?PostID=1342408</wfw:commentRss><comments>http://msmvps.com/blogs/luisabreu/archive/2007/11/20/xaml-and-media-controls-giving-them-a-new-chance.aspx#comments</comments><description>&lt;p&gt;A long (long) time ago I&amp;#39;ve downloaded one of the ASP.NET future CTPS and was really annoyed with the Xaml and Media controls. Why? simple: they injected object tags on the page instead of generating JS code to perform those operations. The problem: you got one of those nasty &amp;quot;click to activate&amp;quot; messages when the page was hosted on IE.&lt;/p&gt; &lt;p&gt;Now that we know that the &amp;quot;click to activate&amp;quot; will be gone, it&amp;#39;s time to give these controls a second chance. &lt;a href="http://weblogs.asp.net/infinitiesloop/"&gt;Dave&lt;/a&gt; has already written a cool &lt;a href="http://weblogs.asp.net/infinitiesloop/archive/2007/11/12/asp-net-futures-intro-to-the-xaml-and-media-controls.aspx"&gt;post&lt;/a&gt; on it and he promises to return with more Silverlight posts.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1342408" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/luisabreu/archive/tags/ASP.NET/default.aspx">ASP.NET</category><category domain="http://msmvps.com/blogs/luisabreu/archive/tags/Silverlight/default.aspx">Silverlight</category></item><item><title>Hebrew and Arabic Silverlight support</title><link>http://msmvps.com/blogs/luisabreu/archive/2007/10/27/hebrew-and-arabic-silverlight-support.aspx</link><pubDate>Sat, 27 Oct 2007 21:24:38 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1268556</guid><dc:creator>luisabreu</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/luisabreu/rsscomments.aspx?PostID=1268556</wfw:commentRss><comments>http://msmvps.com/blogs/luisabreu/archive/2007/10/27/hebrew-and-arabic-silverlight-support.aspx#comments</comments><description>&lt;p&gt;&lt;a href="http://www.justinangel.net"&gt;Justin-Josef&lt;/a&gt; has built a new codeplex &lt;a href="http://www.codeplex.com/SilverlightRTL"&gt;project&lt;/a&gt; that aims to support Hebrew and Arabic text rendering on Silverlight. There are already some support materials over Justin&amp;#39;s site that will help you get started:&lt;/p&gt; &lt;ul&gt; &lt;li&gt;&lt;a href="http://www.justinangel.net/SilverlightRTL"&gt;online lab and demo&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="http://ttvv.tv/users/publicftp/justinangel/SilverlightRTL.wmv"&gt;20 min, web cast&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="http://blogs.microsoft.co.il/blogs/justinangel/archive/2007/10/26/silverlight-1-1-hebrew-and-arabic-language-support-silverlightrtl.aspx"&gt;complete tutorial&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;Nice work Justin!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1268556" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/luisabreu/archive/tags/Silverlight/default.aspx">Silverlight</category></item><item><title>Configuring IIS for hosting Silverlight 1.1</title><link>http://msmvps.com/blogs/luisabreu/archive/2007/09/28/configuring-iis-for-hosting-silverlight-1-1.aspx</link><pubDate>Fri, 28 Sep 2007 18:41:15 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1221251</guid><dc:creator>luisabreu</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/luisabreu/rsscomments.aspx?PostID=1221251</wfw:commentRss><comments>http://msmvps.com/blogs/luisabreu/archive/2007/09/28/configuring-iis-for-hosting-silverlight-1-1.aspx#comments</comments><description>&lt;p&gt;From time to time there&amp;#39;s always a new post asking on how to configure IIS to host Silverlight content. I&amp;#39;ve already written something about it, but I&amp;#39;d like to point you to a more complete reference which can be found here:&lt;/p&gt; &lt;p&gt;&lt;a title="http://silverlight.net/forums/t/479.aspx" href="http://silverlight.net/forums/t/479.aspx"&gt;http://silverlight.net/forums/t/479.aspx&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1221251" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/luisabreu/archive/tags/Silverlight/default.aspx">Silverlight</category></item><item><title>Silverlight pages and VS integration</title><link>http://msmvps.com/blogs/luisabreu/archive/2007/09/25/silverlight-pages-and-vs-integration.aspx</link><pubDate>Tue, 25 Sep 2007 22:01:30 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1215533</guid><dc:creator>luisabreu</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/luisabreu/rsscomments.aspx?PostID=1215533</wfw:commentRss><comments>http://msmvps.com/blogs/luisabreu/archive/2007/09/25/silverlight-pages-and-vs-integration.aspx#comments</comments><description>&lt;p&gt;Have you noticed that you can navigate from the &amp;quot;code-behind&amp;quot; file (cs file) to the designer by right clicking the page and choosing &amp;quot;View designer&amp;quot; (from the context menu that is shown when you perform right click), but there&amp;#39;s isn&amp;#39;t any option for going from the xaml page to the cs code file associated with it? am I blind?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1215533" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/luisabreu/archive/tags/Silverlight/default.aspx">Silverlight</category></item><item><title>How to share code between Silverlight and other kinds of applications?</title><link>http://msmvps.com/blogs/luisabreu/archive/2007/09/25/how-to-share-code-between-silverlight-and-other-kinds-of-applications.aspx</link><pubDate>Tue, 25 Sep 2007 20:47:50 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1215475</guid><dc:creator>luisabreu</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/luisabreu/rsscomments.aspx?PostID=1215475</wfw:commentRss><comments>http://msmvps.com/blogs/luisabreu/archive/2007/09/25/how-to-share-code-between-silverlight-and-other-kinds-of-applications.aspx#comments</comments><description>&lt;p&gt;I really haven&amp;#39;t looked at any Silverlight code for at least 2 months. In fact, I haven&amp;#39;t really been around the forums until today. Now that I&amp;#39;ve returned :), I&amp;#39;ve noticed that there&amp;#39;s a lot of similar questions around sharing code between .NET and the &amp;quot;mini-CLR&amp;quot; that is used Silverlight.&lt;/p&gt; &lt;p&gt;The first thing you should notice is that you &lt;strong&gt;cannot&lt;/strong&gt; pass .NET components to Silverlight methods! Don&amp;#39;t even try this :) Even though I haven&amp;#39;t looked at it for more than 2 months I&amp;#39;m almost positivethat you &lt;strong&gt;cannot &lt;/strong&gt;even interop with ActiveX controls without going through JS code!&lt;/p&gt; &lt;p&gt;What you can do is &amp;quot;share&amp;quot; code so that you can build a class and then use that class from your Silverlight code and from other .NET code. Don&amp;#39;t worry: this is a short post :) Instead of giving you several pieces of advice, I&amp;#39;ll just redirect you to&amp;nbsp;a great article by &lt;a href="http://www.danielmoth.com/Blog/"&gt;Daniel Moth&lt;/a&gt;:&lt;/p&gt; &lt;p&gt;&lt;a href="http://msdn.microsoft.com/msdnmag/issues/07/07/ShareCode/default.aspx"&gt;Write code once for both mobile and desktop apps&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Don&amp;#39;t let the title fool you! Even though &lt;a href="http://www.danielmoth.com/Blog/"&gt;Daniel&lt;/a&gt; has written it thinking about mobile apps, the concepts do apply to code that needs to be shared by SL and other kind of .NET apps. Btw, if you&amp;#39;re not subscribed to Daniel&amp;#39;s most excellent blog, then here&amp;#39;s the &lt;a href="http://feeds.feedburner.com/DanielMoth"&gt;RSS feed&lt;/a&gt; for it. There are really lots of cool posts over there!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1215475" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/luisabreu/archive/tags/Silverlight/default.aspx">Silverlight</category></item></channel></rss>