<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:blogChannel="http://backend.userland.com/blogChannelModule" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">
  <channel>
    <title>Andrej Tozon's blog</title>
    <description>In the Attic</description>
    <link>http://www.tozon.info/blog/</link>
    <docs>http://www.rssboard.org/rss-specification</docs>
    <generator>BlogEngine.NET 1.5.0.7</generator>
    <language>en-GB</language>
    <blogChannel:blogRoll>http://www.tozon.info/blog/opml.axd</blogChannel:blogRoll>
    <blogChannel:blink>http://www.dotnetblogengine.net/syndication.axd</blogChannel:blink>
    <dc:creator>Andrej Tozon</dc:creator>
    <dc:title>Andrej Tozon's blog</dc:title>
    <geo:lat>0.000000</geo:lat>
    <geo:long>0.000000</geo:long>
    <geo:lat>46.106922</geo:lat><geo:long>14.526415</geo:long><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner.com/TheAttic" type="application/rss+xml" /><feedburner:feedFlare href="http://add.my.yahoo.com/rss?url=http%3A%2F%2Ffeeds.feedburner.com%2FTheAttic" src="http://us.i1.yimg.com/us.yimg.com/i/us/my/addtomyyahoo4.gif">Subscribe with My Yahoo!</feedburner:feedFlare><feedburner:feedFlare href="http://www.newsgator.com/ngs/subscriber/subext.aspx?url=http%3A%2F%2Ffeeds.feedburner.com%2FTheAttic" src="http://www.newsgator.com/images/ngsub1.gif">Subscribe with NewsGator</feedburner:feedFlare><feedburner:feedFlare href="http://www.bloglines.com/sub/http://feeds.feedburner.com/TheAttic" src="http://www.bloglines.com/images/sub_modern11.gif">Subscribe with Bloglines</feedburner:feedFlare><feedburner:feedFlare href="http://www.netvibes.com/subscribe.php?url=http%3A%2F%2Ffeeds.feedburner.com%2FTheAttic" src="http://www.netvibes.com/img/add2netvibes.gif">Subscribe with Netvibes</feedburner:feedFlare><feedburner:feedFlare href="http://fusion.google.com/add?feedurl=http%3A%2F%2Ffeeds.feedburner.com%2FTheAttic" src="http://buttons.googlesyndication.com/fusion/add.gif">Subscribe with Google</feedburner:feedFlare><feedburner:feedFlare href="http://www.pageflakes.com/subscribe.aspx?url=http%3A%2F%2Ffeeds.feedburner.com%2FTheAttic" src="http://www.pageflakes.com/ImageFile.ashx?instanceId=Static_4&amp;fileName=ATP_blu_91x17.gif">Subscribe with Pageflakes</feedburner:feedFlare><feedburner:feedFlare href="http://www.live.com/?add=http%3A%2F%2Ffeeds.feedburner.com%2FTheAttic" src="http://tkfiles.storage.msn.com/x1piYkpqHC_35nIp1gLE68-wvzLZO8iXl_JMledmJQXP-XTBOLfmQv4zhj4MhcWEJh_GtoBIiAl1Mjh-ndp9k47If7hTaFno0mxW9_i3p_5qQw">Subscribe with Live.com</feedburner:feedFlare><feedburner:browserFriendly>This is an XML content feed. It is intended to be viewed in a newsreader or syndicated to another site.</feedburner:browserFriendly><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com" /><item>
      <title>Countdown to Silverlight 3 #7: Navigation</title>
      <description>&lt;p&gt;Another powerful Silverlight 3 feature is navigation. The concept is very simple: provide a space on your main page, which you’ll later fill with custom content – pages. You’ll be able to navigate through these pages (by using browser’s Forward/Back buttons, directly access them and even provide custom parameters.&lt;/p&gt;  &lt;p&gt;There’s a special project template in Visual Studio 2008 to create a Silverlight Navigation application and it provides a good start if you’re new with this feature – you’ll get a nice template to get you going, which you’ll be able to customize as you go forward.&lt;/p&gt;  &lt;p&gt;There is one core control that you’ll need to enable this feature – &lt;em&gt;System.Windows.Controls.&lt;/em&gt;Frame, which will host your &lt;em&gt;pages&lt;/em&gt; by &lt;em&gt;navigating&lt;/em&gt; to them. A Page is a special control, derived from UserControl, adding navigation capabilities.&lt;/p&gt;  &lt;p&gt;I refactored my Silverlight 3 features application to a Navigation application, each sample being a separate page, accessible from a list of samples. I’ll continue to add new samples to this application in the future. I’ll try to maintain the main application (as well as the examples pages) to be as much MVVM-ish as possible, but without having to resort to any external dependencies.&lt;/p&gt;  &lt;p&gt;A couple of things to note in the new, refactored application:&lt;/p&gt;  &lt;p&gt;1. By using Element binding feature to bind the Frame Source to selected Url in the samples list, calls to Navigate() method aren’t required – binding does all the magic.&lt;/p&gt;  &lt;div id="codeSnippetWrapper"&gt;   &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;...&lt;br /&gt;  &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;ListBox&lt;/span&gt; &lt;span style="color: #ff0000"&gt;x:Name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;views&amp;quot;&lt;/span&gt; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #ff0000"&gt;ItemsSource&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;{Binding Links, Source={StaticResource viewModel}}&amp;quot;&lt;/span&gt; ... &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;&lt;br /&gt;...&lt;br /&gt;  &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;navigation:Frame&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Source&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;{Binding SelectedItem.Value, ElementName=views}&amp;quot;&lt;/span&gt; ... &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;&lt;br /&gt;...&lt;/pre&gt;

  &lt;br /&gt;&lt;/div&gt;

&lt;p&gt;2. Passing custom parameters to a page. MergedResourceDictionaries page has been modified so it accepts a parameter of a theme to be applied to the sample form. 
  &lt;br /&gt;Example: &lt;a title="http://tozon.info/sl3/#/Views/MergedResourceDictionaries.Xaml?style=Red" href="http://tozon.info/sl3/#/Views/MergedResourceDictionaries.Xaml?style=Red" target="_blank"&gt;http://tozon.info/sl3/#/Views/MergedResourceDictionaries.Xaml?style=Red&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;3. Uri mapping. Parameters for MergedResourceDictionaries can be passed in to the paged in a shorter form, thanks to the Uri mapper.
  &lt;br /&gt;Examples: &lt;a title="http://tozon.info/sl3/#/Form/Red" href="http://tozon.info/sl3/#Form/Red" target="_blank"&gt;http://tozon.info/sl3/#Form/Red&lt;/a&gt;| &lt;a title="http://tozon.info/sl3/#Form/Blue" href="http://tozon.info/sl3/#Form/Blue" target="_blank"&gt;http://tozon.info/sl3/#Form/Blue&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;4. To prevent any mis-addressing of navigation pages, attach a handler to frame’s NavigationFailed event and handle those cases to spare your users from seeing some nasty popup windows, telling them they misspelled the url.&lt;/p&gt;

&lt;div id="codeSnippetWrapper"&gt;
  &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; OnNavigationFailed(&lt;span style="color: #0000ff"&gt;object&lt;/span&gt; sender, NavigationFailedEventArgs e)&lt;br /&gt;{&lt;br /&gt;    e.Handled = &lt;span style="color: #0000ff"&gt;true&lt;/span&gt;;&lt;br /&gt;    views.SelectedIndex = 0;&lt;br /&gt;}&lt;/pre&gt;

  &lt;br /&gt;&lt;/div&gt;

&lt;p&gt;Silverlight 3 navigation feature greatly simplifies creation of modern, interactive web sites with multiple pages, where previous to SL3, ASP.NET was in lots of cases the first choice.&lt;/p&gt;

&lt;p&gt;Additional reading 
  &lt;br /&gt;&lt;a title="http://timheuer.com/blog/archive/2009/03/22/silverlight-navigation-framework-and-uri-routing.aspx" href="http://timheuer.com/blog/archive/2009/03/22/silverlight-navigation-framework-and-uri-routing.aspx" target="_blank"&gt;http://timheuer.com/blog/archive/2009/03/22/silverlight-navigation-framework-and-uri-routing.aspx&lt;/a&gt; 

  &lt;br /&gt;&lt;/p&gt;
&lt;a title="http://blogs.microsoft.co.il/blogs/alex_golesh/archive/2009/04/02/silverlight-3-quick-tip-6-navigation-framework-and-uri-routing.aspx" href="http://blogs.microsoft.co.il/blogs/alex_golesh/archive/2009/04/02/silverlight-3-quick-tip-6-navigation-framework-and-uri-routing.aspx" target="_blank"&gt;http://blogs.microsoft.co.il/blogs/alex_golesh/archive/2009/04/02/ 
  &lt;br /&gt;silverlight-3-quick-tip-6-navigation-framework-and-uri-routing.aspx&lt;/a&gt;

&lt;p&gt;&lt;a href="http://tozon.info/sl3/" target="_blank"&gt;Run the sample online&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Source code below: 
    &lt;br /&gt;&lt;iframe style="border-bottom: #dde5e9 1px solid; border-left: #dde5e9 1px solid; padding-bottom: 0px; background-color: #ffffff; margin: 3px; padding-left: 0px; width: 240px; padding-right: 0px; height: 66px; border-top: #dde5e9 1px solid; border-right: #dde5e9 1px solid; padding-top: 0px" marginheight="0" src="http://cid-d34608bce9688fba.skydrive.live.com/embedrowdetail.aspx/Public/Development/Samples/Silverlight3.zip" frameborder="0" marginwidth="0" scrolling="no"&gt;&lt;/iframe&gt;&lt;/p&gt;
&lt;/blockquote&gt;&lt;div class="wlWriterHeaderFooter" style="text-align:left; margin:0px; padding:4px 4px 4px 4px;"&gt;&lt;a href="http://www.dotnetkicks.com/kick/?url=http://tozon.info/blog/post/2009/07/02/Countdown-to-Silverlight-3-7-Navigation.aspx"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://tozon.info/blog/post/2009/07/02/Countdown-to-Silverlight-3-7-Navigation.aspx&amp;amp;bgcolor=0080C0&amp;amp;fgcolor=FFFFFF&amp;amp;border=000000&amp;amp;cbgcolor=D4E1ED&amp;amp;cfgcolor=000000" border="0/"&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=O29jTe-LPaE:4z6yfwNNBOc:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=O29jTe-LPaE:4z6yfwNNBOc:D7DqB2pKExk"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?i=O29jTe-LPaE:4z6yfwNNBOc:D7DqB2pKExk" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=O29jTe-LPaE:4z6yfwNNBOc:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?i=O29jTe-LPaE:4z6yfwNNBOc:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=O29jTe-LPaE:4z6yfwNNBOc:dnMXMwOfBR0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?d=dnMXMwOfBR0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=O29jTe-LPaE:4z6yfwNNBOc:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?i=O29jTe-LPaE:4z6yfwNNBOc:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=O29jTe-LPaE:4z6yfwNNBOc:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=O29jTe-LPaE:4z6yfwNNBOc:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?i=O29jTe-LPaE:4z6yfwNNBOc:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=O29jTe-LPaE:4z6yfwNNBOc:I9og5sOYxJI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?d=I9og5sOYxJI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=O29jTe-LPaE:4z6yfwNNBOc:G79ilh31hkQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?d=G79ilh31hkQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=O29jTe-LPaE:4z6yfwNNBOc:V-t1I-SPZMU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?d=V-t1I-SPZMU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=O29jTe-LPaE:4z6yfwNNBOc:Jwdi1b3fU3Q"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?d=Jwdi1b3fU3Q" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/TheAttic/~4/O29jTe-LPaE" height="1" width="1"/&gt;</description>
      <link>http://feedproxy.google.com/~r/TheAttic/~3/O29jTe-LPaE/post.aspx</link>
      <author>andrej</author>
      <comments>http://www.tozon.info/blog/post/2009/07/02/Countdown-to-Silverlight-3-7-Navigation.aspx#comment</comments>
      <guid isPermaLink="false">http://www.tozon.info/blog/post.aspx?id=8748b09f-af0a-4a92-802e-4a893cee2f46</guid>
      <pubDate>Thu, 02 Jul 2009 04:23:18 -0700</pubDate>
      <category>Silverlight</category>
      <category>MVVM</category>
      <category>Development</category>
      <dc:publisher>andrej</dc:publisher>
      <pingback:server>http://www.tozon.info/blog/pingback.axd</pingback:server>
      <pingback:target>http://www.tozon.info/blog/post.aspx?id=8748b09f-af0a-4a92-802e-4a893cee2f46</pingback:target>
      <slash:comments>1</slash:comments>
      <trackback:ping>http://www.tozon.info/blog/trackback.axd?id=8748b09f-af0a-4a92-802e-4a893cee2f46</trackback:ping>
      <wfw:comment>http://www.tozon.info/blog/post/2009/07/02/Countdown-to-Silverlight-3-7-Navigation.aspx#comment</wfw:comment>
      <wfw:commentRss>http://www.tozon.info/blog/syndication.axd?post=8748b09f-af0a-4a92-802e-4a893cee2f46</wfw:commentRss>
    <feedburner:origLink>http://www.tozon.info/blog/post.aspx?id=8748b09f-af0a-4a92-802e-4a893cee2f46</feedburner:origLink></item>
    <item>
      <title>Countdown to Silverlight 3 #6: System colors</title>
      <description>&lt;p&gt;With Silverlight 3, we now have access to system colors. If you need your new application to visually fit into the operating system it’s running on, simply inspect one of the static properties, provided by the new &lt;em&gt;SystemColors&lt;/em&gt; class – System.HighlightColor for example, will tell you what color is used for highlighting the selection in ListBoxes.&lt;/p&gt;  &lt;p&gt;The provided example (below) will enumerate all available system colors and display them on the screen. To test it, go to your Control Panel and change the color scheme, then restart the application.&lt;/p&gt;  &lt;p align="center"&gt;&lt;a href="http://tozon.info/images/blog/CountdowntoSilverlight36SystemColors_14BC9/image.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://tozon.info/images/blog/CountdowntoSilverlight36SystemColors_14BC9/image_thumb.png" width="254" height="143" /&gt;&lt;/a&gt; &lt;a href="http://tozon.info/images/blog/CountdowntoSilverlight36SystemColors_14BC9/image_3.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://tozon.info/images/blog/CountdowntoSilverlight36SystemColors_14BC9/image_thumb_3.png" width="254" height="145" /&gt;&lt;/a&gt;     &lt;br /&gt;Windows Aero vs. High Contrast Black&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;Additional reading    &lt;br /&gt;&lt;a title="http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/2009/04/29/silverlight-3-system-colours.aspx" href="http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/2009/04/29/silverlight-3-system-colours.aspx"&gt;http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/2009/04/29/      &lt;br /&gt;silverlight-3-system-colours.aspx&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://tozon.info/sl3/systemcolors.html" target="_blank"&gt;Run the sample online&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Source code below:    &lt;br /&gt;&lt;iframe style="border-bottom: #dde5e9 1px solid; border-left: #dde5e9 1px solid; padding-bottom: 0px; background-color: #ffffff; margin: 3px; padding-left: 0px; width: 240px; padding-right: 0px; height: 66px; border-top: #dde5e9 1px solid; border-right: #dde5e9 1px solid; padding-top: 0px" marginheight="0" src="http://cid-d34608bce9688fba.skydrive.live.com/embedrowdetail.aspx/Public/Development/Samples/Silverlight3.zip" frameborder="0" marginwidth="0" scrolling="no"&gt;&lt;/iframe&gt;&lt;/p&gt;&lt;div class="wlWriterHeaderFooter" style="text-align:left; margin:0px; padding:4px 4px 4px 4px;"&gt;&lt;a href="http://www.dotnetkicks.com/kick/?url=http://tozon.info/blog/post/2009/06/30/Countdown-to-Silverlight-3-6-System-colors.aspx"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://tozon.info/blog/post/2009/06/30/Countdown-to-Silverlight-3-6-System-colors.aspx&amp;amp;bgcolor=0080C0&amp;amp;fgcolor=FFFFFF&amp;amp;border=000000&amp;amp;cbgcolor=D4E1ED&amp;amp;cfgcolor=000000" border="0/"&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=oa6cKmhXImU:y15EC7uGgMI:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=oa6cKmhXImU:y15EC7uGgMI:D7DqB2pKExk"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?i=oa6cKmhXImU:y15EC7uGgMI:D7DqB2pKExk" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=oa6cKmhXImU:y15EC7uGgMI:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?i=oa6cKmhXImU:y15EC7uGgMI:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=oa6cKmhXImU:y15EC7uGgMI:dnMXMwOfBR0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?d=dnMXMwOfBR0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=oa6cKmhXImU:y15EC7uGgMI:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?i=oa6cKmhXImU:y15EC7uGgMI:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=oa6cKmhXImU:y15EC7uGgMI:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=oa6cKmhXImU:y15EC7uGgMI:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?i=oa6cKmhXImU:y15EC7uGgMI:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=oa6cKmhXImU:y15EC7uGgMI:I9og5sOYxJI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?d=I9og5sOYxJI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=oa6cKmhXImU:y15EC7uGgMI:G79ilh31hkQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?d=G79ilh31hkQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=oa6cKmhXImU:y15EC7uGgMI:V-t1I-SPZMU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?d=V-t1I-SPZMU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=oa6cKmhXImU:y15EC7uGgMI:Jwdi1b3fU3Q"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?d=Jwdi1b3fU3Q" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/TheAttic/~4/oa6cKmhXImU" height="1" width="1"/&gt;</description>
      <link>http://feedproxy.google.com/~r/TheAttic/~3/oa6cKmhXImU/post.aspx</link>
      <author>andrej</author>
      <comments>http://www.tozon.info/blog/post/2009/06/30/Countdown-to-Silverlight-3-6-System-colors.aspx#comment</comments>
      <guid isPermaLink="false">http://www.tozon.info/blog/post.aspx?id=d17889af-2c89-4e39-8c86-00d73807be37</guid>
      <pubDate>Tue, 30 Jun 2009 14:59:25 -0700</pubDate>
      <category>Development</category>
      <category>Silverlight</category>
      <dc:publisher>andrej</dc:publisher>
      <pingback:server>http://www.tozon.info/blog/pingback.axd</pingback:server>
      <pingback:target>http://www.tozon.info/blog/post.aspx?id=d17889af-2c89-4e39-8c86-00d73807be37</pingback:target>
      <slash:comments>0</slash:comments>
      <trackback:ping>http://www.tozon.info/blog/trackback.axd?id=d17889af-2c89-4e39-8c86-00d73807be37</trackback:ping>
      <wfw:comment>http://www.tozon.info/blog/post/2009/06/30/Countdown-to-Silverlight-3-6-System-colors.aspx#comment</wfw:comment>
      <wfw:commentRss>http://www.tozon.info/blog/syndication.axd?post=d17889af-2c89-4e39-8c86-00d73807be37</wfw:commentRss>
    <feedburner:origLink>http://www.tozon.info/blog/post.aspx?id=d17889af-2c89-4e39-8c86-00d73807be37</feedburner:origLink></item>
    <item>
      <title>Countdown to Silverlight 3 #5: ChildWindow (Modal, Non-modal, Templated)</title>
      <description>&lt;p&gt;There are many controls being introduced in Silverlight 3; a lot of them were pulled from the &lt;a href="www.codeplex.com/silverlight" target="_blank"&gt;Silverlight Toolkit&lt;/a&gt; (the idea is that for every new Silverlight version, Toolkit controls marked as stable are moved to the Silverlight core. I’m not sure how many new controls I’m going to cover in this series, but the ChildWindow definitely deserves a separate post and sample.&lt;/p&gt;  &lt;p&gt;ChildWindow is a special control, which behaves like a dialog. By default, it is set up to display itself as a modal dialog and can be easily re-templated to give it a new look (included in the sample below).&lt;/p&gt;  &lt;p&gt;There are three steps required to make the ChildWindow display as a non-modal (floating) window:&lt;/p&gt;  &lt;p&gt;1. Create a copy of the default template and get rid of all animations, referencing the Overlay element. The overlay covers all area “behind” the child window and makes it look disabled. If you remove the Overlay element itself, the window will not be centered on the screen when invoked, so it’s best to keep it in, but somehow hide it.&lt;/p&gt;  &lt;div id="codeSnippetWrapper"&gt;   &lt;blockquote&gt;     &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;Grid&lt;/span&gt; &lt;span style="color: #ff0000"&gt;x:Name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Overlay&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Width&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;0&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Height&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;0&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
  &lt;/blockquote&gt;
&lt;/div&gt;

&lt;p&gt;&lt;em&gt;2. This is a hack.&lt;/em&gt; ChildWindow disables the root element when invoked so you have to re-enable it when window is shown:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;div&gt;
    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;Control root = Application.Current.RootVisual &lt;span style="color: #0000ff"&gt;as&lt;/span&gt; Control;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (root != &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;)&lt;br /&gt;{&lt;br /&gt;    root.IsEnabled = &lt;span style="color: #0000ff"&gt;true&lt;/span&gt;;&lt;br /&gt;}&lt;/pre&gt;
  &lt;/div&gt;

  &lt;div&gt;
    &lt;br /&gt;&lt;/div&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;em&gt;3. This is a hack. &lt;/em&gt;ChildWindow also takes control of re-focusing the window when the root control gains the focus so we have to hack into the ChildWindow’s LostFocus event to take care of this:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;div id="codeSnippetWrapper"&gt;
    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;protected&lt;/span&gt; &lt;span style="color: #0000ff"&gt;override&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; OnLostFocus(RoutedEventArgs e)&lt;br /&gt;{&lt;br /&gt;    LostFocus -= Delegate.CreateDelegate(&lt;span style="color: #0000ff"&gt;typeof&lt;/span&gt;(RoutedEventHandler), &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;,&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #006080"&gt;&amp;quot;ChildWindow_LostFocus&amp;quot;&lt;/span&gt;) &lt;span style="color: #0000ff"&gt;as&lt;/span&gt; RoutedEventHandler;&lt;br /&gt;}&lt;/pre&gt;

    &lt;br /&gt;&lt;/div&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;Additional reading: 
  &lt;br /&gt;&lt;a title="http://timheuer.com/blog/archive/2009/05/10/silverlight-childwindow-non-modal-refactor.aspx" href="http://timheuer.com/blog/archive/2009/05/10/silverlight-childwindow-non-modal-refactor.aspx"&gt;http://timheuer.com/blog/archive/2009/05/10/silverlight-childwindow-non-modal-refactor.aspx&lt;/a&gt; (a better approach to non-modal window, also read the comments)&lt;/p&gt;

&lt;p&gt;&lt;a href="http://tozon.info/sl3/childwindow.html" target="_blank"&gt;Run the sample below&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Source code below: 
  &lt;br /&gt;&lt;iframe style="border-bottom: #dde5e9 1px solid; border-left: #dde5e9 1px solid; padding-bottom: 0px; background-color: #ffffff; margin: 3px; padding-left: 0px; width: 240px; padding-right: 0px; height: 66px; border-top: #dde5e9 1px solid; border-right: #dde5e9 1px solid; padding-top: 0px" marginheight="0" src="http://cid-d34608bce9688fba.skydrive.live.com/embedrowdetail.aspx/Public/Development/Samples/Silverlight3.zip" frameborder="0" marginwidth="0" scrolling="no"&gt;&lt;/iframe&gt;&lt;/p&gt;&lt;div class="wlWriterHeaderFooter" style="text-align:left; margin:0px; padding:4px 4px 4px 4px;"&gt;&lt;a href="http://www.dotnetkicks.com/kick/?url=http://tozon.info/blog/post/2009/06/29/Countdown-to-Silverlight-3-5-ChildWindow-(Modal-Non-modal-Templated).aspx"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://tozon.info/blog/post/2009/06/29/Countdown-to-Silverlight-3-5-ChildWindow-(Modal-Non-modal-Templated).aspx&amp;amp;bgcolor=0080C0&amp;amp;fgcolor=FFFFFF&amp;amp;border=000000&amp;amp;cbgcolor=D4E1ED&amp;amp;cfgcolor=000000" border="0/"&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=z1EADU_GqxM:b2YNnIgDRI0:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=z1EADU_GqxM:b2YNnIgDRI0:D7DqB2pKExk"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?i=z1EADU_GqxM:b2YNnIgDRI0:D7DqB2pKExk" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=z1EADU_GqxM:b2YNnIgDRI0:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?i=z1EADU_GqxM:b2YNnIgDRI0:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=z1EADU_GqxM:b2YNnIgDRI0:dnMXMwOfBR0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?d=dnMXMwOfBR0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=z1EADU_GqxM:b2YNnIgDRI0:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?i=z1EADU_GqxM:b2YNnIgDRI0:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=z1EADU_GqxM:b2YNnIgDRI0:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=z1EADU_GqxM:b2YNnIgDRI0:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?i=z1EADU_GqxM:b2YNnIgDRI0:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=z1EADU_GqxM:b2YNnIgDRI0:I9og5sOYxJI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?d=I9og5sOYxJI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=z1EADU_GqxM:b2YNnIgDRI0:G79ilh31hkQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?d=G79ilh31hkQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=z1EADU_GqxM:b2YNnIgDRI0:V-t1I-SPZMU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?d=V-t1I-SPZMU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=z1EADU_GqxM:b2YNnIgDRI0:Jwdi1b3fU3Q"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?d=Jwdi1b3fU3Q" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/TheAttic/~4/z1EADU_GqxM" height="1" width="1"/&gt;</description>
      <link>http://feedproxy.google.com/~r/TheAttic/~3/z1EADU_GqxM/post.aspx</link>
      <author>andrej</author>
      <comments>http://www.tozon.info/blog/post/2009/06/29/Countdown-to-Silverlight-3-5-ChildWindow-(Modal-Non-modal-Templated).aspx#comment</comments>
      <guid isPermaLink="false">http://www.tozon.info/blog/post.aspx?id=339a9dd4-6715-4d3f-a6bf-8c7ec74b0d7e</guid>
      <pubDate>Mon, 29 Jun 2009 13:27:22 -0700</pubDate>
      <category>Development</category>
      <category>Silverlight</category>
      <dc:publisher>andrej</dc:publisher>
      <pingback:server>http://www.tozon.info/blog/pingback.axd</pingback:server>
      <pingback:target>http://www.tozon.info/blog/post.aspx?id=339a9dd4-6715-4d3f-a6bf-8c7ec74b0d7e</pingback:target>
      <slash:comments>0</slash:comments>
      <trackback:ping>http://www.tozon.info/blog/trackback.axd?id=339a9dd4-6715-4d3f-a6bf-8c7ec74b0d7e</trackback:ping>
      <wfw:comment>http://www.tozon.info/blog/post/2009/06/29/Countdown-to-Silverlight-3-5-ChildWindow-(Modal-Non-modal-Templated).aspx#comment</wfw:comment>
      <wfw:commentRss>http://www.tozon.info/blog/syndication.axd?post=339a9dd4-6715-4d3f-a6bf-8c7ec74b0d7e</wfw:commentRss>
    <feedburner:origLink>http://www.tozon.info/blog/post.aspx?id=339a9dd4-6715-4d3f-a6bf-8c7ec74b0d7e</feedburner:origLink></item>
    <item>
      <title>Countdown to Silverlight 3 #4: Element binding</title>
      <description>&lt;p&gt;Binding to elements is yet another feature, known to WPF-ers since v1. Silverlight 3 now allows bindings between UI elements and their properties, without having to use other classes as a workaround. There are numerous cases of when to use such binding, mostly to automate user interface, starting from the basic example of connecting a TextBox to a Slider (also included in the sample below). The interesting point to this binding is that it also works two-way: the TextBox not only displays the current value of the Slider, entering a new value also updates the Slider. &lt;/p&gt;  &lt;p&gt;To make the sample a bit more interesting, I included a new kind of panel, which stores the current mouse coordinates when moving it over the panel. I added two TextBoxes and bound them to the panel to display these coordinates. There’s also an ellipse, which… well, see for yourself ;)&lt;/p&gt;  &lt;p&gt;Additional Reading   &lt;br /&gt;&lt;a title="http://community.irritatedvowel.com/blogs/pete_browns_blog/archive/2009/06/24/From-Silverlight-in-Action-2nd-Edition_3A00_-UI-Element-Binding.aspx" href="http://community.irritatedvowel.com/blogs/pete_browns_blog/archive/2009/06/24/From-Silverlight-in-Action-2nd-Edition_3A00_-UI-Element-Binding.aspx"&gt;http://community.irritatedvowel.com/blogs/pete_browns_blog/archive/2009/06/24/     &lt;br /&gt;From-Silverlight-in-Action-2nd-Edition_3A00_-UI-Element-Binding.aspx&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Run the sample online&lt;/p&gt;  &lt;p&gt;Source code below:    &lt;br /&gt;&lt;iframe style="border-bottom: #dde5e9 1px solid; border-left: #dde5e9 1px solid; padding-bottom: 0px; background-color: #ffffff; margin: 3px; padding-left: 0px; width: 240px; padding-right: 0px; height: 66px; border-top: #dde5e9 1px solid; border-right: #dde5e9 1px solid; padding-top: 0px" marginheight="0" src="http://cid-d34608bce9688fba.skydrive.live.com/embedrowdetail.aspx/Public/Development/Samples/Silverlight3.zip" frameborder="0" marginwidth="0" scrolling="no"&gt;&lt;/iframe&gt;&lt;/p&gt;&lt;div class="wlWriterHeaderFooter" style="text-align:left; margin:0px; padding:4px 4px 4px 4px;"&gt;&lt;a href="http://www.dotnetkicks.com/kick/?url=http://tozon.info/blog/post/2009/06/29/Countdown-to-Silverlight-3-4-Element-binding.aspx"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://tozon.info/blog/post/2009/06/29/Countdown-to-Silverlight-3-4-Element-binding.aspx&amp;amp;bgcolor=0080C0&amp;amp;fgcolor=FFFFFF&amp;amp;border=000000&amp;amp;cbgcolor=D4E1ED&amp;amp;cfgcolor=000000" border="0/"&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=-aeI0YVgGMw:DjR8T9cA48c:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=-aeI0YVgGMw:DjR8T9cA48c:D7DqB2pKExk"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?i=-aeI0YVgGMw:DjR8T9cA48c:D7DqB2pKExk" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=-aeI0YVgGMw:DjR8T9cA48c:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?i=-aeI0YVgGMw:DjR8T9cA48c:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=-aeI0YVgGMw:DjR8T9cA48c:dnMXMwOfBR0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?d=dnMXMwOfBR0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=-aeI0YVgGMw:DjR8T9cA48c:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?i=-aeI0YVgGMw:DjR8T9cA48c:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=-aeI0YVgGMw:DjR8T9cA48c:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=-aeI0YVgGMw:DjR8T9cA48c:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?i=-aeI0YVgGMw:DjR8T9cA48c:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=-aeI0YVgGMw:DjR8T9cA48c:I9og5sOYxJI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?d=I9og5sOYxJI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=-aeI0YVgGMw:DjR8T9cA48c:G79ilh31hkQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?d=G79ilh31hkQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=-aeI0YVgGMw:DjR8T9cA48c:V-t1I-SPZMU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?d=V-t1I-SPZMU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=-aeI0YVgGMw:DjR8T9cA48c:Jwdi1b3fU3Q"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?d=Jwdi1b3fU3Q" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/TheAttic/~4/-aeI0YVgGMw" height="1" width="1"/&gt;</description>
      <link>http://feedproxy.google.com/~r/TheAttic/~3/-aeI0YVgGMw/post.aspx</link>
      <author>andrej</author>
      <comments>http://www.tozon.info/blog/post/2009/06/29/Countdown-to-Silverlight-3-4-Element-binding.aspx#comment</comments>
      <guid isPermaLink="false">http://www.tozon.info/blog/post.aspx?id=b26a969b-2a00-45fd-ba4f-d28d28b31a19</guid>
      <pubDate>Mon, 29 Jun 2009 13:26:07 -0700</pubDate>
      <category>Silverlight</category>
      <category>Development</category>
      <dc:publisher>andrej</dc:publisher>
      <pingback:server>http://www.tozon.info/blog/pingback.axd</pingback:server>
      <pingback:target>http://www.tozon.info/blog/post.aspx?id=b26a969b-2a00-45fd-ba4f-d28d28b31a19</pingback:target>
      <slash:comments>0</slash:comments>
      <trackback:ping>http://www.tozon.info/blog/trackback.axd?id=b26a969b-2a00-45fd-ba4f-d28d28b31a19</trackback:ping>
      <wfw:comment>http://www.tozon.info/blog/post/2009/06/29/Countdown-to-Silverlight-3-4-Element-binding.aspx#comment</wfw:comment>
      <wfw:commentRss>http://www.tozon.info/blog/syndication.axd?post=b26a969b-2a00-45fd-ba4f-d28d28b31a19</wfw:commentRss>
    <feedburner:origLink>http://www.tozon.info/blog/post.aspx?id=b26a969b-2a00-45fd-ba4f-d28d28b31a19</feedburner:origLink></item>
    <item>
      <title>Countdown to Silverlight 3 #3: Merged resource dictionaries</title>
      <description>&lt;p&gt;Coming from the WPF world, finding out that Silverlight lacked the feature of distributing application resources among separate files was one of those kick in a head moments. Well, not anymore. Silverlight 3, like its big brother WPF, now supports partitioning resources through merged dictionaries.&lt;/p&gt;  &lt;p&gt;Merged resource dictionaries can be included as external files (build action = Content), as included resources (build action = Resource), or as referenced assembly resources (e.g. theming).&lt;/p&gt;  &lt;div id="codeSnippetWrapper"&gt;   &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;Application.Resources&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;ResourceDictionary&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;ResourceDictionary.MergedDictionaries&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;ResourceDictionary&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Source&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Themes/Theme1.xaml&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;ResourceDictionary&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Source&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Themes/Theme2.xaml&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;ResourceDictionary.MergedDictionaries&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;ResourceDictionary&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;Application.Resources&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;br /&gt;&lt;/div&gt;

&lt;p&gt;Merged resource dictionaries come in useful when:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;providing different themes for the application (like in the sample below) &lt;/li&gt;

  &lt;li&gt;providing a new style/template for existing control &lt;/li&gt;

  &lt;li&gt;providing a style/template for a custom control &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="tozon.info/sl3/mergedresourcedictionaries.html" target="_blank"&gt;Run the sample online&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Source code below: 
  &lt;br /&gt;&lt;iframe style="border-bottom: #dde5e9 1px solid; border-left: #dde5e9 1px solid; padding-bottom: 0px; background-color: #ffffff; margin: 3px; padding-left: 0px; width: 240px; padding-right: 0px; height: 66px; border-top: #dde5e9 1px solid; border-right: #dde5e9 1px solid; padding-top: 0px" marginheight="0" src="http://cid-d34608bce9688fba.skydrive.live.com/embedrowdetail.aspx/Public/Development/Samples/Silverlight3.zip" frameborder="0" marginwidth="0" scrolling="no"&gt;&lt;/iframe&gt;&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=gyJDNd5gpto:raMD4qzxGsQ:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=gyJDNd5gpto:raMD4qzxGsQ:D7DqB2pKExk"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?i=gyJDNd5gpto:raMD4qzxGsQ:D7DqB2pKExk" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=gyJDNd5gpto:raMD4qzxGsQ:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?i=gyJDNd5gpto:raMD4qzxGsQ:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=gyJDNd5gpto:raMD4qzxGsQ:dnMXMwOfBR0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?d=dnMXMwOfBR0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=gyJDNd5gpto:raMD4qzxGsQ:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?i=gyJDNd5gpto:raMD4qzxGsQ:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=gyJDNd5gpto:raMD4qzxGsQ:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=gyJDNd5gpto:raMD4qzxGsQ:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?i=gyJDNd5gpto:raMD4qzxGsQ:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=gyJDNd5gpto:raMD4qzxGsQ:I9og5sOYxJI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?d=I9og5sOYxJI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=gyJDNd5gpto:raMD4qzxGsQ:G79ilh31hkQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?d=G79ilh31hkQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=gyJDNd5gpto:raMD4qzxGsQ:V-t1I-SPZMU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?d=V-t1I-SPZMU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=gyJDNd5gpto:raMD4qzxGsQ:Jwdi1b3fU3Q"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?d=Jwdi1b3fU3Q" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/TheAttic/~4/gyJDNd5gpto" height="1" width="1"/&gt;</description>
      <link>http://feedproxy.google.com/~r/TheAttic/~3/gyJDNd5gpto/post.aspx</link>
      <author>andrej</author>
      <comments>http://www.tozon.info/blog/post/2009/06/28/Countdown-to-Silverlight-3-3-Merged-resource-dictionaries.aspx#comment</comments>
      <guid isPermaLink="false">http://www.tozon.info/blog/post.aspx?id=9ad539b8-041c-4603-a30b-c9b0f45aedfa</guid>
      <pubDate>Sun, 28 Jun 2009 07:57:33 -0700</pubDate>
      <category>Silverlight</category>
      <category>Development</category>
      <dc:publisher>andrej</dc:publisher>
      <pingback:server>http://www.tozon.info/blog/pingback.axd</pingback:server>
      <pingback:target>http://www.tozon.info/blog/post.aspx?id=9ad539b8-041c-4603-a30b-c9b0f45aedfa</pingback:target>
      <slash:comments>2</slash:comments>
      <trackback:ping>http://www.tozon.info/blog/trackback.axd?id=9ad539b8-041c-4603-a30b-c9b0f45aedfa</trackback:ping>
      <wfw:comment>http://www.tozon.info/blog/post/2009/06/28/Countdown-to-Silverlight-3-3-Merged-resource-dictionaries.aspx#comment</wfw:comment>
      <wfw:commentRss>http://www.tozon.info/blog/syndication.axd?post=9ad539b8-041c-4603-a30b-c9b0f45aedfa</wfw:commentRss>
    <feedburner:origLink>http://www.tozon.info/blog/post.aspx?id=9ad539b8-041c-4603-a30b-c9b0f45aedfa</feedburner:origLink></item>
    <item>
      <title>Countdown to Silverlight 3 #2: Setting styles</title>
      <description>&lt;p&gt;Silverlight 3 is introducing a small, but very powerful feature: styles in Silverlight 3 can be set multiple times! For example, executing the following code in Silverlight 2 will throw a “catastrophic failure” exception on the second line:&lt;/p&gt;  &lt;div id="codeSnippetWrapper"&gt;   &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;textBox.Style = Application.Current.Resources[&lt;span style="color: #006080"&gt;&amp;quot;TextBoxStyle&amp;quot;&lt;/span&gt;] &lt;span style="color: #0000ff"&gt;as&lt;/span&gt; Style;&lt;br /&gt;textBox.Style = Application.Current.Resources[&lt;span style="color: #006080"&gt;&amp;quot;TextBoxStyle&amp;quot;&lt;/span&gt;] &lt;span style="color: #0000ff"&gt;as&lt;/span&gt; Style;&lt;/pre&gt;

  &lt;br /&gt;&lt;/div&gt;

&lt;p&gt;Silverlight 3, on the other hand, won’t have any problems with setting control’s style the second, third or n-th time, if required.&lt;/p&gt;

&lt;p&gt;To reset a control’s style, one can simply set it to null:&lt;/p&gt;

&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;textBox.Style = &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;;&lt;/pre&gt;

&lt;p&gt;… or assign an empty style to it:&lt;/p&gt;

&lt;div&gt;
  &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;Style&lt;/span&gt; &lt;span style="color: #ff0000"&gt;x:Key&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;EmptyTextBoxStyle&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;TargetType&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;TextBox&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;div&gt;&amp;#160;&lt;/div&gt;

&lt;div&gt;&lt;a href="http://tozon.info/sl3/stylesetter.html" target="_blank"&gt;Run the sample online&lt;/a&gt;&lt;/div&gt;

&lt;p&gt;Source code below: 
  &lt;br /&gt;&lt;iframe style="border-bottom: #dde5e9 1px solid; border-left: #dde5e9 1px solid; padding-bottom: 0px; background-color: #ffffff; margin: 3px; padding-left: 0px; width: 240px; padding-right: 0px; height: 66px; border-top: #dde5e9 1px solid; border-right: #dde5e9 1px solid; padding-top: 0px" marginheight="0" src="http://cid-d34608bce9688fba.skydrive.live.com/embedrowdetail.aspx/Public/Development/Samples/Silverlight3.zip" frameborder="0" marginwidth="0" scrolling="no"&gt;&lt;/iframe&gt;&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=Z4fx8WX8dEU:xPu9hCXi9dM:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=Z4fx8WX8dEU:xPu9hCXi9dM:D7DqB2pKExk"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?i=Z4fx8WX8dEU:xPu9hCXi9dM:D7DqB2pKExk" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=Z4fx8WX8dEU:xPu9hCXi9dM:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?i=Z4fx8WX8dEU:xPu9hCXi9dM:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=Z4fx8WX8dEU:xPu9hCXi9dM:dnMXMwOfBR0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?d=dnMXMwOfBR0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=Z4fx8WX8dEU:xPu9hCXi9dM:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?i=Z4fx8WX8dEU:xPu9hCXi9dM:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=Z4fx8WX8dEU:xPu9hCXi9dM:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=Z4fx8WX8dEU:xPu9hCXi9dM:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?i=Z4fx8WX8dEU:xPu9hCXi9dM:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=Z4fx8WX8dEU:xPu9hCXi9dM:I9og5sOYxJI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?d=I9og5sOYxJI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=Z4fx8WX8dEU:xPu9hCXi9dM:G79ilh31hkQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?d=G79ilh31hkQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=Z4fx8WX8dEU:xPu9hCXi9dM:V-t1I-SPZMU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?d=V-t1I-SPZMU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=Z4fx8WX8dEU:xPu9hCXi9dM:Jwdi1b3fU3Q"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?d=Jwdi1b3fU3Q" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/TheAttic/~4/Z4fx8WX8dEU" height="1" width="1"/&gt;</description>
      <link>http://feedproxy.google.com/~r/TheAttic/~3/Z4fx8WX8dEU/post.aspx</link>
      <author>andrej</author>
      <comments>http://www.tozon.info/blog/post/2009/06/27/Countdown-to-Silverlight-3-2-Setting-styles.aspx#comment</comments>
      <guid isPermaLink="false">http://www.tozon.info/blog/post.aspx?id=c3da3b5a-2dac-47ec-8151-154d177abdf6</guid>
      <pubDate>Sat, 27 Jun 2009 14:53:51 -0700</pubDate>
      <category>Development</category>
      <category>Silverlight</category>
      <dc:publisher>andrej</dc:publisher>
      <pingback:server>http://www.tozon.info/blog/pingback.axd</pingback:server>
      <pingback:target>http://www.tozon.info/blog/post.aspx?id=c3da3b5a-2dac-47ec-8151-154d177abdf6</pingback:target>
      <slash:comments>2</slash:comments>
      <trackback:ping>http://www.tozon.info/blog/trackback.axd?id=c3da3b5a-2dac-47ec-8151-154d177abdf6</trackback:ping>
      <wfw:comment>http://www.tozon.info/blog/post/2009/06/27/Countdown-to-Silverlight-3-2-Setting-styles.aspx#comment</wfw:comment>
      <wfw:commentRss>http://www.tozon.info/blog/syndication.axd?post=c3da3b5a-2dac-47ec-8151-154d177abdf6</wfw:commentRss>
    <feedburner:origLink>http://www.tozon.info/blog/post.aspx?id=c3da3b5a-2dac-47ec-8151-154d177abdf6</feedburner:origLink></item>
    <item>
      <title>Countdown to Silverlight 3 #1: Out of Browser applications</title>
      <description>&lt;p&gt;With Silverlight 3 knocking on the door (&lt;a href="http://arstechnica.com/microsoft/news/2009/05/silverlight-3-and-expression-studio-3-launching-july-10.ars" target="_blank"&gt;July 10?&lt;/a&gt;) it’s time to offload my Silverlight 3 examples. Not that they would show anything new (since SL3 Beta got out, new features had been demoed by various people to the death), it’s just another perspective or a way to go public with a sample code that’s been piling up on my desktop since the Beta was released. Anyway, this will be in a form of short posts with provided test page and sample code.&lt;/p&gt;  &lt;p&gt;I’ll begin with probably the most talked about new feature – Out of Browser applications, which could also be referred to as installed applications.&lt;/p&gt;  &lt;p&gt;First of – not every Silverlight application can be installed on the client machine. The developer must enable this by adding a &lt;em&gt;&amp;lt;Deployment.Application&amp;gt;&lt;/em&gt; section to the application manifest (&lt;em&gt;AppManifest.xml&lt;/em&gt;). This section provides more information about the application (name, title, description), along with optional icons in a few different sizes, which are used for branding your application and are displayed on various places on the desktop (install dialog, application shortcut, title bar, …)&lt;/p&gt;  &lt;p&gt;Alternative way to installing the application (a common way is to install it through the Silverlight application right-click context menu) is to provide the user with a button of some sort, which would call the new &lt;em&gt;Application.Current.Detach() &lt;/em&gt;method when clicked. Note that the method requires an explicit user action to succeed; calling it on the application load or perhaps inside a timer tick event should fail with the exception.&lt;/p&gt;  &lt;p&gt;There’s the &lt;em&gt;Application.Current.ExecutionState&lt;/em&gt; property telling the installation state of the application. Possible values include &lt;em&gt;RunningOnline&lt;/em&gt; (not installed, the default), &lt;em&gt;Detaching&lt;/em&gt;, &lt;em&gt;Detached&lt;/em&gt;, &lt;em&gt;DetachedUpdatesAvailable&lt;/em&gt; and DetachFailed (for describing various installed/ing states).&lt;/p&gt;  &lt;p&gt;When installed, the application can be run as before, inside the browser, or, by calling it through a created shortcut (start menu, desktop), outside the browser. Inspecting the &lt;em&gt;Application.Current.RunningOffline&lt;/em&gt; property will tell you how the application was run.&lt;/p&gt;  &lt;p&gt;To check if application is connected to the network, there’s the &lt;em&gt;NetworkInterface.GetIsNetworkAvailable()&lt;/em&gt; method, returning a simple true or false. Remember that being connected to the network doesn’t mean application has access to the internet, and certainly doesn’t imply that a network resource or a service application wants to call is accessible at all.&lt;/p&gt;  &lt;p&gt;One last thing to mention is that Out of Browser application still run in a partial trust, the same security context as it would when run inside the browser. The isolated storage quota, however, increases to 25MB when application gets installed.&lt;/p&gt;  &lt;p&gt;Additional reading   &lt;br /&gt;&lt;a title="http://timheuer.com/blog/archive/2009/03/18/silverlight-3-offline-update-framework.aspx" href="http://timheuer.com/blog/archive/2009/03/18/silverlight-3-offline-update-framework.aspx"&gt;http://timheuer.com/blog/archive/2009/03/18/silverlight-3-offline-update-framework.aspx&lt;/a&gt;    &lt;br /&gt;&lt;a title="http://msdn.microsoft.com/en-us/magazine/dd882515.aspx" href="http://msdn.microsoft.com/en-us/magazine/dd882515.aspx"&gt;http://msdn.microsoft.com/en-us/magazine/dd882515.aspx&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://tozon.info/sl3/outofbrowser.html" target="_blank"&gt;Run the sample online&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Source code below:   &lt;br /&gt;&lt;iframe style="border-bottom: #dde5e9 1px solid; border-left: #dde5e9 1px solid; padding-bottom: 0px; background-color: #ffffff; margin: 3px; padding-left: 0px; width: 240px; padding-right: 0px; height: 66px; border-top: #dde5e9 1px solid; border-right: #dde5e9 1px solid; padding-top: 0px" marginheight="0" src="http://cid-d34608bce9688fba.skydrive.live.com/embedrowdetail.aspx/Public/Development/Samples/Silverlight3.zip" frameborder="0" marginwidth="0" scrolling="no"&gt;&lt;/iframe&gt;&lt;/p&gt;&lt;div class="wlWriterHeaderFooter" style="text-align:left; margin:0px; padding:4px 4px 4px 4px;"&gt;&lt;a href="http://www.dotnetkicks.com/kick/?url=http://tozon.info/blog/post/2009/06/26/Countdown-to-Silverlight-3-1-Out-of-Browser-applications.aspx"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://tozon.info/blog/post/2009/06/26/Countdown-to-Silverlight-3-1-Out-of-Browser-applications.aspx&amp;amp;bgcolor=0080C0&amp;amp;fgcolor=FFFFFF&amp;amp;border=000000&amp;amp;cbgcolor=D4E1ED&amp;amp;cfgcolor=000000" border="0/"&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=Sn2TQb-DQCI:LIYn4UtePsA:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=Sn2TQb-DQCI:LIYn4UtePsA:D7DqB2pKExk"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?i=Sn2TQb-DQCI:LIYn4UtePsA:D7DqB2pKExk" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=Sn2TQb-DQCI:LIYn4UtePsA:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?i=Sn2TQb-DQCI:LIYn4UtePsA:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=Sn2TQb-DQCI:LIYn4UtePsA:dnMXMwOfBR0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?d=dnMXMwOfBR0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=Sn2TQb-DQCI:LIYn4UtePsA:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?i=Sn2TQb-DQCI:LIYn4UtePsA:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=Sn2TQb-DQCI:LIYn4UtePsA:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=Sn2TQb-DQCI:LIYn4UtePsA:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?i=Sn2TQb-DQCI:LIYn4UtePsA:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=Sn2TQb-DQCI:LIYn4UtePsA:I9og5sOYxJI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?d=I9og5sOYxJI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=Sn2TQb-DQCI:LIYn4UtePsA:G79ilh31hkQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?d=G79ilh31hkQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=Sn2TQb-DQCI:LIYn4UtePsA:V-t1I-SPZMU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?d=V-t1I-SPZMU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=Sn2TQb-DQCI:LIYn4UtePsA:Jwdi1b3fU3Q"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?d=Jwdi1b3fU3Q" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/TheAttic/~4/Sn2TQb-DQCI" height="1" width="1"/&gt;</description>
      <link>http://feedproxy.google.com/~r/TheAttic/~3/Sn2TQb-DQCI/post.aspx</link>
      <author>andrej</author>
      <comments>http://www.tozon.info/blog/post/2009/06/26/Countdown-to-Silverlight-3-1-Out-of-Browser-applications.aspx#comment</comments>
      <guid isPermaLink="false">http://www.tozon.info/blog/post.aspx?id=11aedb10-003d-4109-9dae-3b5627171a81</guid>
      <pubDate>Fri, 26 Jun 2009 01:48:59 -0700</pubDate>
      <category>Silverlight</category>
      <category>Development</category>
      <dc:publisher>andrej</dc:publisher>
      <pingback:server>http://www.tozon.info/blog/pingback.axd</pingback:server>
      <pingback:target>http://www.tozon.info/blog/post.aspx?id=11aedb10-003d-4109-9dae-3b5627171a81</pingback:target>
      <slash:comments>6</slash:comments>
      <trackback:ping>http://www.tozon.info/blog/trackback.axd?id=11aedb10-003d-4109-9dae-3b5627171a81</trackback:ping>
      <wfw:comment>http://www.tozon.info/blog/post/2009/06/26/Countdown-to-Silverlight-3-1-Out-of-Browser-applications.aspx#comment</wfw:comment>
      <wfw:commentRss>http://www.tozon.info/blog/syndication.axd?post=11aedb10-003d-4109-9dae-3b5627171a81</wfw:commentRss>
    <feedburner:origLink>http://www.tozon.info/blog/post.aspx?id=11aedb10-003d-4109-9dae-3b5627171a81</feedburner:origLink></item>
    <item>
      <title>NTK09 – Slide decks from my talks</title>
      <description>&lt;p&gt;Had 2 talks at this year’s &lt;a href="http://www.ntk.si" target="_blank"&gt;NT Konferenca&lt;/a&gt;. &lt;/p&gt;  &lt;p&gt;The first one was about building LOB application with Silverlight, starting from what can we do today with v2 (ran a short, 2 min video of a Silverlight 2 LOB app we’re going to be releasing within few weeks) and what’s coming with v3. The last part was about .NET RIA Services. &lt;/p&gt;  &lt;p&gt;The second talk was about Presentation Model (MVVM / Model-View-ViewModel) – from basics to actual working application – starting from a WPF version of an app, then porting the same ViewModel over to Silverlight to build a better UX and thorough testing, to finish with (again, with exactly the same ViewModel) a working version for Windows Forms (&lt;em&gt;yes&lt;/em&gt;, that’s &lt;em&gt;WinForms&lt;/em&gt; built with &lt;em&gt;MVVM&lt;/em&gt;). &lt;/p&gt;  &lt;p&gt;Fun.&lt;/p&gt;  &lt;p&gt;&lt;iframe style="border-bottom: #dde5e9 1px solid; border-left: #dde5e9 1px solid; padding-bottom: 0px; background-color: #ffffff; margin: 3px; padding-left: 0px; width: 240px; padding-right: 0px; height: 66px; border-top: #dde5e9 1px solid; border-right: #dde5e9 1px solid; padding-top: 0px" marginheight="0" src="http://cid-d34608bce9688fba.skydrive.live.com/embedrowdetail.aspx/Public/Presentations/NTK2009/SLLOB.pptx" frameborder="0" marginwidth="0" scrolling="no"&gt;&lt;/iframe&gt;&lt;iframe style="border-bottom: #dde5e9 1px solid; border-left: #dde5e9 1px solid; padding-bottom: 0px; background-color: #ffffff; margin: 3px; padding-left: 0px; width: 240px; padding-right: 0px; height: 66px; border-top: #dde5e9 1px solid; border-right: #dde5e9 1px solid; padding-top: 0px" marginheight="0" src="http://cid-d34608bce9688fba.skydrive.live.com/embedrowdetail.aspx/Public/Presentations/NTK2009/MVVM.pptx" frameborder="0" marginwidth="0" scrolling="no"&gt;&lt;/iframe&gt;&lt;/p&gt;  &lt;p&gt;Update: slides are in Slovenian language…&lt;/p&gt;&lt;div class="wlWriterHeaderFooter" style="text-align:left; margin:0px; padding:4px 4px 4px 4px;"&gt;&lt;a href="http://www.dotnetkicks.com/kick/?url=http://tozon.info/blog/post/2009/06/01/NTK09-e28093-Slide-decks-from-my-talks.aspx"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://tozon.info/blog/post/2009/06/01/NTK09-e28093-Slide-decks-from-my-talks.aspx&amp;amp;bgcolor=0080C0&amp;amp;fgcolor=FFFFFF&amp;amp;border=000000&amp;amp;cbgcolor=D4E1ED&amp;amp;cfgcolor=000000" border="0/"&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=HqNv-lxOnFc:uWntpVBFbgs:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=HqNv-lxOnFc:uWntpVBFbgs:D7DqB2pKExk"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?i=HqNv-lxOnFc:uWntpVBFbgs:D7DqB2pKExk" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=HqNv-lxOnFc:uWntpVBFbgs:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?i=HqNv-lxOnFc:uWntpVBFbgs:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=HqNv-lxOnFc:uWntpVBFbgs:dnMXMwOfBR0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?d=dnMXMwOfBR0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=HqNv-lxOnFc:uWntpVBFbgs:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?i=HqNv-lxOnFc:uWntpVBFbgs:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=HqNv-lxOnFc:uWntpVBFbgs:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=HqNv-lxOnFc:uWntpVBFbgs:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?i=HqNv-lxOnFc:uWntpVBFbgs:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=HqNv-lxOnFc:uWntpVBFbgs:I9og5sOYxJI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?d=I9og5sOYxJI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=HqNv-lxOnFc:uWntpVBFbgs:G79ilh31hkQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?d=G79ilh31hkQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=HqNv-lxOnFc:uWntpVBFbgs:V-t1I-SPZMU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?d=V-t1I-SPZMU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=HqNv-lxOnFc:uWntpVBFbgs:Jwdi1b3fU3Q"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?d=Jwdi1b3fU3Q" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/TheAttic/~4/HqNv-lxOnFc" height="1" width="1"/&gt;</description>
      <link>http://feedproxy.google.com/~r/TheAttic/~3/HqNv-lxOnFc/post.aspx</link>
      <author>andrej</author>
      <comments>http://www.tozon.info/blog/post/2009/06/01/NTK09-e28093-Slide-decks-from-my-talks.aspx#comment</comments>
      <guid isPermaLink="false">http://www.tozon.info/blog/post.aspx?id=6c7e4880-8439-4e9f-b774-0fcc97548725</guid>
      <pubDate>Mon, 01 Jun 2009 14:28:25 -0700</pubDate>
      <category>Development</category>
      <category>MVVM</category>
      <category>Silverlight</category>
      <category>Windows Forms</category>
      <category>WPF</category>
      <dc:publisher>andrej</dc:publisher>
      <pingback:server>http://www.tozon.info/blog/pingback.axd</pingback:server>
      <pingback:target>http://www.tozon.info/blog/post.aspx?id=6c7e4880-8439-4e9f-b774-0fcc97548725</pingback:target>
      <slash:comments>0</slash:comments>
      <trackback:ping>http://www.tozon.info/blog/trackback.axd?id=6c7e4880-8439-4e9f-b774-0fcc97548725</trackback:ping>
      <wfw:comment>http://www.tozon.info/blog/post/2009/06/01/NTK09-e28093-Slide-decks-from-my-talks.aspx#comment</wfw:comment>
      <wfw:commentRss>http://www.tozon.info/blog/syndication.axd?post=6c7e4880-8439-4e9f-b774-0fcc97548725</wfw:commentRss>
    <feedburner:origLink>http://www.tozon.info/blog/post.aspx?id=6c7e4880-8439-4e9f-b774-0fcc97548725</feedburner:origLink></item>
    <item>
      <title>Dynamic Data Forms for Silverlight, revisited</title>
      <description>&lt;p&gt;A couple of weeks ago, I &lt;a href="http://tozon.info/blog/post/2009/03/15/Dynamic-Data-Forms-for-Silverlight-with-a-Data-Template-Selector-Control.aspx"&gt;wrote&lt;/a&gt; a post about handling dynamic forms in Silverlight. With this continuation post, I’m going to make a few changes to the original project:&lt;/p&gt;  &lt;p&gt;1. Implement a new, custom, field type and provide a template for it (I’ll write about it later), and   &lt;br /&gt;2. Make a few changes to the FormFieldTemplateSelector to make it more generic. So instead of writing templates like this:&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;A new TemplateSelectorDataTemplate…&lt;/strong&gt;&lt;/p&gt;  &lt;div&gt;   &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;local:FormFieldTemplateSelector.StringTemplate&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;DataTemplate&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;TextBox&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Text&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;{Binding Value, Mode=TwoWay}&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Width&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;100&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;DataTemplate&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;local:FormFieldTemplateSelector.StringTemplate&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;local:FormFieldTemplateSelector.DateTimeTemplate&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;DataTemplate&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;basics:DatePicker&lt;/span&gt; &lt;span style="color: #ff0000"&gt;SelectedDate&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;{Binding Value, Mode=TwoWay}&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Width&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;100&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;DataTemplate&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;local:FormFieldTemplateSelector.DateTimeTemplate&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;You could simply write:&lt;/p&gt;

&lt;div&gt;
  &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;local:TemplateSelectorDataTemplate&lt;/span&gt; &lt;span style="color: #ff0000"&gt;DataType&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;System.String&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;TextBox&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Text&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;{Binding Value, Mode=TwoWay}&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Width&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;100&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;local:TemplateSelectorDataTemplate&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;local:TemplateSelectorDataTemplate&lt;/span&gt; &lt;span style="color: #ff0000"&gt;DataType&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;System.DateTime&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;basics:DatePicker&lt;/span&gt; &lt;span style="color: #ff0000"&gt;SelectedDate&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;{Binding Value, Mode=TwoWay}&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Width&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;100&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;local:TemplateSelectorDataTemplate&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;You can see the DataType property on the TemplateSelectorDataTemplate used instead of using concrete templates like FormFieldTemplateSelecot.StringTemplate. This way, the FormFieldTemplateSelector’s DataType property can be matched with TemplateSelectorDataTemplate’s DataType property [long names confusion, I know] and you don’t have to factor a new template for each new field type you come with, making it feel a bit more like the DataTemplate implementation in WPF. Strings are used here instead of types. One reason for this is that Silverlight doesn’t support x:Type markup, and the second is the fact you can use any string to identify your field type: for example, you can use “&lt;em&gt;#Signature#&lt;/em&gt;” string as a custom field type to insert a signature control into your form.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A written signature form field…&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To demonstrate a support for custom field types, I created a special control, which will allow the user to sign herself on a special panel and the signature will be submitted to the server together with the other field values.&lt;/p&gt;

&lt;p&gt;The control, which will allow us to write on it with the mouse, is of course InkPresenter. I’ve encapsulated it in another control, called SignaturePanel, which adds required mouse event handler which enables the user to write on the InkPresenter with a mouse. Here’s this control, contained within a new TemplateSelectorDataTemplate:&lt;/p&gt;

&lt;div&gt;
  &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;p&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;local:TemplateSelectorDataTemplate&lt;/span&gt; &lt;span style="color: #ff0000"&gt;DataType&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;#Signature#&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;local:SignaturePanel&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Width&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;100&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Height&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;50&amp;quot;&lt;/span&gt; &lt;br /&gt;                          &lt;span style="color: #ff0000"&gt;Strokes&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;{Binding Value, Mode=TwoWay, Converter={StaticResource strokesConverter}}&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;local:TemplateSelectorDataTemplate&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;The template looks nothing special, except that strokesConverter, specified with the binding. What that does is serialize the Strokes collection from the InkPresenter when being written to the underlying ViewModel, where we need it when sending all submitted data over to the server side. This means that signature actually gets sent over the wire in a form of strokes collection, which you can store in a database. Alternatively, you could convert that strokes into the bitmap on the server and store the signature as an image [And I’ve yet to check how Silverlight 3 WritableBitmap can help doing this on the client]. Anyway, I’ve found StrokeCollection (de)serialization code in &lt;a href="http://www.thedatafarm.com/blog" target="_blank"&gt;Julia Lerman&lt;/a&gt;’s &lt;a href="http://msdn.microsoft.com/en-gb/magazine/cc721604.aspx?pr=blog" target="_blank"&gt;Create Web Apps You Can Draw On with Silverlight 2&lt;/a&gt; MSDN article and is included in the code sample attached to this post.&lt;/p&gt;

&lt;p&gt;Here’s how the current form looks like:&lt;/p&gt;

&lt;p&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: block; float: none; margin-left: auto; border-top: 0px; margin-right: auto; border-right: 0px" title="image" border="0" alt="image" src="http://tozon.info/images/blog/DynamicDataFormsforSilverlightrevisited_F08/image.png" width="217" height="189" /&gt; &lt;/p&gt;

&lt;p&gt;Source code is now available. Please note that this is a Silverlight 3 project. It doesn’t contain any SL3 code, it’s just the project files were converted to SL3 when opened in Visual Studio.&lt;/p&gt;

&lt;p&gt;&lt;iframe style="border-bottom: #dde5e9 1px solid; border-left: #dde5e9 1px solid; padding-bottom: 0px; background-color: #ffffff; margin: 3px; padding-left: 0px; width: 240px; padding-right: 0px; height: 66px; border-top: #dde5e9 1px solid; border-right: #dde5e9 1px solid; padding-top: 0px" marginheight="0" src="http://cid-d34608bce9688fba.skydrive.live.com/embedrowdetail.aspx/Public/Development/Samples/DynamicForm.zip" frameborder="0" marginwidth="0" scrolling="no"&gt;&lt;/iframe&gt;&lt;/p&gt;

&lt;p&gt;All comments welcome. Enjoy.&lt;/p&gt;&lt;div class="wlWriterHeaderFooter" style="text-align:left; margin:0px; padding:4px 4px 4px 4px;"&gt;&lt;a href="http://www.dotnetkicks.com/kick/?url=http://tozon.info/blog/post/2009/04/07/Dynamic-Data-Forms-for-Silverlight-revisited.aspx"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://tozon.info/blog/post/2009/04/07/Dynamic-Data-Forms-for-Silverlight-revisited.aspx&amp;amp;bgcolor=0080C0&amp;amp;fgcolor=FFFFFF&amp;amp;border=000000&amp;amp;cbgcolor=D4E1ED&amp;amp;cfgcolor=000000" border="0/"&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=0NDZRu_Oahg:D5Uc4zm9T0s:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=0NDZRu_Oahg:D5Uc4zm9T0s:D7DqB2pKExk"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?i=0NDZRu_Oahg:D5Uc4zm9T0s:D7DqB2pKExk" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=0NDZRu_Oahg:D5Uc4zm9T0s:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?i=0NDZRu_Oahg:D5Uc4zm9T0s:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=0NDZRu_Oahg:D5Uc4zm9T0s:dnMXMwOfBR0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?d=dnMXMwOfBR0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=0NDZRu_Oahg:D5Uc4zm9T0s:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?i=0NDZRu_Oahg:D5Uc4zm9T0s:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=0NDZRu_Oahg:D5Uc4zm9T0s:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=0NDZRu_Oahg:D5Uc4zm9T0s:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?i=0NDZRu_Oahg:D5Uc4zm9T0s:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=0NDZRu_Oahg:D5Uc4zm9T0s:I9og5sOYxJI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?d=I9og5sOYxJI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=0NDZRu_Oahg:D5Uc4zm9T0s:V-t1I-SPZMU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?d=V-t1I-SPZMU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=0NDZRu_Oahg:D5Uc4zm9T0s:Jwdi1b3fU3Q"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?d=Jwdi1b3fU3Q" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/TheAttic/~4/0NDZRu_Oahg" height="1" width="1"/&gt;</description>
      <link>http://feedproxy.google.com/~r/TheAttic/~3/0NDZRu_Oahg/post.aspx</link>
      <author>andrej</author>
      <comments>http://www.tozon.info/blog/post/2009/04/07/Dynamic-Data-Forms-for-Silverlight-revisited.aspx#comment</comments>
      <guid isPermaLink="false">http://www.tozon.info/blog/post.aspx?id=2b12e705-8d1a-4333-a8d6-090e20fd6749</guid>
      <pubDate>Tue, 07 Apr 2009 17:12:05 -0700</pubDate>
      <category>MVVM</category>
      <category>Silverlight</category>
      <category>User Experience</category>
      <category>Development</category>
      <category>Layout</category>
      <dc:publisher>andrej</dc:publisher>
      <pingback:server>http://www.tozon.info/blog/pingback.axd</pingback:server>
      <pingback:target>http://www.tozon.info/blog/post.aspx?id=2b12e705-8d1a-4333-a8d6-090e20fd6749</pingback:target>
      <slash:comments>5</slash:comments>
      <trackback:ping>http://www.tozon.info/blog/trackback.axd?id=2b12e705-8d1a-4333-a8d6-090e20fd6749</trackback:ping>
      <wfw:comment>http://www.tozon.info/blog/post/2009/04/07/Dynamic-Data-Forms-for-Silverlight-revisited.aspx#comment</wfw:comment>
      <wfw:commentRss>http://www.tozon.info/blog/syndication.axd?post=2b12e705-8d1a-4333-a8d6-090e20fd6749</wfw:commentRss>
    <feedburner:origLink>http://www.tozon.info/blog/post.aspx?id=2b12e705-8d1a-4333-a8d6-090e20fd6749</feedburner:origLink></item>
    <item>
      <title>Creating Silverlight Behaviors (with Blend 3 Interactivity dll)</title>
      <description>&lt;p&gt;Behaviors are not new in WPF / Silverlight world; it’s a common way of extending visual element’s &lt;em&gt;behavior&lt;/em&gt; through the power of attached properties and everybody probably used one of these at least once in their projects. Now, there’s new Behaviors in town…&lt;/p&gt;  &lt;p&gt;I first learned about &lt;strong&gt;&lt;em&gt;the&lt;/em&gt;&lt;/strong&gt; behaviors in this excellent, short but sweet &lt;a href="http://www.visitmix.com/" target="_blank"&gt;MIX09&lt;/a&gt; &lt;a href="http://videos.visitmix.com/MIX09/C27M" target="_blank"&gt;presentation&lt;/a&gt; by &lt;a href="http://blois.us/blog/" target="_blank"&gt;Pete Blois&lt;/a&gt;. In short: the new “breed” of behaviors will be supported in Blend 3, allowing designers to easily extend visual elements by drag’n’dropping a variety of behaviors onto them. If you’re not familiar with what behaviors are – imagine you have a Drag behavior... By setting it to any element in your window (in Blend / Xaml, no .NET code!), that element instantly gets draggable around that window. Yeah, that’s a powerful concept. And it doesn’t stop there. Watch the video, it’s worth the time…&amp;#160; And for detailed info, Christian is running a series on behaviors and other interactivity mechanism in &lt;a href="http://electricbeach.org" target="_blank"&gt;his blog&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;What I don’t get is why they are called &lt;em&gt;Blend (3)&lt;/em&gt; behaviors, because they are not limited to Blend in any way. They would be as easily called Silverlight/WPF behaviors, or simply – Behaviors. Yes, that means you can use (and create) them even if you don’t have Blend 3 installed. Even Silverlight 3 is not required, it works with version 2 perfectly. You only need a special dll, which gets installed with Blend 3 – Microsoft.Expression.Interactivity.dll. I currently have no idea what the deployment story with this assembly is at the time of the writing (with Blend being in Beta and all), but you’ll find it in the c:\Program Files\Microsoft Expression\Blend 3 Preview\Libraries\[Silverlight] | [WPF]\ folder. This assembly (it comes in Silverlight and WPF flavor) provides the base interactivity classes and is required if you’re going to use behaviors in your application.&lt;/p&gt;  &lt;p&gt;It should be quite obvious as to where behaviors fit in the designer / developer workflow: designers will be able to decorate visual elements with various behaviors and see them in action, while developer’s job will be to come up with new, not-yet-existing behaviors that designer had in mind when designing the UX.&lt;/p&gt;  &lt;p&gt;There are a few examples of behaviors up and ready on &lt;a href="http://gallery.expression.microsoft.com/site/items/behaviors" target="_blank"&gt;Expression Gallery&lt;/a&gt;, but let’s take a look how we can develop our own behaviors using Visual Studio 2008.&lt;/p&gt;  &lt;p&gt;The first behavior we’ll look into will be called the TransparencyBehavior. What it will do is make every element semi-transparent when the mouse is not directly over it. I’ll use one of my previous samples (a &lt;a href="http://tozon.info/blog/post/2009/03/10/Disabling-items-in-a-Silverlight-ListBox.aspx"&gt;semaphore&lt;/a&gt;) as a building ground for this one. The lights on the semaphore will be semitransparent until mouse enters the light’s space for it to become fully visible. Let’s begin&lt;/p&gt;  &lt;p&gt;First, you’ll need the Expression interactivity dll (see above). Once you find it, add it as a reference to your project. Then, create a class, deriving from &lt;em&gt;Behavior&amp;lt;T&amp;gt;&lt;/em&gt;. The generic type &lt;em&gt;T&lt;/em&gt; is the type of element you want to extend with this behavior. I’m using the Ellipse type for the purpose of this example to show a more concrete implementation. I could also use &lt;em&gt;&amp;lt;FrameworkElement&amp;gt;&lt;/em&gt; because this type of behavior is so common it could be attached to element.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Update&lt;/strong&gt;: updated the previous paragraph to make sense and align with the sample code.&lt;/p&gt;  &lt;div&gt;   &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; TransparencyBehavior : Behavior&amp;lt;Ellipse&amp;gt; {}&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;We’ll need a couple of properties to control the behavior’s parameter: The InactiveTransparency property will hold an opacity value for element’s inactive state (when the mouse is not over) and the Duration will hold the time for the element to transition from active to inactive state (and vice versa).&lt;/p&gt;

&lt;p&gt;To hook into the element we’re extending, we have to override the OnAttached method. It will be called when the element is being initialized so we have the chance to attach additional event handlers to element’s events. The extended element can be reached through the AssociatedObject property. In this method, I’m hooking up into MouseEnter and MouseLeave events to detect when mouse is over, initialize and construct a storyboard that will be triggered for state transition:&lt;/p&gt;

&lt;div&gt;
  &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #0000ff"&gt;protected&lt;/span&gt; &lt;span style="color: #0000ff"&gt;override&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; OnAttached()
{
    &lt;span style="color: #0000ff"&gt;base&lt;/span&gt;.OnAttached();

    storyboard = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Storyboard();
    animation = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; DoubleAnimation();
    animation.Duration = Duration;
    Storyboard.SetTarget(animation, AssociatedObject);
    Storyboard.SetTargetProperty(animation, &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; PropertyPath(Border.OpacityProperty));
    storyboard.Children.Add(animation);

    AssociatedObject.Opacity = InactiveTransparency;
    AssociatedObject.MouseEnter += OnMouseEnter;
    AssociatedObject.MouseLeave += OnMouseLeave;
}&lt;/pre&gt;
Similarly, there's the OnDetaching method that we can use to clean up (remove event handlers etc.) The rest of the class are just the handlers:&lt;/div&gt;

&lt;div&gt;&amp;#160;&lt;/div&gt;

&lt;div&gt;
  &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #0000ff"&gt;void&lt;/span&gt; OnMouseLeave(&lt;span style="color: #0000ff"&gt;object&lt;/span&gt; sender, MouseEventArgs e)
{
    animation.To = InactiveTransparency;
    storyboard.Begin();
}

&lt;span style="color: #0000ff"&gt;void&lt;/span&gt; OnMouseEnter(&lt;span style="color: #0000ff"&gt;object&lt;/span&gt; sender, MouseEventArgs e)
{
    animation.To = 1;
    storyboard.Begin();
}&lt;/pre&gt;
&lt;/div&gt;

&lt;div&gt;&amp;#160;&lt;/div&gt;

&lt;div&gt;To finish, here’s a piece of modified (from the previous semaphore example) piece of Xaml using the behavior:&lt;/div&gt;

&lt;div&gt;&amp;#160;&lt;/div&gt;

&lt;div&gt;
  &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;Ellipse&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Fill&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;{Binding Brush}&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Width&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;50&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Height&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;50&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Stroke&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Black&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;i:Interaction.Behaviors&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;local:TransparencyBehavior&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Duration&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;00:00:00.2&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;InactiveTransparency&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;0.5&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;i:Interaction.Behaviors&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;Ellipse&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;div&gt;That’s all for this simple behavior. In future posts, I’ll come up with new behaviors and put them in the context of some other samples I’ve used in the previous posts.&lt;/div&gt;

&lt;div&gt;[Hint: in the below sample, hover over green lights]&lt;/div&gt;

&lt;p align="center"&gt;&lt;iframe height="70" src="http://tozon.info/sl/semaphore2/" frameborder="0" width="500"&gt;&lt;/iframe&gt;&lt;/p&gt;

&lt;p&gt;The way to create new behaviors is very similar to using “direct” approach with attached properties. The Behavior base class provides a very convenient infrastructure to build on, and porting the “old way” attached behaviors to this new model shouldn’t be that difficult. Behaviors are not limited to use in Blend 3 and work with Silverlight 2 too. With that, it would be great to see Microsoft releasing the interactivity dll as a standalone release or a part of some other SDK, not tying it to either Blend 3 or any particular Silverlight version.&lt;/p&gt;

&lt;p&gt;The source code for this sample is available. Please note that the project is a Silverlight 3 project and doesn’t include the Expression Interactivity dll.&lt;/p&gt;

&lt;p&gt;&lt;iframe style="border-bottom: #dde5e9 1px solid; border-left: #dde5e9 1px solid; padding-bottom: 0px; background-color: #ffffff; margin: 3px; padding-left: 0px; width: 240px; padding-right: 0px; height: 66px; border-top: #dde5e9 1px solid; border-right: #dde5e9 1px solid; padding-top: 0px" marginheight="0" src="http://cid-d34608bce9688fba.skydrive.live.com/embedrowdetail.aspx/Public/Development/Samples/Semaphore2.zip" frameborder="0" marginwidth="0" scrolling="no"&gt;&lt;/iframe&gt;&lt;/p&gt;&lt;div class="wlWriterHeaderFooter" style="text-align:left; margin:0px; padding:4px 4px 4px 4px;"&gt;&lt;a href="http://www.dotnetkicks.com/kick/?url=http://tozon.info/blog/post/2009/04/04/Creating-Silverlight-Behaviors-(with-Blend-3-Interactivity-dll).aspx"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://tozon.info/blog/post/2009/04/04/Creating-Silverlight-Behaviors-(with-Blend-3-Interactivity-dll).aspx&amp;amp;bgcolor=0080C0&amp;amp;fgcolor=FFFFFF&amp;amp;border=000000&amp;amp;cbgcolor=D4E1ED&amp;amp;cfgcolor=000000" border="0/"&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=wo5fR0Td-b8:jr2AiXcxsiw:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=wo5fR0Td-b8:jr2AiXcxsiw:D7DqB2pKExk"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?i=wo5fR0Td-b8:jr2AiXcxsiw:D7DqB2pKExk" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=wo5fR0Td-b8:jr2AiXcxsiw:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?i=wo5fR0Td-b8:jr2AiXcxsiw:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=wo5fR0Td-b8:jr2AiXcxsiw:dnMXMwOfBR0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?d=dnMXMwOfBR0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=wo5fR0Td-b8:jr2AiXcxsiw:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?i=wo5fR0Td-b8:jr2AiXcxsiw:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=wo5fR0Td-b8:jr2AiXcxsiw:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=wo5fR0Td-b8:jr2AiXcxsiw:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?i=wo5fR0Td-b8:jr2AiXcxsiw:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=wo5fR0Td-b8:jr2AiXcxsiw:I9og5sOYxJI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?d=I9og5sOYxJI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=wo5fR0Td-b8:jr2AiXcxsiw:V-t1I-SPZMU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?d=V-t1I-SPZMU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=wo5fR0Td-b8:jr2AiXcxsiw:Jwdi1b3fU3Q"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?d=Jwdi1b3fU3Q" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/TheAttic/~4/wo5fR0Td-b8" height="1" width="1"/&gt;</description>
      <link>http://feedproxy.google.com/~r/TheAttic/~3/wo5fR0Td-b8/post.aspx</link>
      <author>andrej</author>
      <comments>http://www.tozon.info/blog/post/2009/04/04/Creating-Silverlight-Behaviors-(with-Blend-3-Interactivity-dll).aspx#comment</comments>
      <guid isPermaLink="false">http://www.tozon.info/blog/post.aspx?id=7fcece3d-6106-4013-8cd6-9b272b12d8ae</guid>
      <pubDate>Sat, 04 Apr 2009 15:44:36 -0700</pubDate>
      <category>Design</category>
      <category>Development</category>
      <category>Expression</category>
      <category>Silverlight</category>
      <category>User Experience</category>
      <category>WPF</category>
      <category>Behaviors</category>
      <dc:publisher>andrej</dc:publisher>
      <pingback:server>http://www.tozon.info/blog/pingback.axd</pingback:server>
      <pingback:target>http://www.tozon.info/blog/post.aspx?id=7fcece3d-6106-4013-8cd6-9b272b12d8ae</pingback:target>
      <slash:comments>4</slash:comments>
      <trackback:ping>http://www.tozon.info/blog/trackback.axd?id=7fcece3d-6106-4013-8cd6-9b272b12d8ae</trackback:ping>
      <wfw:comment>http://www.tozon.info/blog/post/2009/04/04/Creating-Silverlight-Behaviors-(with-Blend-3-Interactivity-dll).aspx#comment</wfw:comment>
      <wfw:commentRss>http://www.tozon.info/blog/syndication.axd?post=7fcece3d-6106-4013-8cd6-9b272b12d8ae</wfw:commentRss>
    <feedburner:origLink>http://www.tozon.info/blog/post.aspx?id=7fcece3d-6106-4013-8cd6-9b272b12d8ae</feedburner:origLink></item>
    <item>
      <title>Dynamic Data Forms for Silverlight with a Data Template Selector Control</title>
      <description>&lt;p&gt;The basic idea behind this post is to show a simple way for items/list controls to display each item data with a different template. The ideal candidate for such exercise are data forms, where user can enter different kinds of information - text, numbers, check marks, etc. Imagine a scenario, where each data form field would be presented as a separate ListBox item… no matter of what data type that field is.&lt;/p&gt;  &lt;p&gt;The data model for this solution is going to be very simple and generic. We’ll need a generic class, which will represent a single field in a form. Each field will have an id, a caption, a value (entered by the user) and a value type (what’s the type of the value – text, integer, date, etc.):&lt;/p&gt;  &lt;div&gt;   &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; AutoFormField
{
    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; Guid Id { get; &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; set; }
    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; Caption { get; set; }
    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; Value { get; set; }
    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; Type { get; set; }

    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; AutoFormField()
    {
        Id = Guid.NewGuid();
    }
}&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;When the user requests a form, the associated web service will return a collection of AutoFormFields, representing all fields in the form that user should fill out. I’m not using any database for this example, so I’ve hardcoded the fields, returning to the client, in the service itself:&lt;/p&gt;

&lt;div&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; AutoFormService : IAutoFormService
{
    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; Collection&amp;lt;AutoFormField&amp;gt; GetForm()
    {
        Collection&amp;lt;AutoFormField&amp;gt; form = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Collection&amp;lt;AutoFormField&amp;gt;();
        form.Add(&lt;span style="color: #0000ff"&gt;new&lt;/span&gt; AutoFormField()
        {
            Caption = &lt;span style="color: #006080"&gt;&amp;quot;Name: &amp;quot;&lt;/span&gt;,
            Type = &lt;span style="color: #0000ff"&gt;typeof&lt;/span&gt;(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;).FullName
        });
        form.Add(&lt;span style="color: #0000ff"&gt;new&lt;/span&gt; AutoFormField()
        {
            Caption = &lt;span style="color: #006080"&gt;&amp;quot;Last name: &amp;quot;&lt;/span&gt;,
            Type = &lt;span style="color: #0000ff"&gt;typeof&lt;/span&gt;(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;).FullName
        });
        form.Add(&lt;span style="color: #0000ff"&gt;new&lt;/span&gt; AutoFormField()
        {
            Caption = &lt;span style="color: #006080"&gt;&amp;quot;Birth date: &amp;quot;&lt;/span&gt;,
            Type = &lt;span style="color: #0000ff"&gt;typeof&lt;/span&gt;(DateTime).FullName
        });
        form.Add(&lt;span style="color: #0000ff"&gt;new&lt;/span&gt; AutoFormField()
        {
            Caption = &lt;span style="color: #006080"&gt;&amp;quot;Is employed: &amp;quot;&lt;/span&gt;,
            Type = &lt;span style="color: #0000ff"&gt;typeof&lt;/span&gt;(&lt;span style="color: #0000ff"&gt;bool&lt;/span&gt;).FullName,
            Value = &lt;span style="color: #0000ff"&gt;false&lt;/span&gt;.ToString()
        });
        &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; form;
    }
}&lt;/pre&gt;
&lt;/div&gt;

&lt;div&gt;&amp;#160;&lt;/div&gt;

&lt;div&gt;The above code shows that the form consists of two text fields, a date and a yes/no field. We would naturally want to display TextBoxes for text entry, DatePicker for a date, and a CheckBox for a yes/no field entry. The Type property contains an identifier, which will tell the client what kind of entry field to display; field data type names are used here for convenience.
  &lt;br /&gt;Let’s move to the client and implement this.&lt;/div&gt;

&lt;div&gt;&amp;#160;&lt;/div&gt;

&lt;div&gt;I’ll use the ItemsControl to display the items, because I don’t need the notion of a selected item (yet). Let’s first get the basics out of the way; this is how the ItemsControl looks like, displaying all the form’s captions:&lt;/div&gt;

&lt;div&gt;&amp;#160;&lt;/div&gt;

&lt;div&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&amp;lt;ItemsControl ItemsSource=&lt;span style="color: #006080"&gt;&amp;quot;{Binding Fields, Source={StaticResource viewModel}}&amp;quot;&lt;/span&gt;&amp;gt;
    &amp;lt;ItemsControl.ItemTemplate&amp;gt;
        &amp;lt;DataTemplate&amp;gt;
            &amp;lt;TextBlock Text=&lt;span style="color: #006080"&gt;&amp;quot;{Binding Caption}&amp;quot;&lt;/span&gt; /&amp;gt;
        &amp;lt;/DataTemplate&amp;gt;
    &amp;lt;/ItemsControl.ItemTemplate&amp;gt;
&amp;lt;/ItemsControl&amp;gt;&lt;/pre&gt;
Its ItemsSource property is bound to a ViewModel’s Fields property, which gets populated when a call to the GetForm() web service method returns. The ItemTemplate is set up so that TextBlock displays the fields’ captions.&lt;/div&gt;

&lt;p&gt;What we need to do next is display the actual entry fields the user will fill in. I already mentioned the Type property; this will be the key in deciding what kind of control to display.&lt;/p&gt;

&lt;p&gt;If we would be coding this in WPF, we would use a DataTemplateSelector to help us out with selecting the right template to load for a specific type. Unfortunately, this feature is not implemented in Silverlight, so we’re on our own here. As it turns out, there isn’t much code required to come up with a solution. This is something that I call…&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;… a data template selector control…&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;For our example, we need templates for: a TextBox, a DatePicker and a CheckBox. The following user control will accept all these templates as properties and contain logic to choose between them based on a certain property, which will be bound to AutoFormField’s Type property:&lt;/p&gt;

&lt;div&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;p&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; FormFieldTemplateSelector : UserControl
{
    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; DataTemplate StringTemplate { get; set; }
    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; DataTemplate DateTimeTemplate { get; set; }
    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; DataTemplate BooleanTemplate { get; set; }
    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; DataTemplate SignatureTemplate { get; set; }

    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;readonly&lt;/span&gt; DependencyProperty FieldTypeProperty = 
        DependencyProperty.Register(&lt;span style="color: #006080"&gt;&amp;quot;FieldType&amp;quot;&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;typeof&lt;/span&gt;(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;), 
        &lt;span style="color: #0000ff"&gt;typeof&lt;/span&gt;(FormFieldTemplateSelector), &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; PropertyMetadata(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;.Empty));&lt;br /&gt;
&lt;/p&gt;&lt;p&gt;&amp;#160;&lt;/p&gt;&lt;p&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; FieldType
    {
        get { &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; (&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;)GetValue(FieldTypeProperty); }
        set { SetValue(FieldTypeProperty, &lt;span style="color: #0000ff"&gt;value&lt;/span&gt;); }
    }

    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; FormFieldTemplateSelector()
    {
        Loaded += &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; RoutedEventHandler(OnLoaded);
    }

    &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; OnLoaded(&lt;span style="color: #0000ff"&gt;object&lt;/span&gt; sender, RoutedEventArgs e)
    {
        &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; fieldType = FieldType;
        &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (fieldType == &lt;span style="color: #0000ff"&gt;typeof&lt;/span&gt;(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;).FullName)
        {
            Content = StringTemplate.LoadContent() &lt;span style="color: #0000ff"&gt;as&lt;/span&gt; UIElement;
        }
        &lt;span style="color: #0000ff"&gt;else&lt;/span&gt; &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (fieldType == &lt;span style="color: #0000ff"&gt;typeof&lt;/span&gt;(DateTime).FullName)
        {
            Content = DateTimeTemplate.LoadContent() &lt;span style="color: #0000ff"&gt;as&lt;/span&gt; UIElement;
        }
        &lt;span style="color: #0000ff"&gt;else&lt;/span&gt; &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (fieldType == &lt;span style="color: #0000ff"&gt;typeof&lt;/span&gt;(&lt;span style="color: #0000ff"&gt;bool&lt;/span&gt;).FullName)
        {
            Content = BooleanTemplate.LoadContent() &lt;span style="color: #0000ff"&gt;as&lt;/span&gt; UIElement;
        }
        &lt;span style="color: #0000ff"&gt;else&lt;/span&gt;
        {
            Content = &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;;
        }
    }
}&lt;/p&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;The way to set it up in the item template is simple too. Here’s the complete ItemTemplate:&lt;/p&gt;

&lt;div&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;Grid&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;Grid.ColumnDefinitions&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;ColumnDefinition&lt;/span&gt; &lt;span style="color: #ff0000"&gt;MinWidth&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;100&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;ColumnDefinition&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Width&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;*&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;Grid.ColumnDefinitions&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;TextBlock&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Text&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;{Binding Caption}&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;VerticalAlignment&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Center&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;local:FormFieldTemplateSelector&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Grid&lt;/span&gt;.&lt;span style="color: #ff0000"&gt;Column&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;1&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;FieldType&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;{Binding Type}&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Margin&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;0,2,0,2&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;local:FormFieldTemplateSelector.StringTemplate&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
            &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;DataTemplate&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
                &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;TextBox&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Text&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;{Binding Value, Mode=TwoWay}&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Width&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;100&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
            &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;DataTemplate&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;local:FormFieldTemplateSelector.StringTemplate&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;local:FormFieldTemplateSelector.DateTimeTemplate&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
            &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;DataTemplate&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
                &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;basics:DatePicker&lt;/span&gt; &lt;span style="color: #ff0000"&gt;SelectedDate&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;{Binding Value, Mode=TwoWay}&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Width&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;100&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
            &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;DataTemplate&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;local:FormFieldTemplateSelector.DateTimeTemplate&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;local:FormFieldTemplateSelector.BooleanTemplate&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
            &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;DataTemplate&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
                &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;CheckBox&lt;/span&gt; &lt;span style="color: #ff0000"&gt;IsChecked&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;{Binding Value, Mode=TwoWay}&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
            &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;DataTemplate&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;local:FormFieldTemplateSelector.BooleanTemplate&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;local:FormFieldTemplateSelector&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;Grid&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;Of course, this is just one way to put it together. You're free to style each field completely to your liking. This is what we have so far: &lt;img title="" style="border-right: 0px; border-top: 0px; display: block; float: none; margin-left: auto; border-left: 0px; margin-right: auto; border-bottom: 0px" height="114" alt="" src="http://tozon.info/images/blog/AutoDataFormsforSilverlightwithapoormans_5AF/image.png" width="213" border="0" /&gt; &lt;/p&gt;

&lt;p&gt;To wrap this up, you just have to add a button to submit the form back to the server. I’m not discussing this here since it’s pretty straightforward.&lt;/p&gt;

&lt;p&gt;I will, however, continue to build up on this example in the next couple of posts. Some topics I’ll dig into is styling, positioning and more (interesting) templates. I’ll also post the full code in the final post of this series.&lt;/p&gt;&lt;div class="wlWriterHeaderFooter" style="text-align:left; margin:0px; padding:4px 4px 4px 4px;"&gt;&lt;a href="http://www.dotnetkicks.com/kick/?url=http://tozon.info/blog/post/2009/03/15/Dynamic-Data-Forms-for-Silverlight-with-a-Data-Template-Selector-Control.aspx"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://tozon.info/blog/post/2009/03/15/Dynamic-Data-Forms-for-Silverlight-with-a-Data-Template-Selector-Control.aspx&amp;amp;bgcolor=0080C0&amp;amp;fgcolor=FFFFFF&amp;amp;border=000000&amp;amp;cbgcolor=D4E1ED&amp;amp;cfgcolor=000000" border="0/"&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=OM5LInYi8aU:h0qz4JCMSjE:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=OM5LInYi8aU:h0qz4JCMSjE:D7DqB2pKExk"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?i=OM5LInYi8aU:h0qz4JCMSjE:D7DqB2pKExk" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=OM5LInYi8aU:h0qz4JCMSjE:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?i=OM5LInYi8aU:h0qz4JCMSjE:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=OM5LInYi8aU:h0qz4JCMSjE:dnMXMwOfBR0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?d=dnMXMwOfBR0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=OM5LInYi8aU:h0qz4JCMSjE:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?i=OM5LInYi8aU:h0qz4JCMSjE:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=OM5LInYi8aU:h0qz4JCMSjE:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=OM5LInYi8aU:h0qz4JCMSjE:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?i=OM5LInYi8aU:h0qz4JCMSjE:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=OM5LInYi8aU:h0qz4JCMSjE:I9og5sOYxJI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?d=I9og5sOYxJI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=OM5LInYi8aU:h0qz4JCMSjE:V-t1I-SPZMU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?d=V-t1I-SPZMU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=OM5LInYi8aU:h0qz4JCMSjE:Jwdi1b3fU3Q"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?d=Jwdi1b3fU3Q" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/TheAttic/~4/OM5LInYi8aU" height="1" width="1"/&gt;</description>
      <link>http://feedproxy.google.com/~r/TheAttic/~3/OM5LInYi8aU/post.aspx</link>
      <author>andrej</author>
      <comments>http://www.tozon.info/blog/post/2009/03/15/Dynamic-Data-Forms-for-Silverlight-with-a-Data-Template-Selector-Control.aspx#comment</comments>
      <guid isPermaLink="false">http://www.tozon.info/blog/post.aspx?id=ae296428-7fd4-4727-85bd-2565801d80ef</guid>
      <pubDate>Sun, 15 Mar 2009 16:04:33 -0700</pubDate>
      <category>Development</category>
      <category>MVVM</category>
      <category>Silverlight</category>
      <category>User Experience</category>
      <category>Layout</category>
      <dc:publisher>andrej</dc:publisher>
      <pingback:server>http://www.tozon.info/blog/pingback.axd</pingback:server>
      <pingback:target>http://www.tozon.info/blog/post.aspx?id=ae296428-7fd4-4727-85bd-2565801d80ef</pingback:target>
      <slash:comments>9</slash:comments>
      <trackback:ping>http://www.tozon.info/blog/trackback.axd?id=ae296428-7fd4-4727-85bd-2565801d80ef</trackback:ping>
      <wfw:comment>http://www.tozon.info/blog/post/2009/03/15/Dynamic-Data-Forms-for-Silverlight-with-a-Data-Template-Selector-Control.aspx#comment</wfw:comment>
      <wfw:commentRss>http://www.tozon.info/blog/syndication.axd?post=ae296428-7fd4-4727-85bd-2565801d80ef</wfw:commentRss>
    <feedburner:origLink>http://www.tozon.info/blog/post.aspx?id=ae296428-7fd4-4727-85bd-2565801d80ef</feedburner:origLink></item>
    <item>
      <title>Disabling items in a Silverlight ListBox</title>
      <description>&lt;p&gt;This is a quick tip on making the ListBox items behave as disabled.&lt;/p&gt;  &lt;p&gt;You know the semaphore, right? STOP on red, GO on green? OK. I’m drilling this with my two-year old when driving her to kindergarten every morning so lately it’s probably stuck in my mind a bit more than it should be.&lt;/p&gt;  &lt;p&gt;OK. This is a ListBox:&lt;/p&gt;  &lt;p&gt;&lt;img title="image" style="border-top-width: 0px; display: block; border-left-width: 0px; float: none; border-bottom-width: 0px; margin-left: auto; margin-right: auto; border-right-width: 0px" height="92" alt="image" src="http://tozon.info/images/blog/DisableditemsinaSilverlightListBox_12D77/image.png" width="312" border="0" /&gt; &lt;/p&gt;  &lt;p&gt;Yes, it is:&lt;/p&gt;  &lt;div&gt;   &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;ListBox&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ItemsSource&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;{Binding Lights}&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;BorderThickness&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;0&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;ListBox.ItemsPanel&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;ItemsPanelTemplate&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
            &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;StackPanel&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Orientation&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Horizontal&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;ItemsPanelTemplate&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;ListBox.ItemsPanel&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;ListBox.ItemTemplate&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;DataTemplate&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
            &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;Ellipse&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Fill&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;{Binding Brush}&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Width&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;50&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Height&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;50&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Stroke&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Black&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Cursor&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Hand&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;DataTemplate&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;ListBox.ItemTemplate&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;ListBox.ItemContainerStyle&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;Style&lt;/span&gt; &lt;span style="color: #ff0000"&gt;TargetType&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;ListBoxItem&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
            &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;Setter&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Property&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Template&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
                &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;Setter.Value&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
                    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;ControlTemplate&lt;/span&gt; &lt;span style="color: #ff0000"&gt;TargetType&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;ListBoxItem&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
                        &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;ContentPresenter&lt;/span&gt; &lt;span style="color: #ff0000"&gt;x:Name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;contentPresenter&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Margin&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;4&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
                    &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;ControlTemplate&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
                &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;Setter.Value&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
            &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;Setter&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;Style&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;ListBox.ItemContainerStyle&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;ListBox&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;The data context of this ListBox is a ViewModel with the Lights property. Lights is a collection of five Light objects.&lt;/p&gt;

&lt;p&gt;One property that the Light object exposes is the Brush property; it will simply point to a solid color brush of a red, yellow or green color, respectively. The Ellipse’s Fill property is bound to the Brush property as can observed in the above code.&lt;/p&gt;

&lt;p&gt;Semaphores usually change colors in an order. The ones in this sample will blink randomly, changing their colors in 2 second intervals:&lt;/p&gt;

&lt;div&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; Light()
{
    &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.SetColor();
    DispatcherTimer timer = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; DispatcherTimer()
    {
        Interval = TimeSpan.FromSeconds(2.0)
    };
    
    timer.Tick += (s, e) =&amp;gt; { &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.SetColor(); };
    timer.Start();
}

&lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; SetColor()
{
    Color[] colorArray = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Color[] { Colors.Red, Colors.Yellow, Colors.Green };
    Color color = colorArray[randomizer.Next(0, 3)];
    &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.Brush = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; SolidColorBrush(color);
    &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.IsEnabled = color == Colors.Green;
}&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;Now, we want to allow the user click only on green light, OK? The last line in the above SetColor method sets the IsEnabled property on the Light object only when the current color is set to Green.&lt;/p&gt;

&lt;p&gt;With the IsEnabled property up and about, it gets really easy. To prevent the user from clicking on the ListBox item, simply set bind its IsHitTestVisible property to IsEnabled property on the Light class (bold underlined part added):&lt;/p&gt;

&lt;div&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;ControlTemplate&lt;/span&gt; &lt;span style="color: #ff0000"&gt;TargetType&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;ListBoxItem&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;ContentPresenter&lt;/span&gt; &lt;span style="color: #ff0000"&gt;x:Name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;contentPresenter&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Margin&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;4&amp;quot;&lt;/span&gt; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;strong&gt;&lt;u&gt;&lt;span style="color: #ff0000"&gt;IsHitTestVisible&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;{Binding IsEnabled}&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Cursor&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Hand&amp;quot;&lt;/span&gt;&lt;/u&gt;&lt;/strong&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;ControlTemplate&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;[Cursor property is there for instant visual feedback on when the item is enabled]&lt;/p&gt;

&lt;p&gt;That’s it, really. You can test it by adding i.e. a Click event handler to the contentPresenter and display a message box or something (included in the sample below). You would also want to build a better templates for the enabled/disabled items. If built around the bound IsEnabled property, it should work fine.&lt;/p&gt;

&lt;p align="center"&gt;&lt;iframe src="http://tozon.info/sl/semaphore/" frameborder="0" width="500" height="60"&gt;&lt;/iframe&gt;&lt;/p&gt;

&lt;p&gt;&lt;iframe style="border-right: #dde5e9 1px solid; padding-right: 0px; border-top: #dde5e9 1px solid; padding-left: 0px; padding-bottom: 0px; margin: 3px; border-left: #dde5e9 1px solid; width: 240px; padding-top: 0px; border-bottom: #dde5e9 1px solid; height: 66px; background-color: #ffffff" marginwidth="0" marginheight="0" src="http://cid-d34608bce9688fba.skydrive.live.com/embedrowdetail.aspx/Public/Development/Samples/Semaphore.zip" frameborder="0" scrolling="no"&gt;&lt;/iframe&gt;&lt;/p&gt;&lt;div class="wlWriterHeaderFooter" style="text-align:left; margin:0px; padding:4px 4px 4px 4px;"&gt;&lt;a href="http://www.dotnetkicks.com/kick/?url=http://tozon.info/blog/post/2009/03/10/Disabling-items-in-a-Silverlight-ListBox.aspx"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://tozon.info/blog/post/2009/03/10/Disabling-items-in-a-Silverlight-ListBox.aspx&amp;amp;bgcolor=0080C0&amp;amp;fgcolor=FFFFFF&amp;amp;border=000000&amp;amp;cbgcolor=D4E1ED&amp;amp;cfgcolor=000000" border="0/"&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=Y5E7eiowHWY:YU4bfeWbOZI:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=Y5E7eiowHWY:YU4bfeWbOZI:D7DqB2pKExk"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?i=Y5E7eiowHWY:YU4bfeWbOZI:D7DqB2pKExk" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=Y5E7eiowHWY:YU4bfeWbOZI:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?i=Y5E7eiowHWY:YU4bfeWbOZI:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=Y5E7eiowHWY:YU4bfeWbOZI:dnMXMwOfBR0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?d=dnMXMwOfBR0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=Y5E7eiowHWY:YU4bfeWbOZI:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?i=Y5E7eiowHWY:YU4bfeWbOZI:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=Y5E7eiowHWY:YU4bfeWbOZI:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=Y5E7eiowHWY:YU4bfeWbOZI:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?i=Y5E7eiowHWY:YU4bfeWbOZI:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=Y5E7eiowHWY:YU4bfeWbOZI:I9og5sOYxJI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?d=I9og5sOYxJI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=Y5E7eiowHWY:YU4bfeWbOZI:V-t1I-SPZMU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?d=V-t1I-SPZMU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=Y5E7eiowHWY:YU4bfeWbOZI:Jwdi1b3fU3Q"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?d=Jwdi1b3fU3Q" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/TheAttic/~4/Y5E7eiowHWY" height="1" width="1"/&gt;</description>
      <link>http://feedproxy.google.com/~r/TheAttic/~3/Y5E7eiowHWY/post.aspx</link>
      <author>andrej</author>
      <comments>http://www.tozon.info/blog/post/2009/03/10/Disabling-items-in-a-Silverlight-ListBox.aspx#comment</comments>
      <guid isPermaLink="false">http://www.tozon.info/blog/post.aspx?id=43e7138f-7242-4b9f-b01f-89e68dc62dd0</guid>
      <pubDate>Tue, 10 Mar 2009 14:27:12 -0700</pubDate>
      <category>Development</category>
      <category>MVVM</category>
      <category>Layout</category>
      <category>Silverlight</category>
      <dc:publisher>andrej</dc:publisher>
      <pingback:server>http://www.tozon.info/blog/pingback.axd</pingback:server>
      <pingback:target>http://www.tozon.info/blog/post.aspx?id=43e7138f-7242-4b9f-b01f-89e68dc62dd0</pingback:target>
      <slash:comments>3</slash:comments>
      <trackback:ping>http://www.tozon.info/blog/trackback.axd?id=43e7138f-7242-4b9f-b01f-89e68dc62dd0</trackback:ping>
      <wfw:comment>http://www.tozon.info/blog/post/2009/03/10/Disabling-items-in-a-Silverlight-ListBox.aspx#comment</wfw:comment>
      <wfw:commentRss>http://www.tozon.info/blog/syndication.axd?post=43e7138f-7242-4b9f-b01f-89e68dc62dd0</wfw:commentRss>
    <feedburner:origLink>http://www.tozon.info/blog/post.aspx?id=43e7138f-7242-4b9f-b01f-89e68dc62dd0</feedburner:origLink></item>
    <item>
      <title>Declarative Role-based “security” for Silverlight Xaml elements</title>
      <description>&lt;p&gt;&lt;a href="http://www.timheuer.com/" target="_blank"&gt;Tim Heuer&lt;/a&gt; published a great example on how to implement user authentication and role validation with ASP.NET Application Services in his &lt;a href="http://silverlight.net/learn/appcorner/adventureworkspt1.aspx?pt=1&amp;amp;PageIndex=2" target="_blank"&gt;Application Corner&lt;/a&gt; a while ago. It really works as expected, even with custom membership / role providers. And you get to do declarative role based security checks on your server side classes too.&lt;/p&gt;  &lt;p&gt;When building MVVM pattern applications, you tend to have as less code as possible in your views’ code-behind classes. Call me a MVVM purist [ :), see &lt;a href="http://pixel8.infragistics.com/default.aspx#Episode:11927" target="_blank"&gt;Tim’s video interview for pixel8&lt;/a&gt; ], but (close to) zero lines of custom code is what I like to have in my code-behinds. Not at all costs, but usually it doesn’t take much to code additional helper class, an attached property or a controller of some sort.&lt;/p&gt;  &lt;p&gt;What I wanted to do, was replace the following piece of code with something more declarative, which could be used in Xaml:&lt;/p&gt;  &lt;div&gt;   &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; EnableAppFeatures(ObservableCollection&amp;lt;&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;&amp;gt; roles)
{
    EmployeeButton.IsEnabled = (roles.Contains(&lt;span style="color: #006080"&gt;&amp;quot;Admin&amp;quot;&lt;/span&gt;) || roles.Contains(&lt;span style="color: #006080"&gt;&amp;quot;HR&amp;quot;&lt;/span&gt;));
    OrderButton.IsEnabled = (roles.Contains(&lt;span style="color: #006080"&gt;&amp;quot;Admin&amp;quot;&lt;/span&gt;) || roles.Contains(&lt;span style="color: #006080"&gt;&amp;quot;Sales&amp;quot;&lt;/span&gt;));
    CustomersButton.IsEnabled = (roles.Contains(&lt;span style="color: #006080"&gt;&amp;quot;Admin&amp;quot;&lt;/span&gt;) || roles.Contains(&lt;span style="color: #006080"&gt;&amp;quot;Sales&amp;quot;&lt;/span&gt;));
    ReportsButton.IsEnabled = (roles.Contains(&lt;span style="color: #006080"&gt;&amp;quot;Admin&amp;quot;&lt;/span&gt;) || roles.Contains(&lt;span style="color: #006080"&gt;&amp;quot;Sales&amp;quot;&lt;/span&gt;));
}&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;[the roles string collection comes in as a result of the Roles service call]&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Solution #1 - Good&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;I&lt;/strong&gt;f you’re using MVVM, adding some additional properties to your ViewModels (like IsInHRRole, IsInSalesRole, etc) should be easy, right? You would just need to bind al the buttons’ IsEnabled properties to their ViewModel counterparts and you’re done. &lt;/p&gt;

&lt;div&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;Button&lt;/span&gt; ... &lt;span style="color: #ff0000"&gt;x:Name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;ReportsButton&amp;quot;&lt;/span&gt; ... &lt;span style="color: #ff0000"&gt;IsEnabled&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;{Binding IsInSalesRole}&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;True, but you’ll probably end up “polluting” all your ViewModels with such properties since usually the majority of the Views have some elements, depending on a role the user is in. Additionally, you’d have to create additional properties for combined roles, e.g. &lt;em&gt;IsInSalesOrAdminRole&lt;/em&gt;,&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Solution #2 - Better&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I was thinking somewhere in the lines of attaching a new attached property to each button, which would enable the button when the user would be in one of the specified roles:&lt;/p&gt;

&lt;div&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;Button&lt;/span&gt; ... &lt;span style="color: #ff0000"&gt;x:Name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;ReportsButton&amp;quot;&lt;/span&gt; ... &lt;span style="color: #ff0000"&gt;sec:SecurityAction&lt;/span&gt;.&lt;span style="color: #ff0000"&gt;DemandRole&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Sales,Admin&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;SecurityAction.DemandRole in this case is an attached property, specifying all the roles, which would make the button enabled. The logic is simple – if the user is in one of the specified roles, the button (or any other control with this attribute appended) would have its IsEnabled property set to true.&amp;#160; &lt;/p&gt;

&lt;div&gt;To make this possible, I first had to come up with a class to hold all the current roles, something like a &lt;a href="http://msdn.microsoft.com/en-us/library/axt6w9h8.aspx" target="_blank"&gt;Principal&lt;/a&gt;… This is a short class, supporting roles only that will do a job for this demonstration:&lt;/div&gt;

&lt;div&gt;&amp;#160;&lt;/div&gt;

&lt;div&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; SilverlightPrincipal
{
    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; ObservableCollection&amp;lt;&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;&amp;gt; Roles { get; &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; set; }

    &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; SilverlightPrincipal()
    {
        Roles = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; ObservableCollection&amp;lt;&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;&amp;gt;();
    }

    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; SetRoles(IList&amp;lt;&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;&amp;gt; roles)
    {
        Roles.Clear();
        &lt;span style="color: #0000ff"&gt;for&lt;/span&gt; (&lt;span style="color: #0000ff"&gt;int&lt;/span&gt; i = 0; i &amp;lt; roles.Count; i++)
        {
            Roles.Add(roles[i]);
        }
    }
    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;bool&lt;/span&gt; IsInRole(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; role)
    {
        &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; Roles.Contains(role);
    }

    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;bool&lt;/span&gt; IsInOneOfRoles(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;[] roles)
    {
        &lt;span style="color: #0000ff"&gt;for&lt;/span&gt; (&lt;span style="color: #0000ff"&gt;int&lt;/span&gt; i = 0; i &amp;lt; roles.Length; i++)
        {
            &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (Roles.Contains(roles[i]))
            {
                &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; &lt;span style="color: #0000ff"&gt;true&lt;/span&gt;;
            }
        }
        &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; &lt;span style="color: #0000ff"&gt;false&lt;/span&gt;;
    }
}&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;The roles collection will contain all roles the user is currently in. IsInRole() and IsInOneOfRoles() will return true, if user is in one of the passed in roles. The SetRoles() method is here for simplicity – it servers just as a roles setter, called from wherever the Roles service calls returns.&lt;/p&gt;

&lt;p&gt;Perhaps the class above probably doesn’t even deserve to be called a &lt;em&gt;Principal&lt;/em&gt;, but it will serve well for the purpose of this post. For more ideas to implement a more complete Silverlight Principal, check &lt;a href="http://www.myblogon.net/archive/2008/05/22/creating-a-custom-principal-and-identity-for-silverlight-2.aspx" target="_blank"&gt;this blog post&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;To plug it in Tim’s code, I used the aforementioned EnableAppFeatures method, which now looks like:&lt;/p&gt;

&lt;div&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; EnableAppFeatures(ObservableCollection&amp;lt;&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;&amp;gt; roles)
{
    SilverlightPrincipal.SetRoles(roles);
}&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;The next thing to do was create the SecurityAction.DemandRole attached property that could be used to set the required roles to a specific control. You’ll find this attached property in the sample code attached to this post. I’m not including the code here because it will make this post much longer and I’m not really fond of using it anyway, because of the reasons for solution #3 below. However, feel free to try the property and please leave comment if you like (or dislike) it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Solution #3 - Best&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;After creating #2, I thought – if user can never access the functionality behind the buttons, there is no need to show the buttons to her in the first place, right? Why not showing her the dashboard, created specifically for her role? Sounds familiar? ASP.NET? LoginView?&lt;/p&gt;

&lt;p&gt;Here’s my simple &lt;strong&gt;LoginView control for Silverlight&lt;/strong&gt;. You can define as many LoginView templates for as many roles you have:&lt;/p&gt;

&lt;div&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;controls:LoginView&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;controls:LoginView.Templates&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;controls:LoginViewDataTemplate&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Roles&lt;/span&gt;=&amp;quot;&lt;span style="color: #ff0000"&gt;HR&lt;/span&gt;”&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
            &lt;span style="color: #008000"&gt;&amp;lt;!-- Layout for HR role --&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;controls:LoginViewDataTemplate&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;controls:LoginViewDataTemplate&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Roles&lt;/span&gt;=&amp;quot;&lt;span style="color: #ff0000"&gt;Sales&lt;/span&gt;”&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
        &lt;span style="color: #008000"&gt;&amp;lt;!-- Layout for Sales role --&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;controls:LoginViewDataTemplate&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;controls:LoginViewDataTemplate&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Roles&lt;/span&gt;=&amp;quot;&lt;span style="color: #ff0000"&gt;Admin&lt;/span&gt;”&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
            &lt;span style="color: #008000"&gt;&amp;lt;!-- Layout for Admin role --&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;controls:LoginViewDataTemplate&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
     &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;controls:LoginView.Templates&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;controls:LoginView&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;div&gt;&amp;#160;&lt;/div&gt;

&lt;div&gt;First, here’s the &lt;strong&gt;LoginViewTemplate&lt;/strong&gt; class:&lt;/div&gt;

&lt;div&gt;&amp;#160;&lt;/div&gt;

&lt;div&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; LoginViewDataTemplate : DataTemplate
{
    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; Roles { get; set; }
}&lt;/pre&gt;
&lt;/div&gt;

&lt;div&gt;Yeah, that’s pretty much it. The &lt;strong&gt;Roles&lt;/strong&gt; property will hold the list of roles, which are allowed to see the template.&lt;/div&gt;

&lt;div&gt;&amp;#160;&lt;/div&gt;

&lt;div&gt;The &lt;strong&gt;LoginView&lt;/strong&gt; control itself is simple too:&lt;/div&gt;

&lt;div&gt;&amp;#160;&lt;/div&gt;

&lt;div&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; LoginView : UserControl
{
    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; Collection&amp;lt;LoginViewDataTemplate&amp;gt; Templates { get; set; }

    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; LoginView()
    {
        Templates = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Collection&amp;lt;LoginViewDataTemplate&amp;gt;();

        SilverlightPrincipal.RegisterForRoleChangeNotification(&lt;span style="color: #0000ff"&gt;this&lt;/span&gt;, LoadTemplate);
        Loaded += (s,e) =&amp;gt; { LoadTemplate(); };
    }

    &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; LoadTemplate()
    {
        &lt;span style="color: #0000ff"&gt;for&lt;/span&gt; (&lt;span style="color: #0000ff"&gt;int&lt;/span&gt; i = 0; i &amp;lt; Templates.Count; i++)
        {
            &lt;span style="color: #0000ff"&gt;string&lt;/span&gt;[] roleNames = Templates[i].Roles.Split(&lt;span style="color: #0000ff"&gt;new&lt;/span&gt; &lt;span style="color: #0000ff"&gt;char&lt;/span&gt;[] { &lt;span style="color: #006080"&gt;','&lt;/span&gt;, &lt;span style="color: #006080"&gt;' '&lt;/span&gt; }, &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; StringSplitOptions.RemoveEmptyEntries);
            &lt;span style="color: #0000ff"&gt;bool&lt;/span&gt; isInRole = SilverlightPrincipal.IsInOneOfRoles(roleNames);
            &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (isInRole)
            {
                Content = Templates[i].LoadContent() &lt;span style="color: #0000ff"&gt;as&lt;/span&gt; UIElement;
                &lt;span style="color: #0000ff"&gt;return&lt;/span&gt;;
            }
        }

        Content = &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;;
    }
}&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;[Update 06-13: updated the above code; should work now]&lt;/p&gt;

&lt;p&gt;There’s not much to comment here… The &lt;strong&gt;Templates&lt;/strong&gt; collection holds the collection of, errr., &lt;strong&gt;LoginViewDataTemplates&lt;/strong&gt;, and the &lt;strong&gt;LoadTemplate&lt;/strong&gt; method is there to Load the first template, having one of the specified roles match the current role that user is in. This could be easily extended to support the &lt;em&gt;default&lt;/em&gt; template, if needed. The default template would be loaded when no other template would match the current user’s role.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;RoleChanged notification /execution&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The right template is loaded with the control and whenever the Roles might change, the control would reload the template. I’ve implemented this behavior by adding a registration method for role change notification. Any visual element (or whatever object for that matter) can register itself by passing in the delegate to whatever method should be called whenever role(s) would change. The registration method was conveniently added to existing SilverlightPrincipal class:&lt;/p&gt;

&lt;div&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; RegisterForRoleChangeNotification(&lt;span style="color: #0000ff"&gt;object&lt;/span&gt; o, Action action)
{
    &lt;span style="color: #0000ff"&gt;bool&lt;/span&gt; existsInCollection = references.Keys.FirstOrDefault(reference =&amp;gt; reference.Target == o) != &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;;
    &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (!existsInCollection)
    {
        references.Add(&lt;span style="color: #0000ff"&gt;new&lt;/span&gt; WeakReference(o), action);
    }
}&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;Whenever the roles would change, register objects’ delegate would be called:&lt;/p&gt;

&lt;div&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; OnRolesChanged()
{
    CleanUp();
    &lt;span style="color: #0000ff"&gt;foreach&lt;/span&gt; (var reference &lt;span style="color: #0000ff"&gt;in&lt;/span&gt; references)
    {
        reference.Value();
    }
}&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;The CleanUp method takes care for dead/disposed objects:&lt;/p&gt;

&lt;div&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; CleanUp()
{
    List&amp;lt;WeakReference&amp;gt; list = references.Keys.ToList&amp;lt;WeakReference&amp;gt;();
    &lt;span style="color: #0000ff"&gt;for&lt;/span&gt; (&lt;span style="color: #0000ff"&gt;int&lt;/span&gt; i = list.Count - 1; i &amp;gt;= 0; i--)
    {
        WeakReference r = list[i];
        &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (!r.IsAlive)
        {
            references.Remove(r);
        }
    }
}&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;Classes, included in the package: SilverlightPrincipal, SecurityAction, LoginView:&lt;/p&gt;

&lt;p&gt;&lt;iframe style="border-right: #dde5e9 1px solid; padding-right: 0px; border-top: #dde5e9 1px solid; padding-left: 0px; padding-bottom: 0px; margin: 3px; border-left: #dde5e9 1px solid; width: 240px; padding-top: 0px; border-bottom: #dde5e9 1px solid; height: 66px; background-color: #ffffff" marginwidth="0" marginheight="0" src="http://cid-d34608bce9688fba.skydrive.live.com/embedrowdetail.aspx/Public/Development/Samples/SLLoginView.zip" frameborder="0" scrolling="no"&gt;&lt;/iframe&gt;&lt;/p&gt;&lt;div class="wlWriterHeaderFooter" style="text-align:left; margin:0px; padding:4px 4px 4px 4px;"&gt;&lt;a href="http://www.dotnetkicks.com/kick/?url=http://tozon.info/blog/post/2009/03/06/Declarative-Role-based-e2809csecuritye2809d-for-Silverlight-Xaml-elements.aspx"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://tozon.info/blog/post/2009/03/06/Declarative-Role-based-e2809csecuritye2809d-for-Silverlight-Xaml-elements.aspx&amp;amp;bgcolor=0080C0&amp;amp;fgcolor=FFFFFF&amp;amp;border=000000&amp;amp;cbgcolor=D4E1ED&amp;amp;cfgcolor=000000" border="0/"&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=dDMXL110rYY:V3MwPi9nFCI:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=dDMXL110rYY:V3MwPi9nFCI:D7DqB2pKExk"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?i=dDMXL110rYY:V3MwPi9nFCI:D7DqB2pKExk" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=dDMXL110rYY:V3MwPi9nFCI:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?i=dDMXL110rYY:V3MwPi9nFCI:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=dDMXL110rYY:V3MwPi9nFCI:dnMXMwOfBR0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?d=dnMXMwOfBR0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=dDMXL110rYY:V3MwPi9nFCI:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?i=dDMXL110rYY:V3MwPi9nFCI:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=dDMXL110rYY:V3MwPi9nFCI:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=dDMXL110rYY:V3MwPi9nFCI:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?i=dDMXL110rYY:V3MwPi9nFCI:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=dDMXL110rYY:V3MwPi9nFCI:I9og5sOYxJI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?d=I9og5sOYxJI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=dDMXL110rYY:V3MwPi9nFCI:V-t1I-SPZMU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?d=V-t1I-SPZMU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=dDMXL110rYY:V3MwPi9nFCI:Jwdi1b3fU3Q"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?d=Jwdi1b3fU3Q" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/TheAttic/~4/dDMXL110rYY" height="1" width="1"/&gt;</description>
      <link>http://feedproxy.google.com/~r/TheAttic/~3/dDMXL110rYY/post.aspx</link>
      <author>andrej</author>
      <comments>http://www.tozon.info/blog/post/2009/03/06/Declarative-Role-based-e2809csecuritye2809d-for-Silverlight-Xaml-elements.aspx#comment</comments>
      <guid isPermaLink="false">http://www.tozon.info/blog/post.aspx?id=ef8d6ca0-7adf-4dfa-978b-3bc7cb74821d</guid>
      <pubDate>Fri, 06 Mar 2009 14:53:20 -0700</pubDate>
      <category>Development</category>
      <category>MVVM</category>
      <category>Silverlight</category>
      <category>User Experience</category>
      <dc:publisher>andrej</dc:publisher>
      <pingback:server>http://www.tozon.info/blog/pingback.axd</pingback:server>
      <pingback:target>http://www.tozon.info/blog/post.aspx?id=ef8d6ca0-7adf-4dfa-978b-3bc7cb74821d</pingback:target>
      <slash:comments>6</slash:comments>
      <trackback:ping>http://www.tozon.info/blog/trackback.axd?id=ef8d6ca0-7adf-4dfa-978b-3bc7cb74821d</trackback:ping>
      <wfw:comment>http://www.tozon.info/blog/post/2009/03/06/Declarative-Role-based-e2809csecuritye2809d-for-Silverlight-Xaml-elements.aspx#comment</wfw:comment>
      <wfw:commentRss>http://www.tozon.info/blog/syndication.axd?post=ef8d6ca0-7adf-4dfa-978b-3bc7cb74821d</wfw:commentRss>
    <feedburner:origLink>http://www.tozon.info/blog/post.aspx?id=ef8d6ca0-7adf-4dfa-978b-3bc7cb74821d</feedburner:origLink></item>
    <item>
      <title>The magic happened… again</title>
      <description>&lt;p&gt;I wrote &lt;a href="http://tozon.info/blog/post/2007/01/21/A-new-life.aspx"&gt;this short program&lt;/a&gt; some two years ago and yesterday came time for an upgrade.&lt;/p&gt;  &lt;p&gt;Yesterday evening, a gift of life was given to another beautiful princess, Evita, 3730g, 51cm.&lt;/p&gt;  &lt;p&gt;Her big sister is very proud and already looking after her, and mom’s doing great.&lt;/p&gt;&lt;div class="wlWriterHeaderFooter" style="text-align:left; margin:0px; padding:4px 4px 4px 4px;"&gt;&lt;a href="http://www.dotnetkicks.com/kick/?url=http://tozon.info/blog/post/2009/03/06/The-magic-happenede280a6-again.aspx"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://tozon.info/blog/post/2009/03/06/The-magic-happenede280a6-again.aspx&amp;amp;bgcolor=0080C0&amp;amp;fgcolor=FFFFFF&amp;amp;border=000000&amp;amp;cbgcolor=D4E1ED&amp;amp;cfgcolor=000000" border="0/"&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=rtWQ9h5Uikk:6uuugb_qyL8:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=rtWQ9h5Uikk:6uuugb_qyL8:D7DqB2pKExk"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?i=rtWQ9h5Uikk:6uuugb_qyL8:D7DqB2pKExk" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=rtWQ9h5Uikk:6uuugb_qyL8:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?i=rtWQ9h5Uikk:6uuugb_qyL8:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=rtWQ9h5Uikk:6uuugb_qyL8:dnMXMwOfBR0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?d=dnMXMwOfBR0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=rtWQ9h5Uikk:6uuugb_qyL8:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?i=rtWQ9h5Uikk:6uuugb_qyL8:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=rtWQ9h5Uikk:6uuugb_qyL8:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=rtWQ9h5Uikk:6uuugb_qyL8:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?i=rtWQ9h5Uikk:6uuugb_qyL8:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=rtWQ9h5Uikk:6uuugb_qyL8:I9og5sOYxJI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?d=I9og5sOYxJI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=rtWQ9h5Uikk:6uuugb_qyL8:V-t1I-SPZMU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?d=V-t1I-SPZMU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheAttic?a=rtWQ9h5Uikk:6uuugb_qyL8:Jwdi1b3fU3Q"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheAttic?d=Jwdi1b3fU3Q" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/TheAttic/~4/rtWQ9h5Uikk" height="1" width="1"/&gt;</description>
      <link>http://feedproxy.google.com/~r/TheAttic/~3/rtWQ9h5Uikk/post.aspx</link>
      <author>andrej</author>
      <comments>http://www.tozon.info/blog/post/2009/03/06/The-magic-happenede280a6-again.aspx#comment</comments>
      <guid isPermaLink="false">http://www.tozon.info/blog/post.aspx?id=d8a4db80-90de-49ab-9dd7-e2d27c77f3cf</guid>
      <pubDate>Fri, 06 Mar 2009 14:45:19 -0700</pubDate>
      <category>Personal</category>
      <dc:publisher>andrej</dc:publisher>
      <pingback:server>http://www.tozon.info/blog/pingback.axd</pingback:server>
      <pingback:target>http://www.tozon.info/blog/post.aspx?id=d8a4db80-90de-49ab-9dd7-e2d27c77f3cf</pingback:target>
      <slash:comments>3</slash:comments>
      <trackback:ping>http://www.tozon.info/blog/trackback.axd?id=d8a4db80-90de-49ab-9dd7-e2d27c77f3cf</trackback:ping>
      <wfw:comment>http://www.tozon.info/blog/post/2009/03/06/The-magic-happenede280a6-again.aspx#comment</wfw:comment>
      <wfw:commentRss>http://www.tozon.info/blog/syndication.axd?post=d8a4db80-90de-49ab-9dd7-e2d27c77f3cf</wfw:commentRss>
    <feedburner:origLink>http://www.tozon.info/blog/post.aspx?id=d8a4db80-90de-49ab-9dd7-e2d27c77f3cf</feedburner:origLink></item>
    <item>
      <title>Binding to Enums</title>
      <description>&lt;p&gt;I’ve seen numerous questions regarding data binding to Enums, together with many solutions on how to do it, but the question I’m asking myself is – do I really want to bind anything to an Enum?&lt;/p&gt;  &lt;p&gt;I like to think about Enums purely as a coding aid – to help programmer code with some descriptive names instead of messing with pure numeric values. Similar to what constants are for, except Enums provide a set of values for describing a single parameter.&lt;/p&gt;  &lt;p&gt;Instead of:&lt;/p&gt;  &lt;div&gt;   &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;product.Quality = 3;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;the programmer would write:&lt;/p&gt;

&lt;div&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;product.Quality = Quality.Good;&lt;/pre&gt;
&lt;/div&gt;

&lt;div&gt;&amp;#160;&lt;/div&gt;

&lt;div&gt;… providing that Quality Enum is declared something like:&lt;/div&gt;

&lt;div&gt;&amp;#160;&lt;/div&gt;

&lt;div&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;enum&lt;/span&gt; Quality
{
    JustBad, Poor, OK, Good, Excellent
}&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;Of course, you could set your enum values to some concrete numbers, like:&lt;/p&gt;

&lt;div&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;enum&lt;/span&gt; Quality
{
    JustBad = 1, Poor = 2, OK = 3, Good = 4, Excellent = 5
}&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;… but in most cases you shouldn’t need to. Like I said, I see Enums only as a &lt;em&gt;before-compilation&lt;/em&gt;, &lt;em&gt;human &amp;lt;-&amp;gt; code&lt;/em&gt; communication, and therefore I believe no part of Enum should ever see the light of day (i.e. be exposed to the UI). And with that, there goes the need for binding to Enums…&lt;/p&gt;

&lt;p&gt;Why would I want to bind to Enums anyway? Enum enumerators have no description (other than their names). If you need to provide spaces or even support localized descriptions, you’ll need to extend them significantly, so why not create a new class anyway? Here’s what I use instead of an Enum:&lt;/p&gt;

&lt;div&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;sealed&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; Quality
{
    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;const&lt;/span&gt; &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; JustBad = 1;
    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;const&lt;/span&gt; &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; Poor = 2;
    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;const&lt;/span&gt; &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; OK = 3;
    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;const&lt;/span&gt; &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; Good = 4;
    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;const&lt;/span&gt; &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; Excellent = 5;

    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; Dictionary&amp;lt;&lt;span style="color: #0000ff"&gt;int&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;string&lt;/span&gt;&amp;gt; Collection { get; &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; set; }

    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; Quality()
    {
        Collection = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Dictionary&amp;lt;&lt;span style="color: #0000ff"&gt;int&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;string&lt;/span&gt;&amp;gt;()
        {
            {JustBad,   &lt;span style="color: #006080"&gt;&amp;quot;Just bad :(&amp;quot;&lt;/span&gt;},
            {Poor,      &lt;span style="color: #006080"&gt;&amp;quot;Poor&amp;quot;&lt;/span&gt;},
            {OK,        &lt;span style="color: #006080"&gt;&amp;quot;OK&amp;quot;&lt;/span&gt;},
            {Good,      &lt;span style="color: #006080"&gt;&amp;quot;Good&amp;quot;&lt;/span&gt;},
            {Excellent, &lt;span style="color: #006080"&gt;&amp;quot;Excellent!&amp;quot;&lt;/span&gt;},
        };
    }
}&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;The programmer would still write:&lt;/p&gt;

&lt;div&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;product.Quality = Quality.Good;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;so it makes it easy to refactor existing code. Additionally, you can put in any description for the values, support localization, and it’s easy bindable in Xaml - declare the class instance as a local resource:&lt;/p&gt;

&lt;div&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;local:Quality&lt;/span&gt; &lt;span style="color: #ff0000"&gt;x:Key&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;quality&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
and bind away:&lt;/div&gt;

&lt;div&gt;&amp;#160;&lt;/div&gt;

&lt;div&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;ListBox&lt;/span&gt; &lt;span style="color: #ff0000"&gt;DisplayMemberPath&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Value&amp;quot;&lt;/span&gt; 
         &lt;span style="color: #ff0000"&gt;ItemsSource&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;{Binding Collection, Source={StaticResource quality}}&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;&lt;div class="wlWriterHeaderFooter" style="text-align:left; margin:0px; padding:4px 4px 4px 4px;"&gt;&lt;a href="http://www.dotnetkicks.com/kick/?url=http://tozon.info/blog/post/2009/02/16/Binding-to-Enums.aspx"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://tozon.info/blog/post/2009/02/16/Binding-to-Enums.aspx&amp;amp;bgcolor=0080C0&amp;amp;fgcolor=FFFFFF&amp;amp;border=000000&amp;amp;cbgcolor=D4E1ED&amp;amp;cfgcolor=000000" border="0/"&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~f/TheAttic?a=YOy1bfcH"&gt;&lt;img src="http://feeds.feedburner.com/~f/TheAttic?d=41" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~f/TheAttic?a=AbCUnAld"&gt;&lt;img src="http://feeds.feedburner.com/~f/TheAttic?i=AbCUnAld" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~f/TheAttic?a=uTnBDTBk"&gt;&lt;img src="http://feeds.feedburner.com/~f/TheAttic?i=uTnBDTBk" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~f/TheAttic?a=vow5eBPz"&gt;&lt;img src="http://feeds.feedburner.com/~f/TheAttic?d=43" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~f/TheAttic?a=5TYPDDh8"&gt;&lt;img src="http://feeds.feedburner.com/~f/TheAttic?i=5TYPDDh8" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~f/TheAttic?a=GBRNLYzq"&gt;&lt;img src="http://feeds.feedburner.com/~f/TheAttic?d=52" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~f/TheAttic?a=GA4tdlKd"&gt;&lt;img src="http://feeds.feedburner.com/~f/TheAttic?i=GA4tdlKd" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~f/TheAttic?a=Vw7XS5UL"&gt;&lt;img src="http://feeds.feedburner.com/~f/TheAttic?d=124" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~f/TheAttic?a=MoXUvmEA"&gt;&lt;img src="http://feeds.feedburner.com/~f/TheAttic?d=133" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~f/TheAttic?a=8ybwYexJ"&gt;&lt;img src="http://feeds.feedburner.com/~f/TheAttic?d=238" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/TheAttic/~4/dUbWRpDL_oM" height="1" width="1"/&gt;</description>
      <link>http://feedproxy.google.com/~r/TheAttic/~3/dUbWRpDL_oM/post.aspx</link>
      <author>andrej</author>
      <comments>http://www.tozon.info/blog/post/2009/02/16/Binding-to-Enums.aspx#comment</comments>
      <guid isPermaLink="false">http://www.tozon.info/blog/post.aspx?id=c785a521-ec58-4c2b-88f4-c4ea92e5f150</guid>
      <pubDate>Mon, 16 Feb 2009 05:13:29 -0700</pubDate>
      <category>Development</category>
      <category>Silverlight</category>
      <category>WPF</category>
      <dc:publisher>andrej</dc:publisher>
      <pingback:server>http://www.tozon.info/blog/pingback.axd</pingback:server>
      <pingback:target>http://www.tozon.info/blog/post.aspx?id=c785a521-ec58-4c2b-88f4-c4ea92e5f150</pingback:target>
      <slash:comments>7</slash:comments>
      <trackback:ping>http://www.tozon.info/blog/trackback.axd?id=c785a521-ec58-4c2b-88f4-c4ea92e5f150</trackback:ping>
      <wfw:comment>http://www.tozon.info/blog/post/2009/02/16/Binding-to-Enums.aspx#comment</wfw:comment>
      <wfw:commentRss>http://www.tozon.info/blog/syndication.axd?post=c785a521-ec58-4c2b-88f4-c4ea92e5f150</wfw:commentRss>
    <feedburner:origLink>http://www.tozon.info/blog/post.aspx?id=c785a521-ec58-4c2b-88f4-c4ea92e5f150</feedburner:origLink></item>
  </channel>
</rss>
