<?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:atom="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/" xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule" version="2.0"><channel><atom:id>tag:blogger.com,1999:blog-7411255283791998153</atom:id><lastBuildDate>Sat, 07 Nov 2009 03:25:24 +0000</lastBuildDate><title>Project Silverlight</title><description>My adventures into the wonderful world of Silverlight 2.0!</description><link>http://projectsilverlight.blogspot.com/</link><managingEditor>noreply@blogger.com (Wilfred Pinto)</managingEditor><generator>Blogger</generator><openSearch:totalResults>34</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><geo:lat>34.143856</geo:lat><geo:long>-118.394293</geo:long><creativeCommons:license>http://creativecommons.org/licenses/by/3.0/</creativeCommons:license><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://projectsilverlight.blogspot.com/feeds/posts/default" type="application/rss+xml" /><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://add.my.yahoo.com/rss?url=http%3A%2F%2Fprojectsilverlight.blogspot.com%2Ffeeds%2Fposts%2Fdefault" src="http://us.i1.yimg.com/us.yimg.com/i/us/my/addtomyyahoo4.gif">Subscribe with My Yahoo!</feedburner:feedFlare><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://www.newsgator.com/ngs/subscriber/subext.aspx?url=http%3A%2F%2Fprojectsilverlight.blogspot.com%2Ffeeds%2Fposts%2Fdefault" src="http://www.newsgator.com/images/ngsub1.gif">Subscribe with NewsGator</feedburner:feedFlare><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://feeds.my.aol.com/add.jsp?url=http%3A%2F%2Fprojectsilverlight.blogspot.com%2Ffeeds%2Fposts%2Fdefault" src="http://o.aolcdn.com/favorites.my.aol.com/webmaster/ffclient/webroot/locale/en-US/images/myAOLButtonSmall.gif">Subscribe with My AOL</feedburner:feedFlare><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://www.bloglines.com/sub/http://projectsilverlight.blogspot.com/feeds/posts/default" src="http://www.bloglines.com/images/sub_modern11.gif">Subscribe with Bloglines</feedburner:feedFlare><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://www.netvibes.com/subscribe.php?url=http%3A%2F%2Fprojectsilverlight.blogspot.com%2Ffeeds%2Fposts%2Fdefault" src="http://www.netvibes.com/img/add2netvibes.gif">Subscribe with Netvibes</feedburner:feedFlare><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://fusion.google.com/add?feedurl=http%3A%2F%2Fprojectsilverlight.blogspot.com%2Ffeeds%2Fposts%2Fdefault" src="http://buttons.googlesyndication.com/fusion/add.gif">Subscribe with Google</feedburner:feedFlare><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://www.pageflakes.com/subscribe.aspx?url=http%3A%2F%2Fprojectsilverlight.blogspot.com%2Ffeeds%2Fposts%2Fdefault" src="http://www.pageflakes.com/ImageFile.ashx?instanceId=Static_4&amp;fileName=ATP_blu_91x17.gif">Subscribe with Pageflakes</feedburner:feedFlare><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com" /><item><guid isPermaLink="false">tag:blogger.com,1999:blog-7411255283791998153.post-5228361682142783470</guid><pubDate>Mon, 19 Oct 2009 08:02:00 +0000</pubDate><atom:updated>2009-10-19T01:02:29.176-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Linq</category><title>Remove all empty XML elements using LINQ</title><description>While working on the &lt;a href="http://projectsilverlight.blogspot.com/2009/10/silverlight-3-xamlwriter-basic.html"&gt;XamlWriter&lt;/a&gt; I had to do some post processing on the generated Xaml. One was to delete all nodes that did not have any attributes or contain any elements. The first pass of removing the empty nodes could generate more empty nodes and hence this problem is recursive in nature.&lt;br /&gt;
&lt;br /&gt;
This was my first attempt&lt;br /&gt;
&lt;pre class="csharpcode"&gt;var query = doc.Descendants().Where(c =&amp;gt; !c.HasAttributes &amp;amp;&amp;amp; c.IsEmpty);
&lt;span class="kwrd"&gt;while&lt;/span&gt; (query.Count())
   query.Remove();
&lt;/pre&gt;&lt;br /&gt;
This could be certainly improved using the .Any operator&lt;br /&gt;
&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;&lt;br /&gt;
&lt;pre class="csharpcode"&gt;var query = doc.Descendants().Where(c =&amp;gt; !c.HasAttributes &amp;amp;&amp;amp; c.IsEmpty);
&lt;span class="kwrd"&gt;while&lt;/span&gt; (query.Any())
   query.Remove();&lt;/pre&gt;&lt;br /&gt;
The problem with the above solution(s) is that the query is executed twice, once for the Any/Count method and once for the Remove method. The next approach provided 2x performance gains &lt;i&gt;(in the best case scenario)&lt;/i&gt; over the above approach&lt;br /&gt;
&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;&lt;br /&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;void&lt;/span&gt; RemoveEmptyNodes(XElement root)
{
   var query = root.Descendants().Where(e =&amp;gt; !e.HasAttributes &amp;amp;&amp;amp; e.IsEmpty).ToList();
   query.Remove();
   &lt;span class="kwrd"&gt;if&lt;/span&gt; (query.Any())
      RemoveEmptyNodes(root);
}&lt;/pre&gt;&lt;br /&gt;
The reason for the performance improvement is that although both the Any and the Remove operations are executed on the query, the .ToList operator executes and caches the result and hence the query is executed only once.&lt;br /&gt;
&lt;br /&gt;
The concern I have with the above &lt;b&gt;recursive&lt;/b&gt; solution is the memory requirement for the local variable query which is of type IEnumerable. &lt;br /&gt;
&lt;br /&gt;
Maybe something like this will help but I don't understand GC (garbage collection) in .NET well enough to recommend this approach&lt;br /&gt;
&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;&lt;br /&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;void&lt;/span&gt; RemoveEmptyNodes(XElement root)
{
   var query = root.Descendants().Where(e =&amp;gt; !e.HasAttributes &amp;amp;&amp;amp; e.IsEmpty).ToList();
   query.Remove();
   &lt;span class="kwrd"&gt;if&lt;/span&gt; (query.Any())
   {
      query = &lt;span class="kwrd"&gt;null&lt;/span&gt;;
      RemoveEmptyNodes(root);
   }
}&lt;/pre&gt;&lt;br /&gt;
Anyone with better or alternate approaches please post your thoughts as comments.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7411255283791998153-5228361682142783470?l=projectsilverlight.blogspot.com'/&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/ProjectSilverlight/~4/OyN5ahRVXqo" height="1" width="1"/&gt;</description><link>http://projectsilverlight.blogspot.com/2009/10/remove-all-empty-xml-elements-using.html</link><author>noreply@blogger.com (Wilfred Pinto)</author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">2</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-7411255283791998153.post-5711998014904757078</guid><pubDate>Fri, 16 Oct 2009 22:18:00 +0000</pubDate><atom:updated>2009-10-16T15:18:07.377-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Silverlight</category><category domain="http://www.blogger.com/atom/ns#">XamlWriter</category><title>Silverlight 3 XamlWriter - v0.4 - DataTemplate support</title><description>The new version of XamlWriter with DataTemplate support is now available. Check the previous posts for download and usage information.&lt;br /&gt;
&lt;br /&gt;
While it is possible to recreate the DataTemplate it is not possible to recreate ContentTemplate. Hence I couldn't add support for ContentTemplate. There is also support for the Style class but there is an issue with it.&lt;br /&gt;
&lt;br /&gt;
The DataTemplate example&lt;br /&gt;
&lt;br /&gt;
&lt;a name='more'&gt;&lt;/a&gt;&lt;br /&gt;
&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;&lt;br /&gt;
&lt;pre class="csharpcode"&gt;Assuming an Xaml like this

&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;UserControl&lt;/span&gt; &lt;span class="attr"&gt;x:Class&lt;/span&gt;&lt;span class="kwrd"&gt;="test2.MainPage"&lt;/span&gt; &lt;span class="attr"&gt;x:Name&lt;/span&gt;&lt;span class="kwrd"&gt;="MyControl"&lt;/span&gt;
    &lt;span class="attr"&gt;xmlns&lt;/span&gt;&lt;span class="kwrd"&gt;="http://schemas.microsoft.com/client/2007"&lt;/span&gt; 
    &lt;span class="attr"&gt;xmlns:x&lt;/span&gt;&lt;span class="kwrd"&gt;="http://schemas.microsoft.com/winfx/2006/xaml"&lt;/span&gt; 
    &lt;span class="attr"&gt;xmlns:chartingToolkit&lt;/span&gt;&lt;span class="kwrd"&gt;="clr-namespace:System.Windows.Controls.DataVisualization.Charting;assembly=System.Windows.Controls.DataVisualization.Toolkit"&lt;/span&gt;
    &lt;span class="attr"&gt;xmlns:controls&lt;/span&gt;&lt;span class="kwrd"&gt;="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"&lt;/span&gt;
    &lt;span class="attr"&gt;Width&lt;/span&gt;&lt;span class="kwrd"&gt;="1000"&lt;/span&gt; &lt;span class="attr"&gt;Height&lt;/span&gt;&lt;span class="kwrd"&gt;="300"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Border&lt;/span&gt; &lt;span class="attr"&gt;BorderBrush&lt;/span&gt;&lt;span class="kwrd"&gt;="Green"&lt;/span&gt; &lt;span class="attr"&gt;BorderThickness&lt;/span&gt;&lt;span class="kwrd"&gt;="4"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Grid&lt;/span&gt; &lt;span class="attr"&gt;x:Name&lt;/span&gt;&lt;span class="kwrd"&gt;="LayoutRoot"&lt;/span&gt; &lt;span class="attr"&gt;Background&lt;/span&gt;&lt;span class="kwrd"&gt;="White"&lt;/span&gt;  &lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;controls:TreeView&lt;/span&gt; &lt;span class="attr"&gt;x:Name&lt;/span&gt;&lt;span class="kwrd"&gt;="trv"&lt;/span&gt; &lt;span class="attr"&gt;ItemsSource&lt;/span&gt;&lt;span class="kwrd"&gt;="{Binding}"&lt;/span&gt; &lt;span class="attr"&gt;Width&lt;/span&gt;&lt;span class="kwrd"&gt;="500"&lt;/span&gt; &lt;span class="attr"&gt;BorderThickness&lt;/span&gt;&lt;span class="kwrd"&gt;="4"&lt;/span&gt; &lt;span class="attr"&gt;BorderBrush&lt;/span&gt;&lt;span class="kwrd"&gt;="Purple"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;controls:TreeView.ItemTemplate&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;DataTemplate&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Border&lt;/span&gt; &lt;span class="attr"&gt;BorderBrush&lt;/span&gt;&lt;span class="kwrd"&gt;="Blue"&lt;/span&gt; &lt;span class="attr"&gt;BorderThickness&lt;/span&gt;&lt;span class="kwrd"&gt;="4"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Grid&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                                &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Border&lt;/span&gt; &lt;span class="attr"&gt;BorderBrush&lt;/span&gt;&lt;span class="kwrd"&gt;="Yellow"&lt;/span&gt; &lt;span class="attr"&gt;BorderThickness&lt;/span&gt;&lt;span class="kwrd"&gt;="4"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                                    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;TextBlock&lt;/span&gt; &lt;span class="attr"&gt;Text&lt;/span&gt;&lt;span class="kwrd"&gt;="Hello"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;TextBlock&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                                &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Border&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                            &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Grid&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                        &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Border&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;DataTemplate&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;controls:TreeView.ItemTemplate&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;controls:TreeView&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Button&lt;/span&gt; &lt;span class="attr"&gt;x:Name&lt;/span&gt;&lt;span class="kwrd"&gt;="zz"&lt;/span&gt; &lt;span class="attr"&gt;Width&lt;/span&gt;&lt;span class="kwrd"&gt;="100"&lt;/span&gt; &lt;span class="attr"&gt;Height&lt;/span&gt;&lt;span class="kwrd"&gt;="100"&lt;/span&gt; &lt;span class="attr"&gt;Click&lt;/span&gt;&lt;span class="kwrd"&gt;="Button_Click"&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Grid&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Border&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;UserControl&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;


WriteXaml(MyControl, XamlWriterSettings.LogicalTree) will generate this Xaml


&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;UserControl&lt;/span&gt; &lt;span class="attr"&gt;x:Name&lt;/span&gt;&lt;span class="kwrd"&gt;="MyControl"&lt;/span&gt; &lt;span class="attr"&gt;xmlns:x&lt;/span&gt;&lt;span class="kwrd"&gt;="http://schemas.microsoft.com/winfx/2006/xaml"&lt;/span&gt; &lt;span class="attr"&gt;xmlns&lt;/span&gt;&lt;span class="kwrd"&gt;="http://schemas.microsoft.com/client/2007"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Border&lt;/span&gt; &lt;span class="attr"&gt;BorderThickness&lt;/span&gt;&lt;span class="kwrd"&gt;="4,4,4,4"&lt;/span&gt; &lt;span class="attr"&gt;BorderBrush&lt;/span&gt;&lt;span class="kwrd"&gt;="#FF008000"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Grid&lt;/span&gt; &lt;span class="attr"&gt;x:Name&lt;/span&gt;&lt;span class="kwrd"&gt;="LayoutRoot"&lt;/span&gt; &lt;span class="attr"&gt;Background&lt;/span&gt;&lt;span class="kwrd"&gt;="#FFFFFFFF"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;TreeView&lt;/span&gt; &lt;span class="attr"&gt;BorderThickness&lt;/span&gt;&lt;span class="kwrd"&gt;="4,4,4,4"&lt;/span&gt; &lt;span class="attr"&gt;Width&lt;/span&gt;&lt;span class="kwrd"&gt;="500"&lt;/span&gt; &lt;span class="attr"&gt;x:Name&lt;/span&gt;&lt;span class="kwrd"&gt;="trv"&lt;/span&gt; &lt;span class="attr"&gt;BorderBrush&lt;/span&gt;&lt;span class="kwrd"&gt;="#FF800080"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;TreeView.ItemTemplate&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;DataTemplate&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Border&lt;/span&gt; &lt;span class="attr"&gt;BorderThickness&lt;/span&gt;&lt;span class="kwrd"&gt;="4,4,4,4"&lt;/span&gt; &lt;span class="attr"&gt;BorderBrush&lt;/span&gt;&lt;span class="kwrd"&gt;="#FF0000FF"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
              &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Grid&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Border&lt;/span&gt; &lt;span class="attr"&gt;BorderThickness&lt;/span&gt;&lt;span class="kwrd"&gt;="4,4,4,4"&lt;/span&gt; &lt;span class="attr"&gt;BorderBrush&lt;/span&gt;&lt;span class="kwrd"&gt;="#FFFFFF00"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                  &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;TextBlock&lt;/span&gt; &lt;span class="attr"&gt;Text&lt;/span&gt;&lt;span class="kwrd"&gt;="Hello"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
                &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Border&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
              &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Grid&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Border&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;DataTemplate&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;TreeView.ItemTemplate&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;TreeView&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Button&lt;/span&gt; &lt;span class="attr"&gt;Width&lt;/span&gt;&lt;span class="kwrd"&gt;="100"&lt;/span&gt; &lt;span class="attr"&gt;Height&lt;/span&gt;&lt;span class="kwrd"&gt;="100"&lt;/span&gt; &lt;span class="attr"&gt;x:Name&lt;/span&gt;&lt;span class="kwrd"&gt;="zz"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Grid&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Border&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;UserControl&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7411255283791998153-5711998014904757078?l=projectsilverlight.blogspot.com'/&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/ProjectSilverlight/~4/kOkwVrALE64" height="1" width="1"/&gt;</description><link>http://projectsilverlight.blogspot.com/2009/10/silverlight-3-xamlwriter-v04.html</link><author>noreply@blogger.com (Wilfred Pinto)</author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">2</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-7411255283791998153.post-5833399495448350132</guid><pubDate>Thu, 15 Oct 2009 19:30:00 +0000</pubDate><atom:updated>2009-10-15T12:32:41.679-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Silverlight</category><category domain="http://www.blogger.com/atom/ns#">XamlWriter</category><title>Silverlight 3 XamlWriter - v0.3 - Storyboard and TransformGroup support</title><description>An update every day - Wow! Thought I'd keep the momentum going while I have a liiittle free time. Once it goes on the back-burner, it will lie there to bite the dust!&lt;br /&gt;
&lt;br /&gt;
If anyone has tried the XamlWriter &lt;i&gt;(which I am sure no one has, yet!)&lt;/i&gt; it would be clear that it doesn't work for Storyboards and TransformGroups. That is because they are a slightly special case. Why? I'll leave that for some future post. Anyways it's fixed now.&lt;br /&gt;
&lt;br /&gt;
Please check out my previous &lt;a href="http://projectsilverlight.blogspot.com/2009/10/silverlight-3-xamlwriter-basic.html"&gt;post&lt;/a&gt; for download and usage information. &lt;br /&gt;
&lt;br /&gt;
I also thought I'd take this opportunity to point out some issue that I encountered. If you had read my previous posts on this subject you would know that I used reflection to implement the XamlWriter. &lt;br /&gt;
&lt;br /&gt;
The way to retrieve the properties of an object using reflection is like this -&lt;br /&gt;
&amp;nbsp;&amp;nbsp;PropertyInfo[] props = target.GetType().GetProperties();&lt;br /&gt;
&lt;br /&gt;
I now needed to to check if the property is readonly. The reason for this is that a readonly property cannot be used in Xaml. So I went ahead and used the CanWrite property to check if the property could be written to, like this -&lt;br /&gt;
&amp;nbsp;&amp;nbsp;if (!prop.CanWrite)&lt;br /&gt;
&lt;br /&gt;
But, guess what? It doesn't work in all cases. For example, the IsFocussed property of a Button control returns true for CanWrite. I put the IsFocussed property in the Xaml and it threw an error indicating clearly that this was a read only property.&lt;br /&gt;
&lt;br /&gt;
So there had to be a different way. After all the Xaml parser knows more about readonly properties than the CanWrite property. That is when I discovered the GetSetMethod method on ProperyInfo. This worked wonderfully -&lt;br /&gt;
&amp;nbsp;&amp;nbsp;if (prop.GetSetMethod == null)&lt;br /&gt;
&lt;br /&gt;
Whether this is a bug or some explainable feature, I don't know. Maybe I will post this on the Silverlight.net forums and see if there is an explanation. In the meantime, there is a workaround for me to continue making progress!&lt;br /&gt;
&lt;br /&gt;
The Storyboard and TransformGroup example&lt;br /&gt;
&lt;br /&gt;
&lt;a name='more'&gt;&lt;/a&gt;&lt;br /&gt;
&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;&lt;br /&gt;
&lt;pre class="csharpcode"&gt;Assuming an Xaml like this

&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;UserControl&lt;/span&gt; &lt;span class="attr"&gt;x:Class&lt;/span&gt;&lt;span class="kwrd"&gt;="test2.MainPage"&lt;/span&gt; &lt;span class="attr"&gt;x:Name&lt;/span&gt;&lt;span class="kwrd"&gt;="MyControl"&lt;/span&gt;
 &lt;span class="attr"&gt;xmlns&lt;/span&gt;&lt;span class="kwrd"&gt;="http://schemas.microsoft.com/winfx/2006/xaml/presentation"&lt;/span&gt;
 &lt;span class="attr"&gt;xmlns:x&lt;/span&gt;&lt;span class="kwrd"&gt;="http://schemas.microsoft.com/winfx/2006/xaml"&lt;/span&gt;
 &lt;span class="attr"&gt;Width&lt;/span&gt;&lt;span class="kwrd"&gt;="850"&lt;/span&gt; &lt;span class="attr"&gt;Height&lt;/span&gt;&lt;span class="kwrd"&gt;="447"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Canvas&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Canvas.Triggers&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;EventTrigger&lt;/span&gt; &lt;span class="attr"&gt;RoutedEvent&lt;/span&gt;&lt;span class="kwrd"&gt;="Canvas.Loaded"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;EventTrigger.Actions&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;BeginStoryboard&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Storyboard&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;DoubleAnimation&lt;/span&gt; &lt;span class="attr"&gt;To&lt;/span&gt;&lt;span class="kwrd"&gt;="300"&lt;/span&gt; &lt;span class="attr"&gt;Duration&lt;/span&gt;&lt;span class="kwrd"&gt;="0:0:1"&lt;/span&gt; 
                                             &lt;span class="attr"&gt;Storyboard&lt;/span&gt;.&lt;span class="attr"&gt;TargetName&lt;/span&gt;&lt;span class="kwrd"&gt;="ellipse"&lt;/span&gt; &lt;span class="attr"&gt;Storyboard&lt;/span&gt;.&lt;span class="attr"&gt;TargetProperty&lt;/span&gt;&lt;span class="kwrd"&gt;="(Canvas.Left)"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
                        &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Storyboard&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;BeginStoryboard&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;EventTrigger.Actions&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;EventTrigger&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Canvas.Triggers&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Canvas.RenderTransform&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;TransformGroup&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;ScaleTransform&lt;/span&gt; &lt;span class="attr"&gt;ScaleX&lt;/span&gt;&lt;span class="kwrd"&gt;="1.05"&lt;/span&gt; &lt;span class="attr"&gt;ScaleY&lt;/span&gt;&lt;span class="kwrd"&gt;="1"&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
                &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;SkewTransform&lt;/span&gt; &lt;span class="attr"&gt;AngleX&lt;/span&gt;&lt;span class="kwrd"&gt;="0"&lt;/span&gt; &lt;span class="attr"&gt;AngleY&lt;/span&gt;&lt;span class="kwrd"&gt;="0"&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
                &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;RotateTransform&lt;/span&gt; &lt;span class="attr"&gt;Angle&lt;/span&gt;&lt;span class="kwrd"&gt;="0"&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
                &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;TranslateTransform&lt;/span&gt; &lt;span class="attr"&gt;X&lt;/span&gt;&lt;span class="kwrd"&gt;="1"&lt;/span&gt; &lt;span class="attr"&gt;Y&lt;/span&gt;&lt;span class="kwrd"&gt;="0"&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;TransformGroup&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Canvas.RenderTransform&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Ellipse&lt;/span&gt; &lt;span class="attr"&gt;x:Name&lt;/span&gt;&lt;span class="kwrd"&gt;="ellipse"&lt;/span&gt; &lt;span class="attr"&gt;Height&lt;/span&gt;&lt;span class="kwrd"&gt;="20"&lt;/span&gt; &lt;span class="attr"&gt;Width&lt;/span&gt;&lt;span class="kwrd"&gt;="20"&lt;/span&gt; &lt;span class="attr"&gt;Canvas&lt;/span&gt;.&lt;span class="attr"&gt;Left&lt;/span&gt;&lt;span class="kwrd"&gt;="30"&lt;/span&gt; &lt;span class="attr"&gt;Canvas&lt;/span&gt;.&lt;span class="attr"&gt;Top&lt;/span&gt;&lt;span class="kwrd"&gt;="30"&lt;/span&gt; &lt;span class="attr"&gt;Fill&lt;/span&gt;&lt;span class="kwrd"&gt;="black"&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Button&lt;/span&gt; &lt;span class="attr"&gt;x:Name&lt;/span&gt;&lt;span class="kwrd"&gt;="zz"&lt;/span&gt; &lt;span class="attr"&gt;Width&lt;/span&gt;&lt;span class="kwrd"&gt;="100"&lt;/span&gt; &lt;span class="attr"&gt;Height&lt;/span&gt;&lt;span class="kwrd"&gt;="100"&lt;/span&gt; &lt;span class="attr"&gt;Click&lt;/span&gt;&lt;span class="kwrd"&gt;="Button_Click"&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Canvas&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;UserControl&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;


WriteXaml(MyControl, XamlWriterSettings.LogicalTree) will generate this Xaml


&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;UserControl&lt;/span&gt; &lt;span class="attr"&gt;xmlns&lt;/span&gt;&lt;span class="kwrd"&gt;="http://schemas.microsoft.com/winfx/2006/xaml/presentation"&lt;/span&gt; &lt;span class="attr"&gt;xmlns:x&lt;/span&gt;&lt;span class="kwrd"&gt;="http://schemas.microsoft.com/winfx/2006/xaml"&lt;/span&gt; &lt;span class="attr"&gt;x:Name&lt;/span&gt;&lt;span class="kwrd"&gt;="MyControl"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Canvas&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Ellipse&lt;/span&gt; &lt;span class="attr"&gt;Width&lt;/span&gt;&lt;span class="kwrd"&gt;="20"&lt;/span&gt; &lt;span class="attr"&gt;Height&lt;/span&gt;&lt;span class="kwrd"&gt;="20"&lt;/span&gt; &lt;span class="attr"&gt;x:Name&lt;/span&gt;&lt;span class="kwrd"&gt;="ellipse"&lt;/span&gt; &lt;span class="attr"&gt;Canvas&lt;/span&gt;.&lt;span class="attr"&gt;Left&lt;/span&gt;&lt;span class="kwrd"&gt;="300"&lt;/span&gt; &lt;span class="attr"&gt;Canvas&lt;/span&gt;.&lt;span class="attr"&gt;Top&lt;/span&gt;&lt;span class="kwrd"&gt;="30"&lt;/span&gt; &lt;span class="attr"&gt;Fill&lt;/span&gt;&lt;span class="kwrd"&gt;="#FF000000"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Button&lt;/span&gt; &lt;span class="attr"&gt;Width&lt;/span&gt;&lt;span class="kwrd"&gt;="100"&lt;/span&gt; &lt;span class="attr"&gt;Height&lt;/span&gt;&lt;span class="kwrd"&gt;="100"&lt;/span&gt; &lt;span class="attr"&gt;x:Name&lt;/span&gt;&lt;span class="kwrd"&gt;="zz"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Canvas.Triggers&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;EventTrigger&lt;/span&gt; &lt;span class="attr"&gt;RoutedEvent&lt;/span&gt;&lt;span class="kwrd"&gt;="FrameworkElement.Loaded"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;EventTrigger.Actions&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;BeginStoryboard&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Storyboard&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
              &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;DoubleAnimation&lt;/span&gt; &lt;span class="attr"&gt;To&lt;/span&gt;&lt;span class="kwrd"&gt;="300"&lt;/span&gt; &lt;span class="attr"&gt;Duration&lt;/span&gt;&lt;span class="kwrd"&gt;="00:00:01"&lt;/span&gt; &lt;span class="attr"&gt;Storyboard&lt;/span&gt;.&lt;span class="attr"&gt;TargetName&lt;/span&gt;&lt;span class="kwrd"&gt;="ellipse"&lt;/span&gt; &lt;span class="attr"&gt;Storyboard&lt;/span&gt;.&lt;span class="attr"&gt;TargetProperty&lt;/span&gt;&lt;span class="kwrd"&gt;="(Canvas.Left)"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Storyboard&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;BeginStoryboard&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;EventTrigger.Actions&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;EventTrigger&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Canvas.Triggers&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Canvas.RenderTransform&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;TransformGroup&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;ScaleTransform&lt;/span&gt; &lt;span class="attr"&gt;ScaleX&lt;/span&gt;&lt;span class="kwrd"&gt;="1.04999995231628"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;SkewTransform&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;RotateTransform&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;TranslateTransform&lt;/span&gt; &lt;span class="attr"&gt;X&lt;/span&gt;&lt;span class="kwrd"&gt;="1"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;TransformGroup&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Canvas.RenderTransform&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Canvas&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;UserControl&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7411255283791998153-5833399495448350132?l=projectsilverlight.blogspot.com'/&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/ProjectSilverlight/~4/Y36F5-UwFrM" height="1" width="1"/&gt;</description><link>http://projectsilverlight.blogspot.com/2009/10/silverlight-3-xamlwriter-v03-storyboard.html</link><author>noreply@blogger.com (Wilfred Pinto)</author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-7411255283791998153.post-8298863075760745467</guid><pubDate>Thu, 15 Oct 2009 03:10:00 +0000</pubDate><atom:updated>2009-10-15T12:37:40.494-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Silverlight</category><category domain="http://www.blogger.com/atom/ns#">XamlWriter</category><title>Silverlight 3 XamlWriter - v0.2</title><description>I was just going through the Silverlight.net forums to see if there was any interesting question to answer and I came across a post which had some interesting Xaml content. This used the Accordian control and looked like a good test case so I copied the Xaml to my project and invoked XamlWriter on it.&lt;br /&gt;
&lt;br /&gt;
And...it did not work! That was expected though. I would be very surprised if it did work.&lt;br /&gt;
&lt;br /&gt;
So, back to the drawing board - a few fixes here, a few fixes there, discovered a few more bugs, fixed them, and stopped when I got it to work with the second Xaml test case.&lt;br /&gt;
&lt;br /&gt;
Get the newer version of XamlWriter from here - &lt;i&gt;&lt;a href="http://thepintospatronus.com/xamlwriter/XamlWriter.dll" onClick="javascript: pageTracker._trackPageview('/downloads/XamlWriter';"&gt;XamlWriter.dll&lt;/a&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
The second example&lt;br /&gt;
&lt;br /&gt;
&lt;a name='more'&gt;&lt;/a&gt;&lt;br /&gt;
&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;&lt;br /&gt;
&lt;pre class="csharpcode"&gt;Assuming an Xaml like this

&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;UserControl&lt;/span&gt; &lt;span class="attr"&gt;x:Class&lt;/span&gt;&lt;span class="kwrd"&gt;="test2.MainPage"&lt;/span&gt; &lt;span class="attr"&gt;x:Name&lt;/span&gt;&lt;span class="kwrd"&gt;="MyControl"&lt;/span&gt;
       &lt;span class="attr"&gt;xmlns&lt;/span&gt;&lt;span class="kwrd"&gt;="http://schemas.microsoft.com/winfx/2006/xaml/presentation"&lt;/span&gt;
       &lt;span class="attr"&gt;xmlns:x&lt;/span&gt;&lt;span class="kwrd"&gt;="http://schemas.microsoft.com/winfx/2006/xaml"&lt;/span&gt;
       &lt;span class="attr"&gt;xmlns:layoutToolkit&lt;/span&gt;&lt;span class="kwrd"&gt;="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Layout.Toolkit"&lt;/span&gt;
       &lt;span class="attr"&gt;Height&lt;/span&gt;&lt;span class="kwrd"&gt;="313"&lt;/span&gt; &lt;span class="attr"&gt;Width&lt;/span&gt;&lt;span class="kwrd"&gt;="301"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;

    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Grid&lt;/span&gt; &lt;span class="attr"&gt;x:Name&lt;/span&gt;&lt;span class="kwrd"&gt;="LayoutRoot"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Canvas&lt;/span&gt; &lt;span class="attr"&gt;x:Name&lt;/span&gt;&lt;span class="kwrd"&gt;="Layer_1"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;layoutToolkit:Accordion&lt;/span&gt; &lt;span class="attr"&gt;ExpandDirection&lt;/span&gt;&lt;span class="kwrd"&gt;="Down"&lt;/span&gt; &lt;span class="attr"&gt;SelectionMode&lt;/span&gt;&lt;span class="kwrd"&gt;="One"&lt;/span&gt; &lt;span class="attr"&gt;SelectionSequence&lt;/span&gt;&lt;span class="kwrd"&gt;="Simultaneous"&lt;/span&gt; &lt;span class="attr"&gt;HorizontalAlignment&lt;/span&gt;&lt;span class="kwrd"&gt;="Stretch"&lt;/span&gt; &lt;span class="attr"&gt;VerticalAlignment&lt;/span&gt;&lt;span class="kwrd"&gt;="Stretch"&lt;/span&gt; &lt;span class="attr"&gt;Width&lt;/span&gt;&lt;span class="kwrd"&gt;="297"&lt;/span&gt; &lt;span class="attr"&gt;Height&lt;/span&gt;&lt;span class="kwrd"&gt;="225"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;layoutToolkit:AccordionItem&lt;/span&gt; &lt;span class="attr"&gt;Height&lt;/span&gt;&lt;span class="kwrd"&gt;="100"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;layoutToolkit:AccordionItem.Header&lt;/span&gt; &lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Canvas&lt;/span&gt; &lt;span class="attr"&gt;HorizontalAlignment&lt;/span&gt;&lt;span class="kwrd"&gt;="Center"&lt;/span&gt; &lt;span class="attr"&gt;VerticalAlignment&lt;/span&gt;&lt;span class="kwrd"&gt;="Center"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;TextBlock&lt;/span&gt; &lt;span class="attr"&gt;Text&lt;/span&gt;&lt;span class="kwrd"&gt;="Bedrijfspotentieel"&lt;/span&gt; &lt;span class="attr"&gt;Canvas&lt;/span&gt;.&lt;span class="attr"&gt;Left&lt;/span&gt;&lt;span class="kwrd"&gt;="56.666"&lt;/span&gt; &lt;span class="attr"&gt;Canvas&lt;/span&gt;.&lt;span class="attr"&gt;Top&lt;/span&gt;&lt;span class="kwrd"&gt;="-12"&lt;/span&gt; &lt;span class="kwrd"&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;TextBlock&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                        &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Canvas&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;layoutToolkit:AccordionItem.Header&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;StackPanel&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Button&lt;/span&gt; &lt;span class="attr"&gt;Width&lt;/span&gt;&lt;span class="kwrd"&gt;="75"&lt;/span&gt; &lt;span class="attr"&gt;Content&lt;/span&gt;&lt;span class="kwrd"&gt;="B1"&lt;/span&gt; &lt;span class="attr"&gt;Click&lt;/span&gt;&lt;span class="kwrd"&gt;="Button_Click"&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
                        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Button&lt;/span&gt; &lt;span class="attr"&gt;Width&lt;/span&gt;&lt;span class="kwrd"&gt;="75"&lt;/span&gt; &lt;span class="attr"&gt;Content&lt;/span&gt;&lt;span class="kwrd"&gt;="Button"&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
                    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;StackPanel&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;layoutToolkit:AccordionItem&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;layoutToolkit:AccordionItem&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;layoutToolkit:AccordionItem.Header&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Canvas&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;TextBlock&lt;/span&gt; &lt;span class="attr"&gt;Text&lt;/span&gt;&lt;span class="kwrd"&gt;="Bedrijfspotentieel"&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
                        &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Canvas&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;layoutToolkit:AccordionItem.Header&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Grid&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
                &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;layoutToolkit:AccordionItem&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;layoutToolkit:Accordion&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Canvas&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Grid&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;UserControl&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;


WriteXaml(MyControl, XamlWriterSettings.LogicalTree) will generate this Xaml


&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;UserControl&lt;/span&gt; &lt;span class="attr"&gt;xmlns&lt;/span&gt;&lt;span class="kwrd"&gt;="http://schemas.microsoft.com/winfx/2006/xaml/presentation"&lt;/span&gt; &lt;span class="attr"&gt;xmlns:x&lt;/span&gt;&lt;span class="kwrd"&gt;="http://schemas.microsoft.com/winfx/2006/xaml"&lt;/span&gt; &lt;span class="attr"&gt;x:Name&lt;/span&gt;&lt;span class="kwrd"&gt;="MyControl"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Grid&lt;/span&gt; &lt;span class="attr"&gt;x:Name&lt;/span&gt;&lt;span class="kwrd"&gt;="LayoutRoot"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Canvas&lt;/span&gt; &lt;span class="attr"&gt;x:Name&lt;/span&gt;&lt;span class="kwrd"&gt;="Layer_1"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Accordion&lt;/span&gt; &lt;span class="attr"&gt;Width&lt;/span&gt;&lt;span class="kwrd"&gt;="297"&lt;/span&gt; &lt;span class="attr"&gt;Height&lt;/span&gt;&lt;span class="kwrd"&gt;="225"&lt;/span&gt; &lt;span class="attr"&gt;HorizontalAlignment&lt;/span&gt;&lt;span class="kwrd"&gt;="Stretch"&lt;/span&gt; &lt;span class="attr"&gt;VerticalAlignment&lt;/span&gt;&lt;span class="kwrd"&gt;="Stretch"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;AccordionItem&lt;/span&gt; &lt;span class="attr"&gt;Height&lt;/span&gt;&lt;span class="kwrd"&gt;="100"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;AccordionItem.Header&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Canvas&lt;/span&gt; &lt;span class="attr"&gt;HorizontalAlignment&lt;/span&gt;&lt;span class="kwrd"&gt;="Center"&lt;/span&gt; &lt;span class="attr"&gt;VerticalAlignment&lt;/span&gt;&lt;span class="kwrd"&gt;="Center"&lt;/span&gt; &lt;span class="attr"&gt;UseLayoutRounding&lt;/span&gt;&lt;span class="kwrd"&gt;="False"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
              &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;TextBlock&lt;/span&gt; &lt;span class="attr"&gt;Text&lt;/span&gt;&lt;span class="kwrd"&gt;="Bedrijfspotentieel"&lt;/span&gt; &lt;span class="attr"&gt;UseLayoutRounding&lt;/span&gt;&lt;span class="kwrd"&gt;="False"&lt;/span&gt; &lt;span class="attr"&gt;Canvas&lt;/span&gt;.&lt;span class="attr"&gt;Left&lt;/span&gt;&lt;span class="kwrd"&gt;="56.6660003662109"&lt;/span&gt; &lt;span class="attr"&gt;Canvas&lt;/span&gt;.&lt;span class="attr"&gt;Top&lt;/span&gt;&lt;span class="kwrd"&gt;="-12"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Run&lt;/span&gt; &lt;span class="attr"&gt;Text&lt;/span&gt;&lt;span class="kwrd"&gt;="Bedrijfspotentieel"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
              &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;TextBlock&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Canvas&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;AccordionItem.Header&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;AccordionItem.Content&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;StackPanel&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
              &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Button&lt;/span&gt; &lt;span class="attr"&gt;Content&lt;/span&gt;&lt;span class="kwrd"&gt;="B1"&lt;/span&gt; &lt;span class="attr"&gt;Width&lt;/span&gt;&lt;span class="kwrd"&gt;="75"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
              &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Button&lt;/span&gt; &lt;span class="attr"&gt;Content&lt;/span&gt;&lt;span class="kwrd"&gt;="Button"&lt;/span&gt; &lt;span class="attr"&gt;Width&lt;/span&gt;&lt;span class="kwrd"&gt;="75"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;StackPanel&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;AccordionItem.Content&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;AccordionItem&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;AccordionItem&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;AccordionItem.Header&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Canvas&lt;/span&gt; &lt;span class="attr"&gt;UseLayoutRounding&lt;/span&gt;&lt;span class="kwrd"&gt;="False"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
              &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;TextBlock&lt;/span&gt; &lt;span class="attr"&gt;Text&lt;/span&gt;&lt;span class="kwrd"&gt;="Bedrijfspotentieel"&lt;/span&gt; &lt;span class="attr"&gt;UseLayoutRounding&lt;/span&gt;&lt;span class="kwrd"&gt;="False"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Run&lt;/span&gt; &lt;span class="attr"&gt;Text&lt;/span&gt;&lt;span class="kwrd"&gt;="Bedrijfspotentieel"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
              &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;TextBlock&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Canvas&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;AccordionItem.Header&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;AccordionItem&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Accordion&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Canvas&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Grid&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;UserControl&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7411255283791998153-8298863075760745467?l=projectsilverlight.blogspot.com'/&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/ProjectSilverlight/~4/E7Ih436txyg" height="1" width="1"/&gt;</description><link>http://projectsilverlight.blogspot.com/2009/10/silverlight-3-xamlwriter-v02.html</link><author>noreply@blogger.com (Wilfred Pinto)</author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-7411255283791998153.post-9021772813635633200</guid><pubDate>Wed, 14 Oct 2009 01:51:00 +0000</pubDate><atom:updated>2009-10-15T12:38:41.341-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Silverlight</category><category domain="http://www.blogger.com/atom/ns#">XamlWriter</category><title>Silverlight 3 XamlWriter - A basic implementation</title><description>&lt;div&gt;I am sure that anyone who has worked extensively with Silverlight has felt the need for a XamlWriter at some time. I mostly need it for debugging purposes - to see the xaml of the dynamically assembled controls.&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;I have been taking the cumbersome route of stepping through the control hierarcy using the debugger, but enough is enough! Just takes too much time. It probably is quicker to just write some code which takes in a FrameworkElement and outputs the Xaml representation of it. &lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;I did find 3 resources on the web that would prove useful (or not!)&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;ol&gt;&lt;li&gt;&lt;a href="http://weblogs.asp.net/mehrantoosi/archive/2008/03/03/silverlight-s-xamlwriter.aspx"&gt;XamlWriter by Mehran&lt;/a&gt; (rambler.elf on the Silverlight.net forums) - A nice simple reflection based approach that would prove the starting point for my project&lt;/li&gt;
&lt;li&gt;&lt;a href="http://silverlightcontrib.codeplex.com/sourcecontrol/changeset/view/49151?projectName=silverlightcontrib#602856"&gt;XamlWriter by the SilverlightContrib team&lt;/a&gt;  - Did not try this since it is embedded deep in another project. Not sure if this wuld work for me but since I like to have more control I decided to write one myself (based on Mehran's code)&lt;/li&gt;
&lt;li&gt;&lt;a href="http://silverlightspy.com/silverlightspy/download-silverlight-spy/"&gt;Silverlight Spy&lt;/a&gt; - A third party tool that could be used to extract the Xaml of a specific control. Not so useful for me since I need to hook it in my code&lt;/li&gt;
&lt;/ol&gt;&lt;/div&gt;&lt;div&gt;So I decided to take Mehran's code and make it work on Silverlight 3. Then I refined it and added some features and refined it a bit more and added some more features and...&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;It's by no means complete or well tested but if you feel brave enough&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;ul&gt;&lt;li&gt;just download this file - &lt;i&gt;&lt;a href="http://thepintospatronus.com/xamlwriter/XamlWriter.dll" onClick="javascript: pageTracker._trackPageview('/downloads/XamlWriter';"&gt;XamlWriter.dll&lt;/a&gt;&lt;span style="font-style: normal;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/i&gt;&lt;/li&gt;
&lt;li&gt;add a reference to this file from your project&amp;nbsp;&lt;/li&gt;
&lt;li&gt;and use the following snippet of code to test it&lt;/li&gt;
&lt;/ul&gt;&lt;/div&gt;&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;&lt;br /&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; projectsilverlight.blogspot.com.XamlWriter;

XamlWriter xamlWriter = &lt;span class="kwrd"&gt;new&lt;/span&gt; XamlWriter();
&lt;span class="kwrd"&gt;string&lt;/span&gt; xaml = xamlWriter.WriteXaml(MyControl, XamlWriterSettings.LogicalTree);&lt;/pre&gt;&lt;div&gt;&lt;br /&gt;
&lt;i&gt;Note that XamlWriter uses System.Xml.Linq for some processing so you will find this dll getting added to the xap as well.&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;XamlWriterSettings has 3 values which can be combined to get different output. The 4 valid combinations are&lt;br /&gt;
&lt;/div&gt;&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;&lt;br /&gt;
&lt;pre class="csharpcode"&gt;WriteXaml(MyControl, XamlWriterSettings.LogicalTree);
WriteXaml(MyControl, XamlWriterSettings.LogicalTree | XamlWriterSettings.AllAttributes);
WriteXaml(MyControl, XamlWriterSettings.VisualTree);
WriteXaml(MyControl, XamlWriterSettings.VisualTree | XamlWriterSettings.AllAttributes);&lt;/pre&gt;&lt;div&gt;Like I mentioned before - this is not well tested. In fact, the example below is the only case I have tested. I am putting it up nevertheless to get some feedback. If you find that it is not working for a specific case, send me the Xaml/code that it is not working for and I will take a look. At some point in the future, if still relevant, I will open source this code. But now it is closed source for various reasons - the code quality sucks, haven't taken permission from Mehran yet, want better control so that a single codebase gets improved upon rather than each individual fixing it for his/her needs.&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;Enjoy!&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;An example&lt;br /&gt;
&lt;/div&gt;&lt;a name='more'&gt;&lt;/a&gt;&lt;br /&gt;
&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;&lt;br /&gt;
&lt;pre class="csharpcode"&gt;Assuming an Xaml like this

&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;UserControl&lt;/span&gt; &lt;span class="attr"&gt;x:Class&lt;/span&gt;&lt;span class="kwrd"&gt;="test2.MainPage"&lt;/span&gt; &lt;span class="attr"&gt;x:Name&lt;/span&gt;&lt;span class="kwrd"&gt;="MyControl"&lt;/span&gt;
 &lt;span class="attr"&gt;xmlns&lt;/span&gt;&lt;span class="kwrd"&gt;="http://schemas.microsoft.com/winfx/2006/xaml/presentation"&lt;/span&gt;
 &lt;span class="attr"&gt;xmlns:x&lt;/span&gt;&lt;span class="kwrd"&gt;="http://schemas.microsoft.com/winfx/2006/xaml"&lt;/span&gt;
 &lt;span class="attr"&gt;Width&lt;/span&gt;&lt;span class="kwrd"&gt;="850"&lt;/span&gt; &lt;span class="attr"&gt;Height&lt;/span&gt;&lt;span class="kwrd"&gt;="447"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Grid&lt;/span&gt; &lt;span class="attr"&gt;x:Name&lt;/span&gt;&lt;span class="kwrd"&gt;="test"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Grid.RowDefinitions&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;RowDefinition&lt;/span&gt; &lt;span class="attr"&gt;Height&lt;/span&gt;&lt;span class="kwrd"&gt;="60"&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;RowDefinition&lt;/span&gt; &lt;span class="attr"&gt;Height&lt;/span&gt;&lt;span class="kwrd"&gt;="54"&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;RowDefinition&lt;/span&gt; &lt;span class="attr"&gt;Height&lt;/span&gt;&lt;span class="kwrd"&gt;="*"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Grid.RowDefinitions&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Grid.ColumnDefinitions&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;ColumnDefinition&lt;/span&gt; &lt;span class="attr"&gt;Width&lt;/span&gt;&lt;span class="kwrd"&gt;="60"&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;ColumnDefinition&lt;/span&gt; &lt;span class="attr"&gt;Width&lt;/span&gt;&lt;span class="kwrd"&gt;="54"&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;ColumnDefinition&lt;/span&gt; &lt;span class="attr"&gt;Width&lt;/span&gt;&lt;span class="kwrd"&gt;="*"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Grid.ColumnDefinitions&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Border&lt;/span&gt; &lt;span class="attr"&gt;x:Name&lt;/span&gt;&lt;span class="kwrd"&gt;="ContentBorder"&lt;/span&gt; &lt;span class="attr"&gt;BorderThickness&lt;/span&gt;&lt;span class="kwrd"&gt;="0,3,0,0"&lt;/span&gt; &lt;span class="attr"&gt;BorderBrush&lt;/span&gt;&lt;span class="kwrd"&gt;="#FFAFAFAF"&lt;/span&gt; &lt;span class="attr"&gt;Margin&lt;/span&gt;&lt;span class="kwrd"&gt;="0,58,0,0"&lt;/span&gt; &lt;span class="attr"&gt;Opacity&lt;/span&gt;&lt;span class="kwrd"&gt;="0.5"&lt;/span&gt; 
                &lt;span class="attr"&gt;Grid&lt;/span&gt;.&lt;span class="attr"&gt;Row&lt;/span&gt;&lt;span class="kwrd"&gt;="1"&lt;/span&gt; &lt;span class="attr"&gt;Grid&lt;/span&gt;.&lt;span class="attr"&gt;Column&lt;/span&gt;&lt;span class="kwrd"&gt;="2"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Grid&lt;/span&gt; &lt;span class="attr"&gt;x:Name&lt;/span&gt;&lt;span class="kwrd"&gt;="CurrentContent"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Button&lt;/span&gt; &lt;span class="attr"&gt;x:Name&lt;/span&gt;&lt;span class="kwrd"&gt;="tt"&lt;/span&gt; &lt;span class="attr"&gt;Width&lt;/span&gt;&lt;span class="kwrd"&gt;="100"&lt;/span&gt; &lt;span class="attr"&gt;Height&lt;/span&gt;&lt;span class="kwrd"&gt;="100"&lt;/span&gt; &lt;span class="attr"&gt;Click&lt;/span&gt;&lt;span class="kwrd"&gt;="Button_Click"&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Grid&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Border&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Button&lt;/span&gt; &lt;span class="attr"&gt;x:Name&lt;/span&gt;&lt;span class="kwrd"&gt;="zz"&lt;/span&gt; &lt;span class="attr"&gt;Width&lt;/span&gt;&lt;span class="kwrd"&gt;="100"&lt;/span&gt; &lt;span class="attr"&gt;Height&lt;/span&gt;&lt;span class="kwrd"&gt;="100"&lt;/span&gt; &lt;span class="attr"&gt;Click&lt;/span&gt;&lt;span class="kwrd"&gt;="Button_Click"&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Grid&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;UserControl&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;


WriteXaml(MyControl, XamlWriterSettings.LogicalTree) will generate this Xaml

&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;UserControl&lt;/span&gt; &lt;span class="attr"&gt;xmlns&lt;/span&gt;&lt;span class="kwrd"&gt;="http://schemas.microsoft.com/winfx/2006/xaml/presentation"&lt;/span&gt; &lt;span class="attr"&gt;xmlns:x&lt;/span&gt;&lt;span class="kwrd"&gt;="http://schemas.microsoft.com/winfx/2006/xaml"&lt;/span&gt; &lt;span class="attr"&gt;Width&lt;/span&gt;&lt;span class="kwrd"&gt;="850"&lt;/span&gt; &lt;span class="attr"&gt;Height&lt;/span&gt;&lt;span class="kwrd"&gt;="447"&lt;/span&gt; &lt;span class="attr"&gt;x:Name&lt;/span&gt;&lt;span class="kwrd"&gt;="MyControl"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Grid&lt;/span&gt; &lt;span class="attr"&gt;x:Name&lt;/span&gt;&lt;span class="kwrd"&gt;="test"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Grid.RowDefinitions&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;RowDefinition&lt;/span&gt; &lt;span class="attr"&gt;Height&lt;/span&gt;&lt;span class="kwrd"&gt;="60"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;RowDefinition&lt;/span&gt; &lt;span class="attr"&gt;Height&lt;/span&gt;&lt;span class="kwrd"&gt;="54"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;RowDefinition&lt;/span&gt; &lt;span class="attr"&gt;Height&lt;/span&gt;&lt;span class="kwrd"&gt;="1*"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Grid.RowDefinitions&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Grid.ColumnDefinitions&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;ColumnDefinition&lt;/span&gt; &lt;span class="attr"&gt;Width&lt;/span&gt;&lt;span class="kwrd"&gt;="60"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;ColumnDefinition&lt;/span&gt; &lt;span class="attr"&gt;Width&lt;/span&gt;&lt;span class="kwrd"&gt;="54"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;ColumnDefinition&lt;/span&gt; &lt;span class="attr"&gt;Width&lt;/span&gt;&lt;span class="kwrd"&gt;="1*"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Grid.ColumnDefinitions&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Border&lt;/span&gt; &lt;span class="attr"&gt;BorderThickness&lt;/span&gt;&lt;span class="kwrd"&gt;="0,3,0,0"&lt;/span&gt; &lt;span class="attr"&gt;Margin&lt;/span&gt;&lt;span class="kwrd"&gt;="0,58,0,0"&lt;/span&gt; &lt;span class="attr"&gt;x:Name&lt;/span&gt;&lt;span class="kwrd"&gt;="ContentBorder"&lt;/span&gt; &lt;span class="attr"&gt;Opacity&lt;/span&gt;&lt;span class="kwrd"&gt;="0.5"&lt;/span&gt; &lt;span class="attr"&gt;Grid&lt;/span&gt;.&lt;span class="attr"&gt;Row&lt;/span&gt;&lt;span class="kwrd"&gt;="1"&lt;/span&gt; &lt;span class="attr"&gt;Grid&lt;/span&gt;.&lt;span class="attr"&gt;Column&lt;/span&gt;&lt;span class="kwrd"&gt;="2"&lt;/span&gt; &lt;span class="attr"&gt;BorderBrush&lt;/span&gt;&lt;span class="kwrd"&gt;="#FFAFAFAF"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Grid&lt;/span&gt; &lt;span class="attr"&gt;x:Name&lt;/span&gt;&lt;span class="kwrd"&gt;="CurrentContent"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Button&lt;/span&gt; &lt;span class="attr"&gt;Width&lt;/span&gt;&lt;span class="kwrd"&gt;="100"&lt;/span&gt; &lt;span class="attr"&gt;Height&lt;/span&gt;&lt;span class="kwrd"&gt;="100"&lt;/span&gt; &lt;span class="attr"&gt;x:Name&lt;/span&gt;&lt;span class="kwrd"&gt;="tt"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Grid&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Border&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Button&lt;/span&gt; &lt;span class="attr"&gt;Width&lt;/span&gt;&lt;span class="kwrd"&gt;="100"&lt;/span&gt; &lt;span class="attr"&gt;Height&lt;/span&gt;&lt;span class="kwrd"&gt;="100"&lt;/span&gt; &lt;span class="attr"&gt;x:Name&lt;/span&gt;&lt;span class="kwrd"&gt;="zz"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Grid&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;UserControl&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;

WriteXaml(MyControl, XamlWriterSettings.LogicalTree | XamlWriterSettings.AllAttributes) will generate this Xaml

&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;UserControl&lt;/span&gt; &lt;span class="attr"&gt;xmlns&lt;/span&gt;&lt;span class="kwrd"&gt;="http://schemas.microsoft.com/winfx/2006/xaml/presentation"&lt;/span&gt; &lt;span class="attr"&gt;xmlns:x&lt;/span&gt;&lt;span class="kwrd"&gt;="http://schemas.microsoft.com/winfx/2006/xaml"&lt;/span&gt; &lt;span class="attr"&gt;IsTabStop&lt;/span&gt;&lt;span class="kwrd"&gt;="False"&lt;/span&gt; &lt;span class="attr"&gt;IsEnabled&lt;/span&gt;&lt;span class="kwrd"&gt;="True"&lt;/span&gt; &lt;span class="attr"&gt;TabIndex&lt;/span&gt;&lt;span class="kwrd"&gt;="2147483647"&lt;/span&gt; &lt;span class="attr"&gt;TabNavigation&lt;/span&gt;&lt;span class="kwrd"&gt;="Local"&lt;/span&gt; &lt;span class="attr"&gt;Padding&lt;/span&gt;&lt;span class="kwrd"&gt;="0,0,0,0"&lt;/span&gt; &lt;span class="attr"&gt;BorderThickness&lt;/span&gt;&lt;span class="kwrd"&gt;="0,0,0,0"&lt;/span&gt; &lt;span class="attr"&gt;HorizontalContentAlignment&lt;/span&gt;&lt;span class="kwrd"&gt;="Center"&lt;/span&gt; &lt;span class="attr"&gt;VerticalContentAlignment&lt;/span&gt;&lt;span class="kwrd"&gt;="Center"&lt;/span&gt; &lt;span class="attr"&gt;FontFamily&lt;/span&gt;&lt;span class="kwrd"&gt;="Portable User Interface"&lt;/span&gt; &lt;span class="attr"&gt;FontSize&lt;/span&gt;&lt;span class="kwrd"&gt;="11"&lt;/span&gt; &lt;span class="attr"&gt;FontStretch&lt;/span&gt;&lt;span class="kwrd"&gt;="Normal"&lt;/span&gt; &lt;span class="attr"&gt;FontStyle&lt;/span&gt;&lt;span class="kwrd"&gt;="Normal"&lt;/span&gt; &lt;span class="attr"&gt;FontWeight&lt;/span&gt;&lt;span class="kwrd"&gt;="Normal"&lt;/span&gt; &lt;span class="attr"&gt;Width&lt;/span&gt;&lt;span class="kwrd"&gt;="850"&lt;/span&gt; &lt;span class="attr"&gt;Height&lt;/span&gt;&lt;span class="kwrd"&gt;="447"&lt;/span&gt; &lt;span class="attr"&gt;MinWidth&lt;/span&gt;&lt;span class="kwrd"&gt;="0"&lt;/span&gt; &lt;span class="attr"&gt;MaxWidth&lt;/span&gt;&lt;span class="kwrd"&gt;="Infinity"&lt;/span&gt; &lt;span class="attr"&gt;MinHeight&lt;/span&gt;&lt;span class="kwrd"&gt;="0"&lt;/span&gt; &lt;span class="attr"&gt;MaxHeight&lt;/span&gt;&lt;span class="kwrd"&gt;="Infinity"&lt;/span&gt; &lt;span class="attr"&gt;HorizontalAlignment&lt;/span&gt;&lt;span class="kwrd"&gt;="Stretch"&lt;/span&gt; &lt;span class="attr"&gt;VerticalAlignment&lt;/span&gt;&lt;span class="kwrd"&gt;="Stretch"&lt;/span&gt; &lt;span class="attr"&gt;Margin&lt;/span&gt;&lt;span class="kwrd"&gt;="0,0,0,0"&lt;/span&gt; &lt;span class="attr"&gt;x:Name&lt;/span&gt;&lt;span class="kwrd"&gt;="MyControl"&lt;/span&gt; &lt;span class="attr"&gt;Opacity&lt;/span&gt;&lt;span class="kwrd"&gt;="1"&lt;/span&gt; &lt;span class="attr"&gt;RenderTransformOrigin&lt;/span&gt;&lt;span class="kwrd"&gt;="0,0"&lt;/span&gt; &lt;span class="attr"&gt;IsHitTestVisible&lt;/span&gt;&lt;span class="kwrd"&gt;="True"&lt;/span&gt; &lt;span class="attr"&gt;Visibility&lt;/span&gt;&lt;span class="kwrd"&gt;="Visible"&lt;/span&gt; &lt;span class="attr"&gt;UseLayoutRounding&lt;/span&gt;&lt;span class="kwrd"&gt;="True"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;MainPage.Foreground&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;SolidColorBrush&lt;/span&gt; &lt;span class="attr"&gt;Color&lt;/span&gt;&lt;span class="kwrd"&gt;="#FF000000"&lt;/span&gt; &lt;span class="attr"&gt;Opacity&lt;/span&gt;&lt;span class="kwrd"&gt;="1"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;MainPage.Foreground&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Grid&lt;/span&gt; &lt;span class="attr"&gt;ShowGridLines&lt;/span&gt;&lt;span class="kwrd"&gt;="False"&lt;/span&gt; &lt;span class="attr"&gt;Width&lt;/span&gt;&lt;span class="kwrd"&gt;="NaN"&lt;/span&gt; &lt;span class="attr"&gt;Height&lt;/span&gt;&lt;span class="kwrd"&gt;="NaN"&lt;/span&gt; &lt;span class="attr"&gt;MinWidth&lt;/span&gt;&lt;span class="kwrd"&gt;="0"&lt;/span&gt; &lt;span class="attr"&gt;MaxWidth&lt;/span&gt;&lt;span class="kwrd"&gt;="Infinity"&lt;/span&gt; &lt;span class="attr"&gt;MinHeight&lt;/span&gt;&lt;span class="kwrd"&gt;="0"&lt;/span&gt; &lt;span class="attr"&gt;MaxHeight&lt;/span&gt;&lt;span class="kwrd"&gt;="Infinity"&lt;/span&gt; &lt;span class="attr"&gt;HorizontalAlignment&lt;/span&gt;&lt;span class="kwrd"&gt;="Stretch"&lt;/span&gt; &lt;span class="attr"&gt;VerticalAlignment&lt;/span&gt;&lt;span class="kwrd"&gt;="Stretch"&lt;/span&gt; &lt;span class="attr"&gt;Margin&lt;/span&gt;&lt;span class="kwrd"&gt;="0,0,0,0"&lt;/span&gt; &lt;span class="attr"&gt;x:Name&lt;/span&gt;&lt;span class="kwrd"&gt;="test"&lt;/span&gt; &lt;span class="attr"&gt;Opacity&lt;/span&gt;&lt;span class="kwrd"&gt;="1"&lt;/span&gt; &lt;span class="attr"&gt;RenderTransformOrigin&lt;/span&gt;&lt;span class="kwrd"&gt;="0,0"&lt;/span&gt; &lt;span class="attr"&gt;IsHitTestVisible&lt;/span&gt;&lt;span class="kwrd"&gt;="True"&lt;/span&gt; &lt;span class="attr"&gt;Visibility&lt;/span&gt;&lt;span class="kwrd"&gt;="Visible"&lt;/span&gt; &lt;span class="attr"&gt;UseLayoutRounding&lt;/span&gt;&lt;span class="kwrd"&gt;="True"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Grid.RowDefinitions&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;RowDefinition&lt;/span&gt; &lt;span class="attr"&gt;Height&lt;/span&gt;&lt;span class="kwrd"&gt;="60"&lt;/span&gt; &lt;span class="attr"&gt;MaxHeight&lt;/span&gt;&lt;span class="kwrd"&gt;="Infinity"&lt;/span&gt; &lt;span class="attr"&gt;MinHeight&lt;/span&gt;&lt;span class="kwrd"&gt;="0"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;RowDefinition&lt;/span&gt; &lt;span class="attr"&gt;Height&lt;/span&gt;&lt;span class="kwrd"&gt;="54"&lt;/span&gt; &lt;span class="attr"&gt;MaxHeight&lt;/span&gt;&lt;span class="kwrd"&gt;="Infinity"&lt;/span&gt; &lt;span class="attr"&gt;MinHeight&lt;/span&gt;&lt;span class="kwrd"&gt;="0"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;RowDefinition&lt;/span&gt; &lt;span class="attr"&gt;Height&lt;/span&gt;&lt;span class="kwrd"&gt;="1*"&lt;/span&gt; &lt;span class="attr"&gt;MaxHeight&lt;/span&gt;&lt;span class="kwrd"&gt;="Infinity"&lt;/span&gt; &lt;span class="attr"&gt;MinHeight&lt;/span&gt;&lt;span class="kwrd"&gt;="0"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Grid.RowDefinitions&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Grid.ColumnDefinitions&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;ColumnDefinition&lt;/span&gt; &lt;span class="attr"&gt;Width&lt;/span&gt;&lt;span class="kwrd"&gt;="60"&lt;/span&gt; &lt;span class="attr"&gt;MaxWidth&lt;/span&gt;&lt;span class="kwrd"&gt;="Infinity"&lt;/span&gt; &lt;span class="attr"&gt;MinWidth&lt;/span&gt;&lt;span class="kwrd"&gt;="0"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;ColumnDefinition&lt;/span&gt; &lt;span class="attr"&gt;Width&lt;/span&gt;&lt;span class="kwrd"&gt;="54"&lt;/span&gt; &lt;span class="attr"&gt;MaxWidth&lt;/span&gt;&lt;span class="kwrd"&gt;="Infinity"&lt;/span&gt; &lt;span class="attr"&gt;MinWidth&lt;/span&gt;&lt;span class="kwrd"&gt;="0"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;ColumnDefinition&lt;/span&gt; &lt;span class="attr"&gt;Width&lt;/span&gt;&lt;span class="kwrd"&gt;="1*"&lt;/span&gt; &lt;span class="attr"&gt;MaxWidth&lt;/span&gt;&lt;span class="kwrd"&gt;="Infinity"&lt;/span&gt; &lt;span class="attr"&gt;MinWidth&lt;/span&gt;&lt;span class="kwrd"&gt;="0"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Grid.ColumnDefinitions&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Border&lt;/span&gt; &lt;span class="attr"&gt;BorderThickness&lt;/span&gt;&lt;span class="kwrd"&gt;="0,3,0,0"&lt;/span&gt; &lt;span class="attr"&gt;CornerRadius&lt;/span&gt;&lt;span class="kwrd"&gt;="0,0,0,0"&lt;/span&gt; &lt;span class="attr"&gt;Padding&lt;/span&gt;&lt;span class="kwrd"&gt;="0,0,0,0"&lt;/span&gt; &lt;span class="attr"&gt;Width&lt;/span&gt;&lt;span class="kwrd"&gt;="NaN"&lt;/span&gt; &lt;span class="attr"&gt;Height&lt;/span&gt;&lt;span class="kwrd"&gt;="NaN"&lt;/span&gt; &lt;span class="attr"&gt;MinWidth&lt;/span&gt;&lt;span class="kwrd"&gt;="0"&lt;/span&gt; &lt;span class="attr"&gt;MaxWidth&lt;/span&gt;&lt;span class="kwrd"&gt;="Infinity"&lt;/span&gt; &lt;span class="attr"&gt;MinHeight&lt;/span&gt;&lt;span class="kwrd"&gt;="0"&lt;/span&gt; &lt;span class="attr"&gt;MaxHeight&lt;/span&gt;&lt;span class="kwrd"&gt;="Infinity"&lt;/span&gt; &lt;span class="attr"&gt;HorizontalAlignment&lt;/span&gt;&lt;span class="kwrd"&gt;="Stretch"&lt;/span&gt; &lt;span class="attr"&gt;VerticalAlignment&lt;/span&gt;&lt;span class="kwrd"&gt;="Stretch"&lt;/span&gt; &lt;span class="attr"&gt;Margin&lt;/span&gt;&lt;span class="kwrd"&gt;="0,58,0,0"&lt;/span&gt; &lt;span class="attr"&gt;x:Name&lt;/span&gt;&lt;span class="kwrd"&gt;="ContentBorder"&lt;/span&gt; &lt;span class="attr"&gt;Opacity&lt;/span&gt;&lt;span class="kwrd"&gt;="0.5"&lt;/span&gt; &lt;span class="attr"&gt;RenderTransformOrigin&lt;/span&gt;&lt;span class="kwrd"&gt;="0,0"&lt;/span&gt; &lt;span class="attr"&gt;IsHitTestVisible&lt;/span&gt;&lt;span class="kwrd"&gt;="True"&lt;/span&gt; &lt;span class="attr"&gt;Visibility&lt;/span&gt;&lt;span class="kwrd"&gt;="Visible"&lt;/span&gt; &lt;span class="attr"&gt;UseLayoutRounding&lt;/span&gt;&lt;span class="kwrd"&gt;="True"&lt;/span&gt; &lt;span class="attr"&gt;Grid&lt;/span&gt;.&lt;span class="attr"&gt;Row&lt;/span&gt;&lt;span class="kwrd"&gt;="1"&lt;/span&gt; &lt;span class="attr"&gt;Grid&lt;/span&gt;.&lt;span class="attr"&gt;Column&lt;/span&gt;&lt;span class="kwrd"&gt;="2"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Border.BorderBrush&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;SolidColorBrush&lt;/span&gt; &lt;span class="attr"&gt;Color&lt;/span&gt;&lt;span class="kwrd"&gt;="#FFAFAFAF"&lt;/span&gt; &lt;span class="attr"&gt;Opacity&lt;/span&gt;&lt;span class="kwrd"&gt;="1"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Border.BorderBrush&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Grid&lt;/span&gt; &lt;span class="attr"&gt;ShowGridLines&lt;/span&gt;&lt;span class="kwrd"&gt;="False"&lt;/span&gt; &lt;span class="attr"&gt;Width&lt;/span&gt;&lt;span class="kwrd"&gt;="NaN"&lt;/span&gt; &lt;span class="attr"&gt;Height&lt;/span&gt;&lt;span class="kwrd"&gt;="NaN"&lt;/span&gt; &lt;span class="attr"&gt;MinWidth&lt;/span&gt;&lt;span class="kwrd"&gt;="0"&lt;/span&gt; &lt;span class="attr"&gt;MaxWidth&lt;/span&gt;&lt;span class="kwrd"&gt;="Infinity"&lt;/span&gt; &lt;span class="attr"&gt;MinHeight&lt;/span&gt;&lt;span class="kwrd"&gt;="0"&lt;/span&gt; &lt;span class="attr"&gt;MaxHeight&lt;/span&gt;&lt;span class="kwrd"&gt;="Infinity"&lt;/span&gt; &lt;span class="attr"&gt;HorizontalAlignment&lt;/span&gt;&lt;span class="kwrd"&gt;="Stretch"&lt;/span&gt; &lt;span class="attr"&gt;VerticalAlignment&lt;/span&gt;&lt;span class="kwrd"&gt;="Stretch"&lt;/span&gt; &lt;span class="attr"&gt;Margin&lt;/span&gt;&lt;span class="kwrd"&gt;="0,0,0,0"&lt;/span&gt; &lt;span class="attr"&gt;x:Name&lt;/span&gt;&lt;span class="kwrd"&gt;="CurrentContent"&lt;/span&gt; &lt;span class="attr"&gt;Opacity&lt;/span&gt;&lt;span class="kwrd"&gt;="1"&lt;/span&gt; &lt;span class="attr"&gt;RenderTransformOrigin&lt;/span&gt;&lt;span class="kwrd"&gt;="0,0"&lt;/span&gt; &lt;span class="attr"&gt;IsHitTestVisible&lt;/span&gt;&lt;span class="kwrd"&gt;="True"&lt;/span&gt; &lt;span class="attr"&gt;Visibility&lt;/span&gt;&lt;span class="kwrd"&gt;="Visible"&lt;/span&gt; &lt;span class="attr"&gt;UseLayoutRounding&lt;/span&gt;&lt;span class="kwrd"&gt;="True"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Button&lt;/span&gt; &lt;span class="attr"&gt;ClickMode&lt;/span&gt;&lt;span class="kwrd"&gt;="Release"&lt;/span&gt; &lt;span class="attr"&gt;IsTabStop&lt;/span&gt;&lt;span class="kwrd"&gt;="True"&lt;/span&gt; &lt;span class="attr"&gt;IsEnabled&lt;/span&gt;&lt;span class="kwrd"&gt;="True"&lt;/span&gt; &lt;span class="attr"&gt;TabIndex&lt;/span&gt;&lt;span class="kwrd"&gt;="2147483647"&lt;/span&gt; &lt;span class="attr"&gt;TabNavigation&lt;/span&gt;&lt;span class="kwrd"&gt;="Local"&lt;/span&gt; &lt;span class="attr"&gt;Padding&lt;/span&gt;&lt;span class="kwrd"&gt;="3,3,3,3"&lt;/span&gt; &lt;span class="attr"&gt;BorderThickness&lt;/span&gt;&lt;span class="kwrd"&gt;="1,1,1,1"&lt;/span&gt; &lt;span class="attr"&gt;HorizontalContentAlignment&lt;/span&gt;&lt;span class="kwrd"&gt;="Center"&lt;/span&gt; &lt;span class="attr"&gt;VerticalContentAlignment&lt;/span&gt;&lt;span class="kwrd"&gt;="Center"&lt;/span&gt; &lt;span class="attr"&gt;FontFamily&lt;/span&gt;&lt;span class="kwrd"&gt;="Portable User Interface"&lt;/span&gt; &lt;span class="attr"&gt;FontSize&lt;/span&gt;&lt;span class="kwrd"&gt;="11"&lt;/span&gt; &lt;span class="attr"&gt;FontStretch&lt;/span&gt;&lt;span class="kwrd"&gt;="Normal"&lt;/span&gt; &lt;span class="attr"&gt;FontStyle&lt;/span&gt;&lt;span class="kwrd"&gt;="Normal"&lt;/span&gt; &lt;span class="attr"&gt;FontWeight&lt;/span&gt;&lt;span class="kwrd"&gt;="Normal"&lt;/span&gt; &lt;span class="attr"&gt;Width&lt;/span&gt;&lt;span class="kwrd"&gt;="100"&lt;/span&gt; &lt;span class="attr"&gt;Height&lt;/span&gt;&lt;span class="kwrd"&gt;="100"&lt;/span&gt; &lt;span class="attr"&gt;MinWidth&lt;/span&gt;&lt;span class="kwrd"&gt;="0"&lt;/span&gt; &lt;span class="attr"&gt;MaxWidth&lt;/span&gt;&lt;span class="kwrd"&gt;="Infinity"&lt;/span&gt; &lt;span class="attr"&gt;MinHeight&lt;/span&gt;&lt;span class="kwrd"&gt;="0"&lt;/span&gt; &lt;span class="attr"&gt;MaxHeight&lt;/span&gt;&lt;span class="kwrd"&gt;="Infinity"&lt;/span&gt; &lt;span class="attr"&gt;HorizontalAlignment&lt;/span&gt;&lt;span class="kwrd"&gt;="Stretch"&lt;/span&gt; &lt;span class="attr"&gt;VerticalAlignment&lt;/span&gt;&lt;span class="kwrd"&gt;="Stretch"&lt;/span&gt; &lt;span class="attr"&gt;Margin&lt;/span&gt;&lt;span class="kwrd"&gt;="0,0,0,0"&lt;/span&gt; &lt;span class="attr"&gt;x:Name&lt;/span&gt;&lt;span class="kwrd"&gt;="tt"&lt;/span&gt; &lt;span class="attr"&gt;Opacity&lt;/span&gt;&lt;span class="kwrd"&gt;="1"&lt;/span&gt; &lt;span class="attr"&gt;RenderTransformOrigin&lt;/span&gt;&lt;span class="kwrd"&gt;="0,0"&lt;/span&gt; &lt;span class="attr"&gt;IsHitTestVisible&lt;/span&gt;&lt;span class="kwrd"&gt;="True"&lt;/span&gt; &lt;span class="attr"&gt;Visibility&lt;/span&gt;&lt;span class="kwrd"&gt;="Visible"&lt;/span&gt; &lt;span class="attr"&gt;UseLayoutRounding&lt;/span&gt;&lt;span class="kwrd"&gt;="True"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Button.Background&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;SolidColorBrush&lt;/span&gt; &lt;span class="attr"&gt;Color&lt;/span&gt;&lt;span class="kwrd"&gt;="#FF1F3B53"&lt;/span&gt; &lt;span class="attr"&gt;Opacity&lt;/span&gt;&lt;span class="kwrd"&gt;="1"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
          &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Button.Background&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Button.BorderBrush&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;LinearGradientBrush&lt;/span&gt; &lt;span class="attr"&gt;StartPoint&lt;/span&gt;&lt;span class="kwrd"&gt;="0.5,0"&lt;/span&gt; &lt;span class="attr"&gt;EndPoint&lt;/span&gt;&lt;span class="kwrd"&gt;="0.5,1"&lt;/span&gt; &lt;span class="attr"&gt;SpreadMethod&lt;/span&gt;&lt;span class="kwrd"&gt;="Pad"&lt;/span&gt; &lt;span class="attr"&gt;MappingMode&lt;/span&gt;&lt;span class="kwrd"&gt;="RelativeToBoundingBox"&lt;/span&gt; &lt;span class="attr"&gt;ColorInterpolationMode&lt;/span&gt;&lt;span class="kwrd"&gt;="SRgbLinearInterpolation"&lt;/span&gt; &lt;span class="attr"&gt;Opacity&lt;/span&gt;&lt;span class="kwrd"&gt;="1"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
              &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;LinearGradientBrush.GradientStops&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;GradientStop&lt;/span&gt; &lt;span class="attr"&gt;Color&lt;/span&gt;&lt;span class="kwrd"&gt;="#FFA3AEB9"&lt;/span&gt; &lt;span class="attr"&gt;Offset&lt;/span&gt;&lt;span class="kwrd"&gt;="0"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
                &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;GradientStop&lt;/span&gt; &lt;span class="attr"&gt;Color&lt;/span&gt;&lt;span class="kwrd"&gt;="#FF8399A9"&lt;/span&gt; &lt;span class="attr"&gt;Offset&lt;/span&gt;&lt;span class="kwrd"&gt;="0.375"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
                &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;GradientStop&lt;/span&gt; &lt;span class="attr"&gt;Color&lt;/span&gt;&lt;span class="kwrd"&gt;="#FF718597"&lt;/span&gt; &lt;span class="attr"&gt;Offset&lt;/span&gt;&lt;span class="kwrd"&gt;="0.375"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
                &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;GradientStop&lt;/span&gt; &lt;span class="attr"&gt;Color&lt;/span&gt;&lt;span class="kwrd"&gt;="#FF617584"&lt;/span&gt; &lt;span class="attr"&gt;Offset&lt;/span&gt;&lt;span class="kwrd"&gt;="1"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
              &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;LinearGradientBrush.GradientStops&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;LinearGradientBrush&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Button.BorderBrush&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Button.Foreground&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;SolidColorBrush&lt;/span&gt; &lt;span class="attr"&gt;Color&lt;/span&gt;&lt;span class="kwrd"&gt;="#FF000000"&lt;/span&gt; &lt;span class="attr"&gt;Opacity&lt;/span&gt;&lt;span class="kwrd"&gt;="1"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
          &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Button.Foreground&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Button&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Grid&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Border&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Button&lt;/span&gt; &lt;span class="attr"&gt;ClickMode&lt;/span&gt;&lt;span class="kwrd"&gt;="Release"&lt;/span&gt; &lt;span class="attr"&gt;IsTabStop&lt;/span&gt;&lt;span class="kwrd"&gt;="True"&lt;/span&gt; &lt;span class="attr"&gt;IsEnabled&lt;/span&gt;&lt;span class="kwrd"&gt;="True"&lt;/span&gt; &lt;span class="attr"&gt;TabIndex&lt;/span&gt;&lt;span class="kwrd"&gt;="2147483647"&lt;/span&gt; &lt;span class="attr"&gt;TabNavigation&lt;/span&gt;&lt;span class="kwrd"&gt;="Local"&lt;/span&gt; &lt;span class="attr"&gt;Padding&lt;/span&gt;&lt;span class="kwrd"&gt;="3,3,3,3"&lt;/span&gt; &lt;span class="attr"&gt;BorderThickness&lt;/span&gt;&lt;span class="kwrd"&gt;="1,1,1,1"&lt;/span&gt; &lt;span class="attr"&gt;HorizontalContentAlignment&lt;/span&gt;&lt;span class="kwrd"&gt;="Center"&lt;/span&gt; &lt;span class="attr"&gt;VerticalContentAlignment&lt;/span&gt;&lt;span class="kwrd"&gt;="Center"&lt;/span&gt; &lt;span class="attr"&gt;FontFamily&lt;/span&gt;&lt;span class="kwrd"&gt;="Portable User Interface"&lt;/span&gt; &lt;span class="attr"&gt;FontSize&lt;/span&gt;&lt;span class="kwrd"&gt;="11"&lt;/span&gt; &lt;span class="attr"&gt;FontStretch&lt;/span&gt;&lt;span class="kwrd"&gt;="Normal"&lt;/span&gt; &lt;span class="attr"&gt;FontStyle&lt;/span&gt;&lt;span class="kwrd"&gt;="Normal"&lt;/span&gt; &lt;span class="attr"&gt;FontWeight&lt;/span&gt;&lt;span class="kwrd"&gt;="Normal"&lt;/span&gt; &lt;span class="attr"&gt;Width&lt;/span&gt;&lt;span class="kwrd"&gt;="100"&lt;/span&gt; &lt;span class="attr"&gt;Height&lt;/span&gt;&lt;span class="kwrd"&gt;="100"&lt;/span&gt; &lt;span class="attr"&gt;MinWidth&lt;/span&gt;&lt;span class="kwrd"&gt;="0"&lt;/span&gt; &lt;span class="attr"&gt;MaxWidth&lt;/span&gt;&lt;span class="kwrd"&gt;="Infinity"&lt;/span&gt; &lt;span class="attr"&gt;MinHeight&lt;/span&gt;&lt;span class="kwrd"&gt;="0"&lt;/span&gt; &lt;span class="attr"&gt;MaxHeight&lt;/span&gt;&lt;span class="kwrd"&gt;="Infinity"&lt;/span&gt; &lt;span class="attr"&gt;HorizontalAlignment&lt;/span&gt;&lt;span class="kwrd"&gt;="Stretch"&lt;/span&gt; &lt;span class="attr"&gt;VerticalAlignment&lt;/span&gt;&lt;span class="kwrd"&gt;="Stretch"&lt;/span&gt; &lt;span class="attr"&gt;Margin&lt;/span&gt;&lt;span class="kwrd"&gt;="0,0,0,0"&lt;/span&gt; &lt;span class="attr"&gt;x:Name&lt;/span&gt;&lt;span class="kwrd"&gt;="zz"&lt;/span&gt; &lt;span class="attr"&gt;Opacity&lt;/span&gt;&lt;span class="kwrd"&gt;="1"&lt;/span&gt; &lt;span class="attr"&gt;RenderTransformOrigin&lt;/span&gt;&lt;span class="kwrd"&gt;="0,0"&lt;/span&gt; &lt;span class="attr"&gt;IsHitTestVisible&lt;/span&gt;&lt;span class="kwrd"&gt;="True"&lt;/span&gt; &lt;span class="attr"&gt;Visibility&lt;/span&gt;&lt;span class="kwrd"&gt;="Visible"&lt;/span&gt; &lt;span class="attr"&gt;UseLayoutRounding&lt;/span&gt;&lt;span class="kwrd"&gt;="True"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Button.Background&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;SolidColorBrush&lt;/span&gt; &lt;span class="attr"&gt;Color&lt;/span&gt;&lt;span class="kwrd"&gt;="#FF1F3B53"&lt;/span&gt; &lt;span class="attr"&gt;Opacity&lt;/span&gt;&lt;span class="kwrd"&gt;="1"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Button.Background&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Button.BorderBrush&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;LinearGradientBrush&lt;/span&gt; &lt;span class="attr"&gt;StartPoint&lt;/span&gt;&lt;span class="kwrd"&gt;="0.5,0"&lt;/span&gt; &lt;span class="attr"&gt;EndPoint&lt;/span&gt;&lt;span class="kwrd"&gt;="0.5,1"&lt;/span&gt; &lt;span class="attr"&gt;SpreadMethod&lt;/span&gt;&lt;span class="kwrd"&gt;="Pad"&lt;/span&gt; &lt;span class="attr"&gt;MappingMode&lt;/span&gt;&lt;span class="kwrd"&gt;="RelativeToBoundingBox"&lt;/span&gt; &lt;span class="attr"&gt;ColorInterpolationMode&lt;/span&gt;&lt;span class="kwrd"&gt;="SRgbLinearInterpolation"&lt;/span&gt; &lt;span class="attr"&gt;Opacity&lt;/span&gt;&lt;span class="kwrd"&gt;="1"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;LinearGradientBrush.GradientStops&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;GradientStop&lt;/span&gt; &lt;span class="attr"&gt;Color&lt;/span&gt;&lt;span class="kwrd"&gt;="#FFA3AEB9"&lt;/span&gt; &lt;span class="attr"&gt;Offset&lt;/span&gt;&lt;span class="kwrd"&gt;="0"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;GradientStop&lt;/span&gt; &lt;span class="attr"&gt;Color&lt;/span&gt;&lt;span class="kwrd"&gt;="#FF8399A9"&lt;/span&gt; &lt;span class="attr"&gt;Offset&lt;/span&gt;&lt;span class="kwrd"&gt;="0.375"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;GradientStop&lt;/span&gt; &lt;span class="attr"&gt;Color&lt;/span&gt;&lt;span class="kwrd"&gt;="#FF718597"&lt;/span&gt; &lt;span class="attr"&gt;Offset&lt;/span&gt;&lt;span class="kwrd"&gt;="0.375"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;GradientStop&lt;/span&gt; &lt;span class="attr"&gt;Color&lt;/span&gt;&lt;span class="kwrd"&gt;="#FF617584"&lt;/span&gt; &lt;span class="attr"&gt;Offset&lt;/span&gt;&lt;span class="kwrd"&gt;="1"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
          &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;LinearGradientBrush.GradientStops&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;LinearGradientBrush&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Button.BorderBrush&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Button.Foreground&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;SolidColorBrush&lt;/span&gt; &lt;span class="attr"&gt;Color&lt;/span&gt;&lt;span class="kwrd"&gt;="#FF000000"&lt;/span&gt; &lt;span class="attr"&gt;Opacity&lt;/span&gt;&lt;span class="kwrd"&gt;="1"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Button.Foreground&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Button&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Grid&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;UserControl&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;

WriteXaml(MyControl, XamlWriterSettings.VisualTree) will generate this Xaml

&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;UserControl&lt;/span&gt; &lt;span class="attr"&gt;xmlns&lt;/span&gt;&lt;span class="kwrd"&gt;="http://schemas.microsoft.com/winfx/2006/xaml/presentation"&lt;/span&gt; &lt;span class="attr"&gt;xmlns:x&lt;/span&gt;&lt;span class="kwrd"&gt;="http://schemas.microsoft.com/winfx/2006/xaml"&lt;/span&gt; &lt;span class="attr"&gt;Width&lt;/span&gt;&lt;span class="kwrd"&gt;="850"&lt;/span&gt; &lt;span class="attr"&gt;Height&lt;/span&gt;&lt;span class="kwrd"&gt;="447"&lt;/span&gt; &lt;span class="attr"&gt;x:Name&lt;/span&gt;&lt;span class="kwrd"&gt;="MyControl"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Grid&lt;/span&gt; &lt;span class="attr"&gt;x:Name&lt;/span&gt;&lt;span class="kwrd"&gt;="test"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Grid.RowDefinitions&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;RowDefinition&lt;/span&gt; &lt;span class="attr"&gt;Height&lt;/span&gt;&lt;span class="kwrd"&gt;="60"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;RowDefinition&lt;/span&gt; &lt;span class="attr"&gt;Height&lt;/span&gt;&lt;span class="kwrd"&gt;="54"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;RowDefinition&lt;/span&gt; &lt;span class="attr"&gt;Height&lt;/span&gt;&lt;span class="kwrd"&gt;="1*"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Grid.RowDefinitions&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Grid.ColumnDefinitions&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;ColumnDefinition&lt;/span&gt; &lt;span class="attr"&gt;Width&lt;/span&gt;&lt;span class="kwrd"&gt;="60"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;ColumnDefinition&lt;/span&gt; &lt;span class="attr"&gt;Width&lt;/span&gt;&lt;span class="kwrd"&gt;="54"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;ColumnDefinition&lt;/span&gt; &lt;span class="attr"&gt;Width&lt;/span&gt;&lt;span class="kwrd"&gt;="1*"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Grid.ColumnDefinitions&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Border&lt;/span&gt; &lt;span class="attr"&gt;BorderThickness&lt;/span&gt;&lt;span class="kwrd"&gt;="0,3,0,0"&lt;/span&gt; &lt;span class="attr"&gt;Margin&lt;/span&gt;&lt;span class="kwrd"&gt;="0,58,0,0"&lt;/span&gt; &lt;span class="attr"&gt;x:Name&lt;/span&gt;&lt;span class="kwrd"&gt;="ContentBorder"&lt;/span&gt; &lt;span class="attr"&gt;Opacity&lt;/span&gt;&lt;span class="kwrd"&gt;="0.5"&lt;/span&gt; &lt;span class="attr"&gt;Grid&lt;/span&gt;.&lt;span class="attr"&gt;Row&lt;/span&gt;&lt;span class="kwrd"&gt;="1"&lt;/span&gt; &lt;span class="attr"&gt;Grid&lt;/span&gt;.&lt;span class="attr"&gt;Column&lt;/span&gt;&lt;span class="kwrd"&gt;="2"&lt;/span&gt; &lt;span class="attr"&gt;BorderBrush&lt;/span&gt;&lt;span class="kwrd"&gt;="#FFAFAFAF"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Grid&lt;/span&gt; &lt;span class="attr"&gt;x:Name&lt;/span&gt;&lt;span class="kwrd"&gt;="CurrentContent"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Button&lt;/span&gt; &lt;span class="attr"&gt;Width&lt;/span&gt;&lt;span class="kwrd"&gt;="100"&lt;/span&gt; &lt;span class="attr"&gt;Height&lt;/span&gt;&lt;span class="kwrd"&gt;="100"&lt;/span&gt; &lt;span class="attr"&gt;x:Name&lt;/span&gt;&lt;span class="kwrd"&gt;="tt"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Grid&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Border&lt;/span&gt; &lt;span class="attr"&gt;BorderThickness&lt;/span&gt;&lt;span class="kwrd"&gt;="1,1,1,1"&lt;/span&gt; &lt;span class="attr"&gt;CornerRadius&lt;/span&gt;&lt;span class="kwrd"&gt;="3,3,3,3"&lt;/span&gt; &lt;span class="attr"&gt;x:Name&lt;/span&gt;&lt;span class="kwrd"&gt;="Background"&lt;/span&gt; &lt;span class="attr"&gt;Background&lt;/span&gt;&lt;span class="kwrd"&gt;="#FFFFFFFF"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
              &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Border.BorderBrush&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;LinearGradientBrush&lt;/span&gt; &lt;span class="attr"&gt;StartPoint&lt;/span&gt;&lt;span class="kwrd"&gt;="0.5,0"&lt;/span&gt; &lt;span class="attr"&gt;EndPoint&lt;/span&gt;&lt;span class="kwrd"&gt;="0.5,1"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                  &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;LinearGradientBrush.GradientStops&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;GradientStop&lt;/span&gt; &lt;span class="attr"&gt;Color&lt;/span&gt;&lt;span class="kwrd"&gt;="#FFA3AEB9"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
                    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;GradientStop&lt;/span&gt; &lt;span class="attr"&gt;Color&lt;/span&gt;&lt;span class="kwrd"&gt;="#FF8399A9"&lt;/span&gt; &lt;span class="attr"&gt;Offset&lt;/span&gt;&lt;span class="kwrd"&gt;="0.375"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
                    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;GradientStop&lt;/span&gt; &lt;span class="attr"&gt;Color&lt;/span&gt;&lt;span class="kwrd"&gt;="#FF718597"&lt;/span&gt; &lt;span class="attr"&gt;Offset&lt;/span&gt;&lt;span class="kwrd"&gt;="0.375"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
                    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;GradientStop&lt;/span&gt; &lt;span class="attr"&gt;Color&lt;/span&gt;&lt;span class="kwrd"&gt;="#FF617584"&lt;/span&gt; &lt;span class="attr"&gt;Offset&lt;/span&gt;&lt;span class="kwrd"&gt;="1"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
                  &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;LinearGradientBrush.GradientStops&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;LinearGradientBrush&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
              &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Border.BorderBrush&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
              &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Grid&lt;/span&gt; &lt;span class="attr"&gt;Margin&lt;/span&gt;&lt;span class="kwrd"&gt;="1,1,1,1"&lt;/span&gt; &lt;span class="attr"&gt;Background&lt;/span&gt;&lt;span class="kwrd"&gt;="#FF1F3B53"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Border&lt;/span&gt; &lt;span class="attr"&gt;x:Name&lt;/span&gt;&lt;span class="kwrd"&gt;="BackgroundAnimation"&lt;/span&gt; &lt;span class="attr"&gt;Opacity&lt;/span&gt;&lt;span class="kwrd"&gt;="0"&lt;/span&gt; &lt;span class="attr"&gt;Background&lt;/span&gt;&lt;span class="kwrd"&gt;="#FF448DCA"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
                &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Rectangle&lt;/span&gt; &lt;span class="attr"&gt;x:Name&lt;/span&gt;&lt;span class="kwrd"&gt;="BackgroundGradient"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                  &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Rectangle.Fill&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;LinearGradientBrush&lt;/span&gt; &lt;span class="attr"&gt;StartPoint&lt;/span&gt;&lt;span class="kwrd"&gt;="0.699999988079071,0"&lt;/span&gt; &lt;span class="attr"&gt;EndPoint&lt;/span&gt;&lt;span class="kwrd"&gt;="0.699999988079071,1"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                      &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;LinearGradientBrush.GradientStops&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;GradientStop&lt;/span&gt; &lt;span class="attr"&gt;Color&lt;/span&gt;&lt;span class="kwrd"&gt;="#FFFFFFFF"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
                        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;GradientStop&lt;/span&gt; &lt;span class="attr"&gt;Color&lt;/span&gt;&lt;span class="kwrd"&gt;="#F9FFFFFF"&lt;/span&gt; &lt;span class="attr"&gt;Offset&lt;/span&gt;&lt;span class="kwrd"&gt;="0.375"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
                        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;GradientStop&lt;/span&gt; &lt;span class="attr"&gt;Color&lt;/span&gt;&lt;span class="kwrd"&gt;="#E5FFFFFF"&lt;/span&gt; &lt;span class="attr"&gt;Offset&lt;/span&gt;&lt;span class="kwrd"&gt;="0.625"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
                        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;GradientStop&lt;/span&gt; &lt;span class="attr"&gt;Color&lt;/span&gt;&lt;span class="kwrd"&gt;="#C6FFFFFF"&lt;/span&gt; &lt;span class="attr"&gt;Offset&lt;/span&gt;&lt;span class="kwrd"&gt;="1"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
                      &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;LinearGradientBrush.GradientStops&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;LinearGradientBrush&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                  &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Rectangle.Fill&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Rectangle&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
              &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Grid&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Border&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;ContentPresenter&lt;/span&gt; &lt;span class="attr"&gt;HorizontalAlignment&lt;/span&gt;&lt;span class="kwrd"&gt;="Center"&lt;/span&gt; &lt;span class="attr"&gt;VerticalAlignment&lt;/span&gt;&lt;span class="kwrd"&gt;="Center"&lt;/span&gt; &lt;span class="attr"&gt;Margin&lt;/span&gt;&lt;span class="kwrd"&gt;="3,3,3,3"&lt;/span&gt; &lt;span class="attr"&gt;x:Name&lt;/span&gt;&lt;span class="kwrd"&gt;="contentPresenter"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Rectangle&lt;/span&gt; &lt;span class="attr"&gt;RadiusX&lt;/span&gt;&lt;span class="kwrd"&gt;="3"&lt;/span&gt; &lt;span class="attr"&gt;RadiusY&lt;/span&gt;&lt;span class="kwrd"&gt;="3"&lt;/span&gt; &lt;span class="attr"&gt;x:Name&lt;/span&gt;&lt;span class="kwrd"&gt;="DisabledVisualElement"&lt;/span&gt; &lt;span class="attr"&gt;Opacity&lt;/span&gt;&lt;span class="kwrd"&gt;="0"&lt;/span&gt; &lt;span class="attr"&gt;IsHitTestVisible&lt;/span&gt;&lt;span class="kwrd"&gt;="False"&lt;/span&gt; &lt;span class="attr"&gt;Fill&lt;/span&gt;&lt;span class="kwrd"&gt;="#FFFFFFFF"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Rectangle&lt;/span&gt; &lt;span class="attr"&gt;RadiusX&lt;/span&gt;&lt;span class="kwrd"&gt;="2"&lt;/span&gt; &lt;span class="attr"&gt;RadiusY&lt;/span&gt;&lt;span class="kwrd"&gt;="2"&lt;/span&gt; &lt;span class="attr"&gt;Margin&lt;/span&gt;&lt;span class="kwrd"&gt;="1,1,1,1"&lt;/span&gt; &lt;span class="attr"&gt;x:Name&lt;/span&gt;&lt;span class="kwrd"&gt;="FocusVisualElement"&lt;/span&gt; &lt;span class="attr"&gt;Opacity&lt;/span&gt;&lt;span class="kwrd"&gt;="0"&lt;/span&gt; &lt;span class="attr"&gt;IsHitTestVisible&lt;/span&gt;&lt;span class="kwrd"&gt;="False"&lt;/span&gt; &lt;span class="attr"&gt;Stroke&lt;/span&gt;&lt;span class="kwrd"&gt;="#FF6DBDD1"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
          &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Grid&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Button&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Grid&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Border&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Button&lt;/span&gt; &lt;span class="attr"&gt;Width&lt;/span&gt;&lt;span class="kwrd"&gt;="100"&lt;/span&gt; &lt;span class="attr"&gt;Height&lt;/span&gt;&lt;span class="kwrd"&gt;="100"&lt;/span&gt; &lt;span class="attr"&gt;x:Name&lt;/span&gt;&lt;span class="kwrd"&gt;="zz"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Grid&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Border&lt;/span&gt; &lt;span class="attr"&gt;BorderThickness&lt;/span&gt;&lt;span class="kwrd"&gt;="1,1,1,1"&lt;/span&gt; &lt;span class="attr"&gt;CornerRadius&lt;/span&gt;&lt;span class="kwrd"&gt;="3,3,3,3"&lt;/span&gt; &lt;span class="attr"&gt;x:Name&lt;/span&gt;&lt;span class="kwrd"&gt;="Background"&lt;/span&gt; &lt;span class="attr"&gt;Background&lt;/span&gt;&lt;span class="kwrd"&gt;="#FF6DBDD1"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Border.BorderBrush&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;LinearGradientBrush&lt;/span&gt; &lt;span class="attr"&gt;StartPoint&lt;/span&gt;&lt;span class="kwrd"&gt;="0.5,0"&lt;/span&gt; &lt;span class="attr"&gt;EndPoint&lt;/span&gt;&lt;span class="kwrd"&gt;="0.5,1"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
              &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;LinearGradientBrush.GradientStops&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;GradientStop&lt;/span&gt; &lt;span class="attr"&gt;Color&lt;/span&gt;&lt;span class="kwrd"&gt;="#FFA3AEB9"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
                &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;GradientStop&lt;/span&gt; &lt;span class="attr"&gt;Color&lt;/span&gt;&lt;span class="kwrd"&gt;="#FF8399A9"&lt;/span&gt; &lt;span class="attr"&gt;Offset&lt;/span&gt;&lt;span class="kwrd"&gt;="0.375"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
                &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;GradientStop&lt;/span&gt; &lt;span class="attr"&gt;Color&lt;/span&gt;&lt;span class="kwrd"&gt;="#FF718597"&lt;/span&gt; &lt;span class="attr"&gt;Offset&lt;/span&gt;&lt;span class="kwrd"&gt;="0.375"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
                &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;GradientStop&lt;/span&gt; &lt;span class="attr"&gt;Color&lt;/span&gt;&lt;span class="kwrd"&gt;="#FF617584"&lt;/span&gt; &lt;span class="attr"&gt;Offset&lt;/span&gt;&lt;span class="kwrd"&gt;="1"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
              &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;LinearGradientBrush.GradientStops&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;LinearGradientBrush&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Border.BorderBrush&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Grid&lt;/span&gt; &lt;span class="attr"&gt;Margin&lt;/span&gt;&lt;span class="kwrd"&gt;="1,1,1,1"&lt;/span&gt; &lt;span class="attr"&gt;Background&lt;/span&gt;&lt;span class="kwrd"&gt;="#FF1F3B53"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Border&lt;/span&gt; &lt;span class="attr"&gt;x:Name&lt;/span&gt;&lt;span class="kwrd"&gt;="BackgroundAnimation"&lt;/span&gt; &lt;span class="attr"&gt;Background&lt;/span&gt;&lt;span class="kwrd"&gt;="#FF448DCA"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Rectangle&lt;/span&gt; &lt;span class="attr"&gt;x:Name&lt;/span&gt;&lt;span class="kwrd"&gt;="BackgroundGradient"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
              &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Rectangle.Fill&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;LinearGradientBrush&lt;/span&gt; &lt;span class="attr"&gt;StartPoint&lt;/span&gt;&lt;span class="kwrd"&gt;="0.699999988079071,0"&lt;/span&gt; &lt;span class="attr"&gt;EndPoint&lt;/span&gt;&lt;span class="kwrd"&gt;="0.699999988079071,1"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                  &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;LinearGradientBrush.GradientStops&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;GradientStop&lt;/span&gt; &lt;span class="attr"&gt;Color&lt;/span&gt;&lt;span class="kwrd"&gt;="#D8FFFFFF"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
                    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;GradientStop&lt;/span&gt; &lt;span class="attr"&gt;Color&lt;/span&gt;&lt;span class="kwrd"&gt;="#C6FFFFFF"&lt;/span&gt; &lt;span class="attr"&gt;Offset&lt;/span&gt;&lt;span class="kwrd"&gt;="0.375"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
                    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;GradientStop&lt;/span&gt; &lt;span class="attr"&gt;Color&lt;/span&gt;&lt;span class="kwrd"&gt;="#8CFFFFFF"&lt;/span&gt; &lt;span class="attr"&gt;Offset&lt;/span&gt;&lt;span class="kwrd"&gt;="0.625"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
                    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;GradientStop&lt;/span&gt; &lt;span class="attr"&gt;Color&lt;/span&gt;&lt;span class="kwrd"&gt;="#3FFFFFFF"&lt;/span&gt; &lt;span class="attr"&gt;Offset&lt;/span&gt;&lt;span class="kwrd"&gt;="1"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
                  &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;LinearGradientBrush.GradientStops&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;LinearGradientBrush&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
              &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Rectangle.Fill&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Rectangle&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Grid&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Border&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;ContentPresenter&lt;/span&gt; &lt;span class="attr"&gt;HorizontalAlignment&lt;/span&gt;&lt;span class="kwrd"&gt;="Center"&lt;/span&gt; &lt;span class="attr"&gt;VerticalAlignment&lt;/span&gt;&lt;span class="kwrd"&gt;="Center"&lt;/span&gt; &lt;span class="attr"&gt;Margin&lt;/span&gt;&lt;span class="kwrd"&gt;="3,3,3,3"&lt;/span&gt; &lt;span class="attr"&gt;x:Name&lt;/span&gt;&lt;span class="kwrd"&gt;="contentPresenter"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Rectangle&lt;/span&gt; &lt;span class="attr"&gt;RadiusX&lt;/span&gt;&lt;span class="kwrd"&gt;="3"&lt;/span&gt; &lt;span class="attr"&gt;RadiusY&lt;/span&gt;&lt;span class="kwrd"&gt;="3"&lt;/span&gt; &lt;span class="attr"&gt;x:Name&lt;/span&gt;&lt;span class="kwrd"&gt;="DisabledVisualElement"&lt;/span&gt; &lt;span class="attr"&gt;Opacity&lt;/span&gt;&lt;span class="kwrd"&gt;="0"&lt;/span&gt; &lt;span class="attr"&gt;IsHitTestVisible&lt;/span&gt;&lt;span class="kwrd"&gt;="False"&lt;/span&gt; &lt;span class="attr"&gt;Fill&lt;/span&gt;&lt;span class="kwrd"&gt;="#FFFFFFFF"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Rectangle&lt;/span&gt; &lt;span class="attr"&gt;RadiusX&lt;/span&gt;&lt;span class="kwrd"&gt;="2"&lt;/span&gt; &lt;span class="attr"&gt;RadiusY&lt;/span&gt;&lt;span class="kwrd"&gt;="2"&lt;/span&gt; &lt;span class="attr"&gt;Margin&lt;/span&gt;&lt;span class="kwrd"&gt;="1,1,1,1"&lt;/span&gt; &lt;span class="attr"&gt;x:Name&lt;/span&gt;&lt;span class="kwrd"&gt;="FocusVisualElement"&lt;/span&gt; &lt;span class="attr"&gt;IsHitTestVisible&lt;/span&gt;&lt;span class="kwrd"&gt;="False"&lt;/span&gt; &lt;span class="attr"&gt;Stroke&lt;/span&gt;&lt;span class="kwrd"&gt;="#FF6DBDD1"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Grid&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Button&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Grid&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;UserControl&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;

WriteXaml(MyControl, XamlWriterSettings.VisualTree | XamlWriterSettings.AllAttributes) will generate this Xaml

-- You get the idea! (too big to display here)&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7411255283791998153-9021772813635633200?l=projectsilverlight.blogspot.com'/&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/ProjectSilverlight/~4/MzmKywoYl0U" height="1" width="1"/&gt;</description><link>http://projectsilverlight.blogspot.com/2009/10/silverlight-3-xamlwriter-basic.html</link><author>noreply@blogger.com (Wilfred Pinto)</author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">1</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-7411255283791998153.post-6984863277386468412</guid><pubDate>Fri, 14 Aug 2009 07:52:00 +0000</pubDate><atom:updated>2009-08-14T01:31:40.306-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">job</category><title>I am available for contract work</title><description>It's been a long time since I last put up a post on this blog! I kind of got buried in my work which got more hectic since we had a few layoffs, which is when I finally decided to take a break, after 5 long but incredibly exciting years, and spend some time with my 2 year old daughter. I had an absolutely wonderful time the last few months taking it easy, but now the time has come to get back in the game!&lt;br /&gt;&lt;br /&gt;I recently peeked into the MSDN magazine &lt;span style="font-style:italic;"&gt;(July edition)&lt;/span&gt; and noticed this article - 'Taking Silverlight Deep Zoom to the Next Level' - by Jeff Prosise, and suddenly realized how much I missed doing this Deep Zoom stuff. The first half of his article is similar to some of the code I have on this blog. I was kind of surprised by this since I thought that no one would be interested in reading this stuff because it was so old - so last year! :) Apparently people are still interested in Deep Zoom related articles. I corroborated this by looking at the hits this blog has been receiving and I was surprised that the activity in the recent few months has been more than last year. I thought this was hot last year when we got a glimpse of the hard rock site but I guess lots of developers have been recently getting into Silverlight, especially Deep Zoom related.&lt;br /&gt;&lt;br /&gt;Anyways, I am free and passively looking for a contract assignment in .Net, Silverlight etc. I enjoy spending time with my daughter and would like to continue doing that so I am not looking for any assignment that includes travel &lt;span style="font-style:italic;"&gt;(minimal travel like a day here and there is fine)&lt;/span&gt;. So if you have an opening which doesn't include travel and think that I could be a good addition to your team &lt;span style="font-style:italic;"&gt;(based on what you see on this blog)&lt;/span&gt;, give me a buzz and we can chat.&lt;br /&gt;&lt;br /&gt;Cheers,&lt;br /&gt;&lt;br /&gt;Wilfred&lt;br /&gt;contactwilfred@yahoo.com&lt;br /&gt;Los Angeles, CA&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7411255283791998153-6984863277386468412?l=projectsilverlight.blogspot.com'/&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/ProjectSilverlight/~4/5A2637wklQo" height="1" width="1"/&gt;</description><link>http://projectsilverlight.blogspot.com/2009/08/i-am-available-for-contract-work.html</link><author>noreply@blogger.com (Wilfred Pinto)</author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-7411255283791998153.post-7503124713584813767</guid><pubDate>Sat, 18 Oct 2008 22:13:00 +0000</pubDate><atom:updated>2008-10-18T15:25:11.912-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">SimpleViewer</category><category domain="http://www.blogger.com/atom/ns#">Silverlight</category><title>SimpleViewer-SL ported to Silverlight 2 and uploaded to CodePlex</title><description>I finally got around to uploading the SimpleViewer-SL source code to &lt;a href="http://www.codeplex.com/simpleviewerSL"&gt;CodePlex&lt;/a&gt;. Minor changes were required to get the code to compile on Silverlight 2.&lt;br /&gt;&lt;br /&gt;The SimpleViewer-SL project on CodePlex can be found here: &lt;a href="http://www.codeplex.com/simpleviewerSL"&gt;http://www.codeplex.com/simpleviewerSL&lt;/a&gt;. Please feel free to report all bugs/issues/enhancements on &lt;a href="http://www.codeplex.com/simpleviewerSL/WorkItem/List.aspx"&gt;this&lt;/a&gt; site.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7411255283791998153-7503124713584813767?l=projectsilverlight.blogspot.com'/&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/ProjectSilverlight/~4/aBPBy-ioitA" height="1" width="1"/&gt;</description><link>http://projectsilverlight.blogspot.com/2008/10/simpleviewer-sl-ported-to-silverlight-2.html</link><author>noreply@blogger.com (Wilfred Pinto)</author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">1</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-7411255283791998153.post-5115814785992743856</guid><pubDate>Wed, 15 Oct 2008 04:21:00 +0000</pubDate><atom:updated>2008-10-14T21:58:14.025-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Deep Zoom</category><category domain="http://www.blogger.com/atom/ns#">Silverlight</category><title>DeepZoom sample ported to Silverlight 2</title><description>The source code can be found &lt;a href="http://thepintospatronus.com/deepzoom/DeepZoomOutput.zip"&gt;here&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;For those wanting to download the legacy code &lt;em&gt;(for whatever reason!)&lt;/em&gt; --&lt;ul&gt;&lt;li&gt;&lt;a href="http://thepintospatronus.com/deepzoom/DeepZoomOutput-RC0.zip"&gt;Silverlight 2 Release Candidate&lt;/a&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;a href="http://thepintospatronus.com/deepzoom/DeepZoomOutput-Beta2.zip"&gt;Silverlight 2 Beta 2&lt;/a&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;a href="http://thepintospatronus.com/deepzoom/DeepZoomOutput-Beta1.zip"&gt;Silverlight 2 Beta 1&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;Note that the disclaimer from this &lt;a href="http://projectsilverlight.blogspot.com/2008/04/dissecting-hard-rock-memorabilia-part-9.html"&gt;post &lt;/a&gt;still holds!&lt;br /&gt;&lt;br /&gt;All inline samples have been upgraded to work with Silverlight 2. If you are still using Beta 2 you will need to upgrade to view the samples!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7411255283791998153-5115814785992743856?l=projectsilverlight.blogspot.com'/&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/ProjectSilverlight/~4/bI9YiC32QKk" height="1" width="1"/&gt;</description><link>http://projectsilverlight.blogspot.com/2008/10/deepzoom-sample-ported-to-silverlight-2.html</link><author>noreply@blogger.com (Wilfred Pinto)</author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">1</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-7411255283791998153.post-2726121751997640199</guid><pubDate>Mon, 07 Jul 2008 23:10:00 +0000</pubDate><atom:updated>2008-10-14T16:36:03.760-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Deep Zoom</category><category domain="http://www.blogger.com/atom/ns#">Silverlight</category><category domain="http://www.blogger.com/atom/ns#">Beta2</category><title>Deep Zoom - Rendering in 2 different layouts based on zoom factor</title><description>Berend, the author of &lt;span style="font-style:italic;"&gt;&lt;a href="http://www.codeproject.com/KB/silverlight/DecosDeepZoom.aspx"&gt;Generate Silverlight 2 DeepZoom image collection from multi-page tiff&lt;/a&gt;&lt;/span&gt;, wanted to know if it was possible to render the contents of the deep zoom control in different layouts based on the current zoom factor. Initially, he wanted to show the images in a single row layout with each image taking the entire height of the control. As the user zooms out, after the image reaches a certain factor - say half the height, he wanted to switch to a thumbnails mode where all the images are displayed in a multi row and column format (&lt;span style="font-style:italic;"&gt;much like how it is now&lt;/span&gt;).&lt;br /&gt;&lt;br /&gt;It was pretty easy to do and here is the result of my experimentation:&lt;br /&gt;&lt;p align="center"&gt; &lt;iframe id="I1" border="0" marginheight="0" marginwidth="0" name="I1" src="http://thepintospatronus.com/deepzoom/ClientBin/DeepZoomOutput2.html" style="width: 389px; height: 309px;" frameborder="0" scrolling="no"&gt; Your browser does not support inline frames or is currently configured not to display inline frames. &lt;/iframe&gt; &lt;/p&gt;&lt;br /&gt;Try zooming out so that the first image height is less than half the height of the control. After the motion is completed, it should switch to the thumbnails mode. I have currently based this off the height of the first image. The layout will switch depending on whether the height of the first image is greater than or less than half the height of the control.&lt;br /&gt;&lt;br /&gt;The code:&lt;br /&gt;&lt;pre class="csharpcode"&gt;&lt;br /&gt;&lt;span class="kwrd"&gt;enum&lt;/span&gt; DisplayMode {&lt;br /&gt;    Full = 1,&lt;br /&gt;    Thumbnails = 2&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;DisplayMode _displayMode = DisplayMode.Full;&lt;br /&gt;&lt;br /&gt;msi.MotionFinished += &lt;span class="kwrd"&gt;delegate&lt;/span&gt;(&lt;span class="kwrd"&gt;object&lt;/span&gt; sender, RoutedEventArgs e)&lt;br /&gt;{&lt;br /&gt;    &lt;span class="rem"&gt;// This is required to ensure that ArrangeImages is called only once&lt;/span&gt;&lt;br /&gt;    &lt;span class="kwrd"&gt;if&lt;/span&gt; (msi.UseSprings == &lt;span class="kwrd"&gt;false&lt;/span&gt;) {&lt;br /&gt;        ShowAllImages();&lt;br /&gt;        msi.UseSprings = &lt;span class="kwrd"&gt;true&lt;/span&gt;;&lt;br /&gt;    }&lt;br /&gt;    &lt;span class="kwrd"&gt;else&lt;/span&gt; {&lt;br /&gt;        DisplayMode _origDisplayMode = _displayMode;&lt;br /&gt;        &lt;br /&gt;        Rect imageRectElement = msiLogicalToElementRect(GetSubImageRect(0));&lt;br /&gt;        _displayMode = (msi.ActualHeight / imageRectElement.Height &amp;lt; 2) ? DisplayMode.Full : DisplayMode.Thumbnails;&lt;br /&gt;&lt;br /&gt;        &lt;span class="kwrd"&gt;if&lt;/span&gt; (_displayMode != _origDisplayMode) {&lt;br /&gt;            Reset();&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Reset()&lt;br /&gt;{&lt;br /&gt;    _lastMousePos = &lt;span class="kwrd"&gt;new&lt;/span&gt; Point(0, 0);&lt;br /&gt;    msi.ViewportOrigin = &lt;span class="kwrd"&gt;new&lt;/span&gt; Point (0, 0);&lt;br /&gt;    msi.ViewportWidth = 1.0;&lt;br /&gt;&lt;br /&gt;    &lt;span class="rem"&gt;// Show all the images&lt;/span&gt;&lt;br /&gt;    _imagesToShow.Clear();&lt;br /&gt;    _imagesToHide.Clear();&lt;br /&gt;    &lt;span class="kwrd"&gt;for&lt;/span&gt; (&lt;span class="kwrd"&gt;int&lt;/span&gt; i=0; i&amp;lt;msi.SubImages.Count; i++) {&lt;br /&gt;        _imagesToShow.Add(msi.SubImages[i]);&lt;br /&gt;    }&lt;br /&gt;    ArrangeImages();&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; ArrangeImages()&lt;br /&gt;{&lt;br /&gt;    InitStoryboard();&lt;br /&gt;    &lt;br /&gt;    &lt;span class="kwrd"&gt;double&lt;/span&gt; containerAspectRatio = &lt;span class="kwrd"&gt;this&lt;/span&gt;.msi.ActualWidth / &lt;span class="kwrd"&gt;this&lt;/span&gt;.msi.ActualHeight;&lt;br /&gt;    &lt;span class="kwrd"&gt;double&lt;/span&gt; spaceBetweenImages = 0.005;&lt;br /&gt;&lt;br /&gt;    List&amp;lt;SubImage&amp;gt; subImages = &lt;span class="kwrd"&gt;new&lt;/span&gt; List&amp;lt;SubImage&amp;gt;();&lt;br /&gt;    _imagesToShow.ForEach(subImage =&amp;gt; subImages.Add(&lt;span class="kwrd"&gt;new&lt;/span&gt; SubImage(subImage)));&lt;br /&gt;    &lt;br /&gt;    &lt;span class="rem"&gt;// Capture the total width of all images&lt;/span&gt;&lt;br /&gt;    &lt;span class="kwrd"&gt;double&lt;/span&gt; totalImagesWidth = 0.0;&lt;br /&gt;    subImages.ForEach(subImage =&amp;gt; totalImagesWidth += subImage.Width);&lt;br /&gt;&lt;br /&gt;    &lt;span class="rem"&gt;// Calculate the total number of rows required to display all the images&lt;/span&gt;&lt;br /&gt;    &lt;span class="asp"&gt;&lt;span class="kwrd"&gt;int&lt;/span&gt; numRows = (_displayMode == DisplayMode.Thumbnails) ? (&lt;span class="kwrd"&gt;int&lt;/span&gt;)Math.Sqrt((totalImagesWidth / containerAspectRatio)+1) : 1;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span class="rem"&gt;// Assign images to each row&lt;/span&gt;&lt;br /&gt;    List&amp;lt;Row&amp;gt; rows = &lt;span class="kwrd"&gt;new&lt;/span&gt; List&amp;lt;Row&amp;gt;(numRows);&lt;br /&gt;    &lt;span class="kwrd"&gt;for&lt;/span&gt; (&lt;span class="kwrd"&gt;int&lt;/span&gt; i=0; i&amp;lt;numRows; i++)&lt;br /&gt;        rows.Add(&lt;span class="kwrd"&gt;new&lt;/span&gt; Row(spaceBetweenImages));&lt;br /&gt;&lt;br /&gt;    &lt;span class="kwrd"&gt;double&lt;/span&gt; widthPerRow = totalImagesWidth / numRows;&lt;br /&gt;    &lt;span class="kwrd"&gt;double&lt;/span&gt; imagesWidth = 0;&lt;br /&gt;    &lt;span class="rem"&gt;// Separate the images into rows. The total width of all images in a row should not exceed widthPerRow&lt;/span&gt;&lt;br /&gt;    &lt;span class="kwrd"&gt;for&lt;/span&gt; (&lt;span class="kwrd"&gt;int&lt;/span&gt; i=0, j=0; i&amp;lt;numRows; i++, imagesWidth=0) {&lt;br /&gt;        &lt;span class="kwrd"&gt;while&lt;/span&gt; (imagesWidth &amp;lt; widthPerRow &amp;amp;&amp;amp; j &amp;lt; subImages.Count) {&lt;br /&gt;            rows[i].AddImage(subImages[j]);&lt;br /&gt;            subImages[j].RowNum = i;&lt;br /&gt;            imagesWidth += subImages[j++].Width;&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    &lt;span class="rem"&gt;// At this point in time the subimage height is 1 &lt;/span&gt;&lt;br /&gt;    &lt;span class="rem"&gt;// If we assume that the total height is also 1 we need to scale the subimages to fit within a total height of 1&lt;/span&gt;&lt;br /&gt;    &lt;span class="rem"&gt;// If the total height is 1, the total width is aspectRatio. Hence (aspectRatio)/(total width of all images in a row) is the scaling factor.&lt;/span&gt;&lt;br /&gt;    &lt;span class="rem"&gt;// Added later: take into account spacing between images&lt;/span&gt;&lt;br /&gt;    rows.ForEach(Row =&amp;gt; Row.Scale(containerAspectRatio));&lt;br /&gt;&lt;br /&gt;    &lt;span class="rem"&gt;// Calculate the total height, with space between images, of the images across all rows&lt;/span&gt;&lt;br /&gt;    &lt;span class="rem"&gt;// Also adjust the colNum for each image&lt;/span&gt;&lt;br /&gt;    &lt;span class="kwrd"&gt;double&lt;/span&gt; totalImagesHeight = (numRows - 1) * spaceBetweenImages;&lt;br /&gt;    rows.ForEach(Row =&amp;gt; totalImagesHeight += Row.Height);&lt;br /&gt;&lt;br /&gt;    &lt;span class="rem"&gt;// The totalImagesHeight should not exceed 1. &lt;/span&gt;&lt;br /&gt;    &lt;span class="rem"&gt;// if it does, we need to scale all images by a factor of (1 / totalImagesHeight)&lt;/span&gt;&lt;br /&gt;    &lt;span class="asp"&gt;&lt;span class="kwrd"&gt;if&lt;/span&gt; (((_displayMode == DisplayMode.Thumbnails &amp;amp;&amp;amp; totalImagesHeight &amp;gt; 1)) || _displayMode == DisplayMode.Full)&lt;/span&gt; {&lt;br /&gt;        subImages.ForEach(subImage =&amp;gt; subImage.Scale(1 / (totalImagesHeight+spaceBetweenImages)));&lt;br /&gt;        totalImagesHeight = (numRows - 1) * spaceBetweenImages;&lt;br /&gt;        rows.ForEach(Row =&amp;gt; totalImagesHeight += Row.Height);&lt;br /&gt;        Debug.Assert(totalImagesHeight &amp;lt;= 1);&lt;br /&gt;    }&lt;br /&gt;    &lt;br /&gt;    &lt;span class="rem"&gt;// Calculate the top and bottom margin&lt;/span&gt;&lt;br /&gt;    &lt;span class="kwrd"&gt;double&lt;/span&gt; margin = (1 - totalImagesHeight) / 2;&lt;br /&gt;&lt;br /&gt;    &lt;span class="rem"&gt;// First hide all the images that should not be displayed&lt;/span&gt;&lt;br /&gt;    _imagesToHide.ForEach(subImage =&amp;gt; subImage.Opacity = 0.0);&lt;br /&gt;&lt;br /&gt;    &lt;span class="rem"&gt;// Then display the displayable images to scale&lt;/span&gt;&lt;br /&gt;    &lt;span class="kwrd"&gt;for&lt;/span&gt; (&lt;span class="kwrd"&gt;int&lt;/span&gt; i=0; i&amp;lt;_imagesToShow.Count; i++) {&lt;br /&gt;        &lt;span class="kwrd"&gt;double&lt;/span&gt; X = rows[subImages[i].RowNum].CalcX(subImages[i].ColNum);&lt;br /&gt;        &lt;span class="kwrd"&gt;double&lt;/span&gt; Y = margin;&lt;br /&gt;        &lt;span class="kwrd"&gt;for&lt;/span&gt; (&lt;span class="kwrd"&gt;int&lt;/span&gt; j=0; j&amp;lt;subImages[i].RowNum; j++)&lt;br /&gt;            Y += spaceBetweenImages + rows[j].Height;&lt;br /&gt;        &lt;br /&gt;        _imagesToShow[i].ViewportWidth = containerAspectRatio / subImages[i].Width;&lt;br /&gt;        AnimateImage(_imagesToShow[i], &lt;span class="kwrd"&gt;new&lt;/span&gt; Point(-(X / subImages[i].Width), -(Y / subImages[i].Width)));    &lt;span class="rem"&gt;// for animation, use this statement instead of the next one&lt;/span&gt;&lt;br /&gt;        _imagesToShow[i].Opacity = 1.0;&lt;br /&gt;    }&lt;br /&gt;    &lt;span class="rem"&gt;// Play Storyboard&lt;/span&gt;&lt;br /&gt;    _moveStoryboard.Begin();&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7411255283791998153-2726121751997640199?l=projectsilverlight.blogspot.com'/&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/ProjectSilverlight/~4/VoWCXzxqUaw" height="1" width="1"/&gt;</description><link>http://projectsilverlight.blogspot.com/2008/07/deep-zoom-rendering-in-2-different.html</link><author>noreply@blogger.com (Wilfred Pinto)</author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">2</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-7411255283791998153.post-6381134248657691323</guid><pubDate>Thu, 03 Jul 2008 21:43:00 +0000</pubDate><atom:updated>2008-10-14T22:05:33.152-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Deep Zoom</category><category domain="http://www.blogger.com/atom/ns#">Silverlight</category><title>I'm honored!</title><description>I just noticed that my blog is referenced in the MSDN Silverlight Beta 2 documentation, specifically &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.multiscaleimage(VS.95).aspx"&gt;http://msdn.microsoft.com/en-us/library/system.windows.controls.multiscaleimage(VS.95).aspx&lt;/a&gt;  (search for &lt;span style="font-style:italic;"&gt;Filter Example&lt;/span&gt;). This is definitely an honor!&lt;br /&gt;&lt;br /&gt;Does this mean that I can now ask Microsoft for a free copy of Visual Studio 2008? Just kidding :) I am currently working on a Silverlight project so I have access to VS2008. I still use Notepad++ on my laptop though, since it is underpowered for VS.&lt;br /&gt;&lt;br /&gt;I finally got around to uploading the source code for the DeepZoom sample. You will find the link to the code in this post - &lt;a href="http://projectsilverlight.blogspot.com/2008/06/deepzoom-sample-ported-to-silverlight-2.html"&gt;DeepZoom sample ported to Silverlight 2 Beta 2&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7411255283791998153-6381134248657691323?l=projectsilverlight.blogspot.com'/&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/ProjectSilverlight/~4/SUd7l8I3eZo" height="1" width="1"/&gt;</description><link>http://projectsilverlight.blogspot.com/2008/07/im-honored.html</link><author>noreply@blogger.com (Wilfred Pinto)</author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-7411255283791998153.post-8604329159386950716</guid><pubDate>Wed, 02 Jul 2008 04:35:00 +0000</pubDate><atom:updated>2008-07-01T21:49:23.285-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Deep Zoom</category><category domain="http://www.blogger.com/atom/ns#">Silverlight</category><title>Deep Zoom Composer source code</title><description>Not really...but pretty close! Check out Berend's article on CodeProject - &lt;br /&gt;&lt;a href="http://www.codeproject.com/KB/silverlight/DecosDeepZoom.aspx"&gt;Generate Silverlight 2 DeepZoom image collection from multi-page tiff&lt;/a&gt; &lt;br /&gt;&lt;br /&gt;I haven't tried it myself so I don't know if it works, but it definitely opens up a lot of possibilities - Dynamic gallery generation; Adding images to collection without regenerating all the tiles...&lt;br /&gt;&lt;br /&gt;If only Microsoft would open source the DeepZoom Composer code, or at least the image/tile generation part! &lt;br /&gt;&lt;br /&gt;Great work, Berend Engelbrecht!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7411255283791998153-8604329159386950716?l=projectsilverlight.blogspot.com'/&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/ProjectSilverlight/~4/_eqtwzSiHlc" height="1" width="1"/&gt;</description><link>http://projectsilverlight.blogspot.com/2008/07/deep-zoom-composer-source-code.html</link><author>noreply@blogger.com (Wilfred Pinto)</author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-7411255283791998153.post-516697731428129705</guid><pubDate>Mon, 30 Jun 2008 18:43:00 +0000</pubDate><atom:updated>2008-06-30T11:49:42.462-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">SimpleViewer</category><category domain="http://www.blogger.com/atom/ns#">Silverlight</category><category domain="http://www.blogger.com/atom/ns#">Beta2</category><title>SimpleViewer-SL ported to Silverlight 2 Beta 2</title><description>SimpleViewer-SL now works on Beta 2 as well. I updated the inline samples in the previous posts so folks with Beta 2 should be able to view all the sample galleries that I created using SimpleViewer-SL.&lt;br /&gt;&lt;br /&gt;If you recollect from my earlier post, I did not use the ScrollViewer control since I wanted to keep the .xap package as small as possible. This is no longer the case since ScrollViewer is now part of the Silverlight framework itself. I still haven't updated the code to take advantage of this but might do so at a later date.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7411255283791998153-516697731428129705?l=projectsilverlight.blogspot.com'/&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/ProjectSilverlight/~4/2m3rsj6EzTU" height="1" width="1"/&gt;</description><link>http://projectsilverlight.blogspot.com/2008/06/simpleviewer-sl-ported-to-silverlight-2.html</link><author>noreply@blogger.com (Wilfred Pinto)</author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-7411255283791998153.post-6956983266703238180</guid><pubDate>Sun, 29 Jun 2008 22:28:00 +0000</pubDate><atom:updated>2008-07-03T14:59:24.451-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Deep Zoom</category><category domain="http://www.blogger.com/atom/ns#">Silverlight</category><category domain="http://www.blogger.com/atom/ns#">Beta2</category><title>DeepZoom sample ported to Silverlight 2 Beta 2</title><description>I have been planning to do this for some time now but finally managed to squeeze some time for this activity. I am going to leave the previous posts as-is so that the folks with Beta 1 can look at the previous sample.&lt;br /&gt;&lt;br /&gt;&lt;p align="center"&gt; &lt;iframe id="I1" border="0" marginheight="0" marginwidth="0" name="I1" src="http://thepintospatronus.com/deepzoom/ClientBin/DeepZoomOutput.html" style="width: 389px; height: 309px;" frameborder="0" scrolling="no"&gt; Your browser does not support inline frames or is currently configured not to display inline frames. &lt;/iframe&gt; &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;It was a relatively straightforward exercise but one thing I noticed is that msi.Width/Height doesn't work properly in Beta 2, but luckily msi.ActualWidth/ActualHeight works! I also used the new tagging format (Metadata.xml) that the latest DeepZoom Composer generates.&lt;br /&gt;&lt;br /&gt;&lt;s&gt;I will post the source code in the next post.&lt;/s&gt;&lt;br /&gt;The source code has been uploaded and can be found &lt;a href="http://thepintospatronus.com/deepzoom/DeepZoomOutput-Beta2.zip"&gt;here&lt;/a&gt;. Note that the disclaimer from this &lt;a href="http://projectsilverlight.blogspot.com/2008/04/dissecting-hard-rock-memorabilia-part-9.html"&gt;post &lt;/a&gt;still holds!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7411255283791998153-6956983266703238180?l=projectsilverlight.blogspot.com'/&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/ProjectSilverlight/~4/cxS7w1ACPGM" height="1" width="1"/&gt;</description><link>http://projectsilverlight.blogspot.com/2008/06/deepzoom-sample-ported-to-silverlight-2.html</link><author>noreply@blogger.com (Wilfred Pinto)</author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">12</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-7411255283791998153.post-9152203555288161848</guid><pubDate>Tue, 13 May 2008 00:29:00 +0000</pubDate><atom:updated>2008-05-12T18:06:55.555-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">SimpleViewer</category><category domain="http://www.blogger.com/atom/ns#">Tips</category><category domain="http://www.blogger.com/atom/ns#">Silverlight</category><title>Scrolling, without using ScrollViewer!</title><description>The main objective when building SimpleViewer-SL was to keep the executable as small as possible and hence I didn't have the option of using ScrollViewer. I still needed scrolling functionality though and hence had to take &lt;span style="font-style: italic;"&gt;some&lt;/span&gt; alternate approach. This post is a result of my findings. There is possibly no reason for anyone to take this approach, unless there is a compelling reason to not use ScrollViewer, but it might prove useful!&lt;br /&gt;&lt;br /&gt;So how did I go about implementing scrolling? The trick is to contain the visible area and use TranslateTransform.&lt;br /&gt;&lt;br /&gt;Let's look at the Xaml first&lt;br /&gt;&lt;pre&gt;&lt;code&gt;&amp;lt;UserControl x:Class="SimpleViewer_SL.Thumbnails"&lt;br /&gt; xmlns="http://schemas.microsoft.com/client/2007"&lt;br /&gt; xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"&amp;gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;&amp;lt;Grid x:Name="LayoutRoot" HorizontalAlignment="Center" VerticalAlignment="Center"&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;&amp;lt;Grid x:Name="LayoutThumbnailsViewport" HorizontalAlignment="Left"&amp;gt;&lt;/span&gt;&lt;br /&gt; &lt;span style="font-weight: bold;"&gt;&amp;lt;Grid x:Name="LayoutThumbnails" HorizontalAlignment="Left"&amp;gt;&lt;/span&gt;&lt;br /&gt;  &amp;lt;Grid.RenderTransform&amp;gt;&lt;br /&gt;   &lt;span style="font-weight: bold;"&gt;&amp;lt;TranslateTransform x:Name="GridTranslate" /&amp;gt;&lt;/span&gt;&lt;br /&gt;  &amp;lt;/Grid.RenderTransform&amp;gt;&lt;br /&gt;  &amp;lt;Grid.Resources&amp;gt;&lt;br /&gt;     &lt;span style="font-weight: bold;"&gt;&amp;lt;Storyboard x:Name="GridScrollStoryboard"&amp;gt;&lt;/span&gt;&lt;br /&gt;     &amp;lt;DoubleAnimation x:Name="GridScrollAnimation" Storyboard.TargetName="GridTranslate" Storyboard.TargetProperty="X" Duration="00:00:00.5"/&amp;gt;&lt;br /&gt;     &amp;lt;/Storyboard&amp;gt;&lt;br /&gt;  &amp;lt;/Grid.Resources&amp;gt;&lt;br /&gt; &amp;lt;/Grid&amp;gt;&lt;br /&gt;&amp;lt;/Grid&amp;gt;&lt;br /&gt;&amp;lt;Canvas x:Name="RightNav" Height="25" Width="30" Background="Transparent" HorizontalAlignment="Right"&amp;gt;&lt;br /&gt; &amp;lt;Path Height="25" Width="30" Stretch="Fill"&lt;br /&gt;  Data="F1 M 0,50L 130,50L 80,0L 130,0L 200,70L 130,140L 80,140L 130,90L 0,90L 0,50 Z"&amp;gt;&lt;br /&gt; &amp;lt;/Path&amp;gt;&lt;br /&gt;&amp;lt;/Canvas&amp;gt;&lt;br /&gt;&amp;lt;Canvas x:Name="LeftNav" Height="25" Width="30" Background="Transparent" HorizontalAlignment="Left"&amp;gt;&lt;br /&gt; &amp;lt;Path Height="25" Width="30" Stretch="Fill"&lt;br /&gt;  Data="F1 M 200,90L 70,90L 120,140L 70,140L 0,70L 70,0L 120,0L 70,50L 200,50L 200,90 Z"&amp;gt;&lt;br /&gt; &amp;lt;/Path&amp;gt;&lt;br /&gt;&amp;lt;/Canvas&amp;gt;&lt;br /&gt;&amp;lt;/Grid&amp;gt;&lt;br /&gt;&amp;lt;/UserControl&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;What we are trying to do here is display the thumbnails in a grid, but, as you can see from the above Xaml, I have had to create 3 grids to implement scrolling.&lt;br /&gt;&lt;ul&gt;&lt;li&gt;LayoutThumbnails - This is the grid which will host the thumbnails&lt;/li&gt;&lt;li&gt;LayoutThumbnailsViewport - This is the grid which will host the translated thumbnails&lt;/li&gt;&lt;li&gt;LayoutRoot - This is the grid which will host the clipped thumbnails&lt;br /&gt;&lt;/li&gt;&lt;/ul&gt;&lt;ul&gt;&lt;li&gt;GridTranslate - This exposes the translate transform of LayoutThumbnails&lt;/li&gt;&lt;li&gt;GridScrollStoryboard - This is the storyboard that animates GridTranslate to simulate (horizontal) scrolling&lt;/li&gt;&lt;/ul&gt;Now for some code&lt;br /&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;partial&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; Thumbnails : UserControl&lt;br /&gt;{&lt;br /&gt; Page _parent = &lt;span class="kwrd"&gt;null&lt;/span&gt;;&lt;br /&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt; _borderWidth = 2;&lt;br /&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt; _selectedThumbnailIndex = -1;&lt;br /&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt; _rowCount = 0;&lt;br /&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt; _colCount = 0;&lt;br /&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt; _totalColCount = 0;&lt;br /&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt; _numPages = 0;&lt;br /&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt; _currPage = 0;&lt;br /&gt; Size _thumbSize = &lt;span class="kwrd"&gt;new&lt;/span&gt; Size { Width = 65, Height = 65 };&lt;br /&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt; _borderPlusPaddingWidth = 0;&lt;br /&gt;&lt;br /&gt; &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;double&lt;/span&gt; ControlWidth { get { &lt;span class="kwrd"&gt;return&lt;/span&gt; (_thumbSize.Width + (_borderPlusPaddingWidth * 2)) * _colCount; }}&lt;br /&gt;&lt;br /&gt; &lt;span class="kwrd"&gt;public&lt;/span&gt; Thumbnails(Page parent)&lt;br /&gt; {&lt;br /&gt;     _parent = parent;&lt;br /&gt;     _rowCount = _parent.Settings.ThumbnailRows;&lt;br /&gt;     _colCount = _parent.Settings.ThumbnailColumns;&lt;br /&gt;     _totalColCount = (&lt;span class="kwrd"&gt;int&lt;/span&gt;)(Math.Ceiling((&lt;span class="kwrd"&gt;double&lt;/span&gt;)_parent.Settings.ImagesSettings.Count / _rowCount));&lt;br /&gt;     _numPages = (&lt;span class="kwrd"&gt;int&lt;/span&gt;)(Math.Ceiling((&lt;span class="kwrd"&gt;double&lt;/span&gt;)_totalColCount / _colCount));&lt;br /&gt;     _borderPlusPaddingWidth = _parent.Settings.ThumbPadding + _borderWidth;&lt;br /&gt;&lt;br /&gt;     InitializeComponent();&lt;br /&gt;  &lt;br /&gt;     &lt;span class="asp"&gt;LayoutRoot.Width = ControlWidth; // ****1****&lt;/span&gt;&lt;br /&gt;     &lt;span class="asp"&gt;LayoutThumbnailsViewport.Width = ControlWidth * _numPages; // ****2****&lt;/span&gt;&lt;br /&gt;  &lt;br /&gt;     CreateLayout();&lt;br /&gt;     DrawThumbnails();&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt; CreateLayout() {&lt;br /&gt;     &lt;span class="rem"&gt;// Thumbnails &lt;/span&gt;&lt;br /&gt;     LayoutRoot.RowDefinitions.Add(&lt;span class="kwrd"&gt;new&lt;/span&gt; RowDefinition());&lt;br /&gt;     LayoutThumbnailsViewport.SetValue(Grid.RowProperty, 0);&lt;br /&gt;  &lt;br /&gt;     &lt;span class="kwrd"&gt;if&lt;/span&gt; (_numPages &amp;gt; 0) {&lt;br /&gt;         &lt;span class="rem"&gt;// Navigation Arrows&lt;/span&gt;&lt;br /&gt;         LayoutRoot.RowDefinitions.Add(&lt;span class="kwrd"&gt;new&lt;/span&gt; RowDefinition { Height = &lt;span class="kwrd"&gt;new&lt;/span&gt; GridLength(30) });&lt;br /&gt;         RightNav.SetValue(Grid.RowProperty, 1);&lt;br /&gt;         LeftNav.SetValue(Grid.RowProperty, 1);&lt;br /&gt;     }&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; DrawThumbnails()&lt;br /&gt; {&lt;br /&gt;     &lt;span class="kwrd"&gt;for&lt;/span&gt; (&lt;span class="kwrd"&gt;int&lt;/span&gt; row = 0; row &amp;lt; _rowCount; row++) {&lt;br /&gt;         LayoutThumbnails.RowDefinitions.Add(&lt;span class="kwrd"&gt;new&lt;/span&gt; RowDefinition { Height = &lt;span class="kwrd"&gt;new&lt;/span&gt; GridLength(_thumbSize.Height + (_borderPlusPaddingWidth * 2)) });&lt;br /&gt;     }&lt;br /&gt;  &lt;br /&gt;     &lt;span class="kwrd"&gt;for&lt;/span&gt; (&lt;span class="kwrd"&gt;int&lt;/span&gt; col = 0; col &amp;lt; _colCount * _numPages; col++) {&lt;br /&gt;         LayoutThumbnails.ColumnDefinitions.Add(&lt;span class="kwrd"&gt;new&lt;/span&gt; ColumnDefinition { Width = &lt;span class="kwrd"&gt;new&lt;/span&gt; GridLength(_thumbSize.Width + (_borderPlusPaddingWidth * 2)) });&lt;br /&gt;     }&lt;br /&gt;  &lt;br /&gt;     &lt;span class="kwrd"&gt;int&lt;/span&gt; imageIndex = 0;&lt;br /&gt;     &lt;span class="kwrd"&gt;int&lt;/span&gt; startCol = 0;&lt;br /&gt;     &lt;span class="kwrd"&gt;for&lt;/span&gt; (&lt;span class="kwrd"&gt;int&lt;/span&gt; page = 0; page &amp;lt; _numPages; page++) {&lt;br /&gt;         &lt;span class="kwrd"&gt;for&lt;/span&gt; (&lt;span class="kwrd"&gt;int&lt;/span&gt; row = 0; row &amp;lt; _rowCount; row++) {&lt;br /&gt;             &lt;span class="kwrd"&gt;for&lt;/span&gt; (&lt;span class="kwrd"&gt;int&lt;/span&gt; col = 0; col &amp;lt; _colCount &amp;amp;&amp;amp; imageIndex &amp;lt; _parent.Settings.ImagesSettings.Count; col++) {&lt;br /&gt;                 CreateImage(row, col + startCol, imageIndex);&lt;br /&gt;                 imageIndex++;&lt;br /&gt;             }&lt;br /&gt;         }&lt;br /&gt;         startCol += _colCount;&lt;br /&gt;     }&lt;br /&gt;  &lt;br /&gt;     LeftNav.MouseLeftButtonUp += (sender, e) =&amp;gt; {&lt;br /&gt;         ScrollLeft();&lt;br /&gt;     };&lt;br /&gt;  &lt;br /&gt;     RightNav.MouseLeftButtonUp += (sender, e) =&amp;gt; {&lt;br /&gt;         ScrollRight();&lt;br /&gt;     };&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; CreateImage(&lt;span class="kwrd"&gt;int&lt;/span&gt; row, &lt;span class="kwrd"&gt;int&lt;/span&gt; col, &lt;span class="kwrd"&gt;int&lt;/span&gt; imageIndex)&lt;br /&gt; {&lt;br /&gt;     Image thumb = &lt;span class="kwrd"&gt;new&lt;/span&gt; Image();&lt;br /&gt;     thumb.Source = &lt;span class="kwrd"&gt;new&lt;/span&gt; BitmapImage(&lt;span class="kwrd"&gt;new&lt;/span&gt; Uri(_parent.Settings.ThumbPath + _parent.Settings.ImagesSettings[imageIndex].Name, UriKind.Relative));&lt;br /&gt;&lt;br /&gt;     Border border = &lt;span class="kwrd"&gt;new&lt;/span&gt; Border {&lt;br /&gt;                         Width = _thumbSize.Width + (_borderWidth*2),&lt;br /&gt;                         Height = _thumbSize.Height + (_borderWidth*2),&lt;br /&gt;                         BorderThickness = &lt;span class="kwrd"&gt;new&lt;/span&gt; Thickness(_borderWidth),&lt;br /&gt;                         BorderBrush = &lt;span class="kwrd"&gt;new&lt;/span&gt; SolidColorBrush(_parent.Settings.FrameColor),&lt;br /&gt;                         Margin = &lt;span class="kwrd"&gt;new&lt;/span&gt; Thickness(_parent.Settings.ThumbPadding),&lt;br /&gt;                         Opacity = 0.6&lt;br /&gt;                                 };&lt;br /&gt;     border.SetValue(Grid.RowProperty, row);&lt;br /&gt;     border.SetValue(Grid.ColumnProperty, col);&lt;br /&gt;     border.SetValue(NameProperty, &lt;span class="str"&gt;"Image"&lt;/span&gt; + imageIndex.ToString());&lt;br /&gt;     border.Tag = imageIndex.ToString();            &lt;span class="rem"&gt;// Tag can only handle Strings as of SL2 B1 release&lt;/span&gt;&lt;br /&gt;  &lt;br /&gt;     border.Child = thumb;&lt;br /&gt;     LayoutThumbnails.Children.Add(border);&lt;br /&gt;  &lt;br /&gt;     border.MouseLeftButtonUp += (sender, e) =&amp;gt; {&lt;br /&gt;         Rect LayoutRootRect = &lt;span class="kwrd"&gt;new&lt;/span&gt; Rect(0, 0, LayoutRoot.RenderSize.Width, LayoutRoot.RenderSize.Height);&lt;br /&gt;         &lt;span class="asp"&gt;&lt;span class="kwrd"&gt;if&lt;/span&gt; (LayoutRootRect.Contains(e.GetPosition(LayoutRoot))) { // ****3****&lt;/span&gt;&lt;br /&gt;             Border currentBorder = (Border)sender;&lt;br /&gt;             SelectedThumbnailIndex = Int32.Parse((&lt;span class="kwrd"&gt;string&lt;/span&gt;)currentBorder.Tag);&lt;br /&gt;         }&lt;br /&gt;     };&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; &lt;span class="kwrd"&gt;bool&lt;/span&gt; CanScrollRight    { get { &lt;span class="kwrd"&gt;return&lt;/span&gt; ((_currPage + 1) &amp;lt; _numPages); }}&lt;br /&gt; &lt;span class="kwrd"&gt;bool&lt;/span&gt; CanScrollLeft    { get { &lt;span class="kwrd"&gt;return&lt;/span&gt; (_currPage &amp;gt; 0); }}&lt;br /&gt;&lt;br /&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; ScrollRight()&lt;br /&gt; {&lt;br /&gt;     &lt;span class="kwrd"&gt;if&lt;/span&gt; (CanScrollRight) {&lt;br /&gt;         _currPage++;&lt;br /&gt;         GridScrollAnimation.To = -(_thumbSize.Width + (_borderPlusPaddingWidth * 2)) * _colCount * _currPage;&lt;br /&gt;         GridScrollStoryboard.Begin();&lt;br /&gt;     }&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; ScrollLeft()&lt;br /&gt; {&lt;br /&gt;     &lt;span class="kwrd"&gt;if&lt;/span&gt; (CanScrollLeft) {&lt;br /&gt;         _currPage--;&lt;br /&gt;         GridScrollAnimation.To = -(_thumbSize.Width + (_borderPlusPaddingWidth * 2)) * _colCount * _currPage;&lt;br /&gt;         GridScrollStoryboard.Begin();&lt;br /&gt;     }&lt;br /&gt; }&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;Most of the code is self explanatory but I would like to elaborate on a few key points which is highlighted in the code:&lt;br /&gt;&lt;ol&gt;&lt;li&gt;The width of LayoutThumbnailsViewport should be equal to or greater than the width of the entire grid. If the width is not explicitly set or is less than the width of the entire grid, translatetransform will clip the contents that lie outside the area of the grid&lt;/li&gt;&lt;li&gt;The width of LayoutRoot should be set to the viewing area. This should be less than the width of LayoutThumbnailsViewport if scrolling is desired&lt;/li&gt;&lt;li&gt;One undesired effect of creating this layout is that the underlying grid (LayoutThumbnails) and hence the thumbnails receive mouse events even for the contents that is outside the visible area (LayoutRoot). To circumvent this I had to put this check - if (LayoutRootRect.Contains(e.GetPosition(LayoutRoot))) - in the border.MouseLeftButtonUp event handler. &lt;span style="font-style:italic;"&gt;(Note that border is synonymous with thumbnail)&lt;/span&gt;&lt;/li&gt;&lt;/ol&gt;&lt;br /&gt;&lt;iframe src="http://thepintospatronus.com/simpleviewer-sl/gallery2/gallery1.html" height="200" width="260"&gt;&lt;/iframe&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7411255283791998153-9152203555288161848?l=projectsilverlight.blogspot.com'/&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/ProjectSilverlight/~4/HO-56IGddAM" height="1" width="1"/&gt;</description><link>http://projectsilverlight.blogspot.com/2008/05/scrolling-without-using-scrollviewer.html</link><author>noreply@blogger.com (Wilfred Pinto)</author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-7411255283791998153.post-3516544117505498601</guid><pubDate>Mon, 05 May 2008 04:45:00 +0000</pubDate><atom:updated>2008-05-08T17:38:36.753-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">SimpleViewer</category><category domain="http://www.blogger.com/atom/ns#">Silverlight</category><title>SimpleViewer-SL Beta 1</title><description>&lt;span style="font-style: italic;"&gt;Update 5/8/08: Fixed blank screen bug when navigating between thumbnails, and improved browser resizing support...&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The Silverlight version of the flash based photo album viewer - &lt;a href="http://www.airtightinteractive.com/simpleviewer/"&gt;SimpleViewer&lt;/a&gt;, is here! I decided to call it &lt;span style="font-weight: bold;"&gt;SimpleViewer-SL&lt;/span&gt; for now.&lt;br /&gt;&lt;br /&gt;Here are a few examples that were created using SimpleViewer-SL &lt;span style="font-style: italic;"&gt;(the keyboard arrow keys are supported as well)&lt;/span&gt;&lt;ol&gt;&lt;li&gt;&lt;a href="http://thepintospatronus.com/simpleviewer-sl/gallery1/gallery1.html" target="_blank"&gt;Thumbnails on the left, 3x3 grid&lt;/a&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;a href="http://thepintospatronus.com/simpleviewer-sl/gallery1/gallery2.html" target="_blank"&gt;Thumbnails on the right, 5x4 grid&lt;/a&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;a href="http://thepintospatronus.com/simpleviewer-sl/gallery1/gallery3.html" target="_blank"&gt;Thumbnails on bottom, 2x4 grid&lt;/a&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;a href="http://thepintospatronus.com/simpleviewer-sl/gallery1/gallery4.html" target="_blank"&gt;Thumbnails on the left, with background image&lt;/a&gt;&lt;/li&gt;&lt;/ol&gt;&lt;br /&gt;SimpleViewer-SL is highly customizable. It is compatible with SimpleViewer and hence all options exposed by SimpleViewer are applicable to SimpleViewer-SL as well. The options are listed &lt;a href="http://www.airtightinteractive.com/simpleviewer/options.html"&gt;here&lt;/a&gt;. The only XML option that is not supported at this time is enableRightClickOpen. &lt;span style="font-style: italic;"&gt;Note that the text fields like title and Caption should be plain text (no HTML) for now since I haven't implemented the HTML text control as yet.&lt;/span&gt; As for the HTML options, the only supported option is xmlDataPath. The HTML option should be passed to the SimpleViewer-SL Silverlight object using the param tag - &lt;span style="font-style: italic;"&gt;&amp;lt;param name="initParams" value="xmlDataPath=gallery1.xml" /&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The album can be created using any of the methods described &lt;a href="http://www.airtightinteractive.com/simpleviewer/auto_desktop_instruct.html"&gt;here&lt;/a&gt; . After creating the albums, a few modifications to the generated file(s) is required to make it work on SimpleViewer-SL.&lt;br /&gt;&lt;br /&gt;The xap can be found &lt;a href="http://thepintospatronus.com/simpleviewer-sl/gallery1/SimpleViewer-SL.xap"&gt;here&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;The directory structure for the samples is as follows:&lt;pre&gt;&lt;br /&gt; gallery1/&lt;br /&gt;   SimpleViewer-SL.xap&lt;br /&gt;   gallery1.html&lt;br /&gt;   gallery1.xml&lt;br /&gt;   gallery2.html&lt;br /&gt;   gallery2.xml&lt;br /&gt;   gallery3.html&lt;br /&gt;   gallery3.xml&lt;br /&gt;   gallery4.html&lt;br /&gt;   gallery4.xml&lt;br /&gt;   thumbs/&lt;br /&gt;     65x65 thumbnail images&lt;br /&gt;   images/&lt;br /&gt;     the corresponding big images&lt;/pre&gt;&lt;br /&gt;Between the above links, the sample html and xml files, it should be fairly straightforward for anyone to figure out how to use SimpleViewer-SL. Overall it is fairly feature complete but there is always room for improvement. &lt;s&gt;It is a little unstable, in that sometime navigating between thumbnails results in a blank screen, but I think it is more to do with Silverlight being a Beta release&lt;/s&gt; &lt;span style="font-style: italic;"&gt;(looks like it was more to do with my code!)&lt;/span&gt;.&lt;br /&gt;&lt;br /&gt;This exercise took me a little over a week of part time work so I have to say that I am pretty impressed with Silverlight. Most of my time was spent in figuring out a way to work around Silverlight 2 Beta 1 bugs. I suspect that I can simplify the code a bit after the final release of Siverlight 2. Nevertheless, the current size of SimpleViewer-SL is a mere 17kb, the same as SimpleViewer, with lots of opportunity for improvement.&lt;br /&gt;&lt;br /&gt;For those looking for the code, I am planning to codeplex it when I get some time. Feel free to leave comments to pressure me into doing it sooner rather than later!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7411255283791998153-3516544117505498601?l=projectsilverlight.blogspot.com'/&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/ProjectSilverlight/~4/7S9rzOdzbgk" height="1" width="1"/&gt;</description><link>http://projectsilverlight.blogspot.com/2008/05/simpleviewer-sl-beta-1.html</link><author>noreply@blogger.com (Wilfred Pinto)</author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">7</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-7411255283791998153.post-6912606822183959983</guid><pubDate>Sun, 04 May 2008 18:44:00 +0000</pubDate><atom:updated>2008-05-04T13:24:02.019-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Deep Zoom</category><category domain="http://www.blogger.com/atom/ns#">Silverlight</category><title>Deep Zoom Composer Updated!</title><description>A nice update to Deep Zoom Composer can be found here - &lt;a href="http://blogs.msdn.com/expression/archive/2008/05/03/an-update-to-deep-zoom-composer.aspx"&gt;http://blogs.msdn.com/expression/archive/2008/05/03/an-update-to-deep-zoom-composer.aspx&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;The new update includes: improved exporting (includes mousewheel, pan, zoom, and keyboard functionality), better design experience, collection export bug fix, and greater access to help.&lt;br /&gt;&lt;br /&gt;Nice!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7411255283791998153-6912606822183959983?l=projectsilverlight.blogspot.com'/&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/ProjectSilverlight/~4/xHkxbGDdgvg" height="1" width="1"/&gt;</description><link>http://projectsilverlight.blogspot.com/2008/05/deep-zoom-composer-updated.html</link><author>noreply@blogger.com (Wilfred Pinto)</author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-7411255283791998153.post-5646375427464037190</guid><pubDate>Fri, 25 Apr 2008 18:09:00 +0000</pubDate><atom:updated>2008-04-25T11:41:47.066-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">SimpleViewer</category><category domain="http://www.blogger.com/atom/ns#">Silverlight</category><title>Next Project - Port SimpleViewer to Silverlight</title><description>Having run out of ideas on how further to exploit Deep Zoom, I am going to now focus my energy on porting the closed-source flash based &lt;a href="http://www.airtightinteractive.com/simpleviewer/"&gt;SimpleViewer&lt;/a&gt; to Silverlight. Again, my objective is to learn Silverlight, so I will try to push some boundaries (&lt;span style="font-style:italic;"&gt;if required&lt;/span&gt;). As part of this exercise, I will try to stick to the original goal of SimpleViewer, that is keep the download as small as possible. The current version (1.8.5) of SimpleViewer is only 17k and that is what I am aiming for. This, of course, means no using the extended controls, but only what is available in the core Silverlight 2 SDK!&lt;br /&gt;&lt;br /&gt;So, why SimpleViewer? I actually use it in my personal blog and have always wanted more control over it. I also want to know what it takes to create the same experience in Silverlight. I am expecting this to be a trivial exercise, but let's see!&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style:italic;"&gt;My first roadblock!&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;I wanted to keep everything as dynamic as possible. This means no explicitly specifying the height and width of any control. I was happy to see that the image control provides this capability and is able to work well within the constraints of MaxWidth and MaxHeight. This was all wonderful and perfect for my needs but now I wanted to draw a simple border around the image. Pretty easy...all I need is the dimensions of the image (control), but this is where it got a little complicated. The image control does give access to the dimensions but a little too late. I won't go into the details here but I did post it on the &lt;a href="http://silverlight.net/forums/t/14855.aspx"&gt;Silverlight.net&lt;/a&gt; forum is anyone's interested. By the way this is a great forum and one of the best places to get answers to all your Silverlight questions or issues.&lt;br /&gt;&lt;br /&gt;What I discovered is that the image loaded event is not a reliable place to extract the dimensions from the image control. I tried a kludgey workaround by creating a timer and accessing the dimensions from the image control a little later - around 100 milli seconds - but this is definitely not reliable. But at least I had a solution!&lt;br /&gt;&lt;br /&gt;While I was playing with it some more, I discovered the SizeChanged event. This also doesn't help if the image dimensions are extracted from the image control itself, but I discovered that the event itself has the size, and that is when I had my solution! &lt;br /&gt;&lt;br /&gt;There might be some issues with this so please leave a comment if you find something. I am assuming this is a bug with the image loaded event so, hopefully, it will be fixed in the next release of Silverlight. &lt;span style="font-style:italic;"&gt;But, for now, it looks like I can make some "not so kludgey" progress!&lt;/span&gt;&lt;br /&gt;&lt;pre class="csharpcode"&gt;&lt;br /&gt;MyImage.SizeChanged += (sender, e) =&amp;gt; {&lt;br /&gt;    &lt;span class="kwrd"&gt;if&lt;/span&gt; (e.PreviousSize.Width == 0 &amp;amp;&amp;amp; e.PreviousSize.Height == 0 &amp;amp;&amp;amp; e.NewSize != e.PreviousSize) {&lt;br /&gt;        &lt;span class="rem"&gt;// e.NewSize contains the dimension of the image&lt;/span&gt;&lt;br /&gt;        &lt;span class="rem"&gt;// MyImage.Width and MyImage.ActualWidth is unreliable so use e.NewSize instead&lt;/span&gt;&lt;br /&gt;        DrawBorderAroundImage(e.NewSize);&lt;br /&gt;    }&lt;br /&gt;};&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7411255283791998153-5646375427464037190?l=projectsilverlight.blogspot.com'/&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/ProjectSilverlight/~4/PonaVLOrxos" height="1" width="1"/&gt;</description><link>http://projectsilverlight.blogspot.com/2008/04/next-project-port-simpleviewer-to.html</link><author>noreply@blogger.com (Wilfred Pinto)</author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">4</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-7411255283791998153.post-1644492905270811327</guid><pubDate>Sun, 20 Apr 2008 21:17:00 +0000</pubDate><atom:updated>2008-04-20T14:23:14.509-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Deep Zoom</category><category domain="http://www.blogger.com/atom/ns#">Silverlight</category><title>Deep Zoom - Album Creator</title><description>&lt;span style="font-style:italic;"&gt;No, this one is not by me!&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Marauderz has developed a Deep Zoom &lt;a href="http://www.marauderzstuff.com/PermaLink,guid,2dbe34b8-306a-45cf-8bf1-db718a5c998c.aspx"&gt;Album Creator&lt;/a&gt; which uses some code from my blog so I thought I'd mention it here. I am glad to see my code being leveraged in some useful tools, hopefully more of which we shall be seeing soon.&lt;br /&gt;&lt;br /&gt;How about some designers getting involved and skinning this baby?&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7411255283791998153-1644492905270811327?l=projectsilverlight.blogspot.com'/&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/ProjectSilverlight/~4/DXTS0G_VmgI" height="1" width="1"/&gt;</description><link>http://projectsilverlight.blogspot.com/2008/04/deep-zoom-album-creator.html</link><author>noreply@blogger.com (Wilfred Pinto)</author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">2</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-7411255283791998153.post-7375387193521400410</guid><pubDate>Sun, 20 Apr 2008 06:46:00 +0000</pubDate><atom:updated>2008-10-14T16:44:17.736-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Deep Zoom</category><category domain="http://www.blogger.com/atom/ns#">Silverlight</category><title>Deep Zoom - SlideShow</title><description>I was wondering how best to showcase the functionality from my last post and the idea of SlideShow popped up in my head. Also, I was bored and wanted to play around with Deep Zoom some more...&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="font-style:italic;"&gt;&lt;u&gt;Update Oct 14, 2008:&lt;/u&gt; Removed the example from this post to reduce load time of this page. Please use the example from this post, &lt;a href="http://projectsilverlight.blogspot.com/2008/06/deepzoom-sample-ported-to-silverlight-2.html"&gt;DeepZoom sample ported to Silverlight 2 Beta 2&lt;/a&gt;, to try the functionality.&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;Click on the &lt;span style="font-style:italic;"&gt;Start Slide&lt;/span&gt; button to activate the slide show. Click on the button again to stop the slide show.&lt;br /&gt;&lt;br /&gt;The code to enable slide show is very simple. Most of the work is done by the function described in my last post.&lt;br /&gt;&lt;br /&gt;Xaml&lt;br /&gt;&lt;pre&gt;&lt;code&gt;&amp;lt;Button Grid.Column="2" x:Name="buttonSlideshow" Width="70" Content="Start Slide" IsEnabled="False"/&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;Code&lt;br /&gt;&lt;pre class="csharpcode"&gt;&lt;br /&gt;&lt;span class="kwrd"&gt;int&lt;/span&gt; _slideshowImageIndex = 0;&lt;br /&gt;System.Windows.Threading.DispatcherTimer _myDispatcherTimer;&lt;br /&gt;&lt;br /&gt;msi.Loaded += &lt;span class="kwrd"&gt;delegate&lt;/span&gt;(&lt;span class="kwrd"&gt;object&lt;/span&gt; sender, RoutedEventArgs e)&lt;br /&gt;{&lt;br /&gt;    _myDispatcherTimer = &lt;span class="kwrd"&gt;new&lt;/span&gt; System.Windows.Threading.DispatcherTimer();&lt;br /&gt;    _myDispatcherTimer.Tick += &lt;span class="kwrd"&gt;new&lt;/span&gt; EventHandler(Each_Tick);&lt;br /&gt;    buttonSlideshow.IsEnabled = &lt;span class="kwrd"&gt;true&lt;/span&gt;;&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;buttonSlideshow.Click += &lt;span class="kwrd"&gt;delegate&lt;/span&gt;(&lt;span class="kwrd"&gt;object&lt;/span&gt; sender, RoutedEventArgs e)&lt;br /&gt;{&lt;br /&gt;    &lt;span class="kwrd"&gt;if&lt;/span&gt; ((&lt;span class="kwrd"&gt;string&lt;/span&gt;)buttonSlideshow.Content == &lt;span class="str"&gt;"Start Slide"&lt;/span&gt;) {&lt;br /&gt;        buttonSlideshow.Content = &lt;span class="str"&gt;"Stop Slide"&lt;/span&gt;;&lt;br /&gt;        StartSlideShow();&lt;br /&gt;    }&lt;br /&gt;    &lt;span class="kwrd"&gt;else&lt;/span&gt; {&lt;br /&gt;        buttonSlideshow.Content = &lt;span class="str"&gt;"Start Slide"&lt;/span&gt;;&lt;br /&gt;        StopSlideShow();&lt;br /&gt;    }&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; StartSlideShow()&lt;br /&gt;{&lt;br /&gt;    &lt;span class="rem"&gt;// Set the timer interval to 200 ms so that the tick event is called immediately&lt;/span&gt;&lt;br /&gt;    _myDispatcherTimer.Interval = &lt;span class="kwrd"&gt;new&lt;/span&gt; TimeSpan(0, 0, 0, 0, 200);&lt;br /&gt;    _myDispatcherTimer.Start();&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; StopSlideShow()&lt;br /&gt;{&lt;br /&gt;    _myDispatcherTimer.Stop();&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Each_Tick(&lt;span class="kwrd"&gt;object&lt;/span&gt; o, EventArgs sender)&lt;br /&gt;{&lt;br /&gt;    &lt;span class="rem"&gt;// Reset the timer to 5 sec so that each slide appears after 5 seconds&lt;/span&gt;&lt;br /&gt;    _myDispatcherTimer.Interval = &lt;span class="kwrd"&gt;new&lt;/span&gt; TimeSpan(0, 0, 0, 0, 5000);&lt;br /&gt;    ZoomFullAndCenterImage(_slideshowImageIndex);&lt;br /&gt;    &lt;span class="kwrd"&gt;if&lt;/span&gt; (++_slideshowImageIndex == msi.SubImages.Count)&lt;br /&gt;        _slideshowImageIndex = 0;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7411255283791998153-7375387193521400410?l=projectsilverlight.blogspot.com'/&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/ProjectSilverlight/~4/UypmxxqPslk" height="1" width="1"/&gt;</description><link>http://projectsilverlight.blogspot.com/2008/04/deep-zoom-slideshow.html</link><author>noreply@blogger.com (Wilfred Pinto)</author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">5</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-7411255283791998153.post-5829249999957746612</guid><pubDate>Mon, 14 Apr 2008 23:13:00 +0000</pubDate><atom:updated>2008-04-19T23:38:00.963-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Deep Zoom</category><category domain="http://www.blogger.com/atom/ns#">Silverlight</category><title>Deep Zoom - Zooming and centering image to fill the Deep Zoom screen</title><description>One of the readers (&lt;span style="font-style:italic;"&gt;see comments &lt;a href="http://projectsilverlight.blogspot.com/2008/04/dissecting-hard-rock-memorabilia-and_08.html#comments"&gt;here&lt;/a&gt;&lt;/span&gt;) wanted to zoom and center an image from the collection in such a way that it would fill the screen. Here is the code snippet that will fulfill this requirement. I haven't applied this to an example yet, but I will, if there is enough interest.&lt;br /&gt;&lt;pre class="csharpcode"&gt;&lt;br /&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; ZoomFullAndCenterImage(&lt;span class="kwrd"&gt;int&lt;/span&gt; subImageIndex)&lt;br /&gt;{&lt;br /&gt;    Rect subImageRect = GetSubImageRect(subImageIndex);&lt;br /&gt;    Rect imageRectElement = msiLogicalToElementRect(GetSubImageRect(subImageIndex));&lt;br /&gt;    &lt;br /&gt;    &lt;span class="rem"&gt;// Calculate the zoom factor such that the image will fill up the entire screen&lt;/span&gt;&lt;br /&gt;    &lt;span class="kwrd"&gt;double&lt;/span&gt; zoomFactor = (msi.Width / imageRectElement.Width) &amp;lt; (msi.Height / imageRectElement.Height) ? &lt;br /&gt;                                        msi.Width / imageRectElement.Width : msi.Height / imageRectElement.Height;&lt;br /&gt;    &lt;br /&gt;    &lt;span class="rem"&gt;// Center the image&lt;/span&gt;&lt;br /&gt;    DisplaySubImageCentered(subImageIndex);&lt;br /&gt;    &lt;span class="rem"&gt;// Use the mid point of the image to zoom from&lt;/span&gt;&lt;br /&gt;    msi.ZoomAboutLogicalPoint(zoomFactor, (subImageRect.Left+subImageRect.Right)/2, (subImageRect.Top+subImageRect.Bottom)/2);&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7411255283791998153-5829249999957746612?l=projectsilverlight.blogspot.com'/&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/ProjectSilverlight/~4/e_Gtrbv5R2g" height="1" width="1"/&gt;</description><link>http://projectsilverlight.blogspot.com/2008/04/deep-zoom-zooming-and-centering-image.html</link><author>noreply@blogger.com (Wilfred Pinto)</author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">2</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-7411255283791998153.post-180754495180238633</guid><pubDate>Mon, 14 Apr 2008 03:14:00 +0000</pubDate><atom:updated>2008-10-14T16:33:15.350-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Deep Zoom</category><category domain="http://www.blogger.com/atom/ns#">Silverlight</category><title>Dissecting Hard Rock Memorabilia...- Part 9 - Source code</title><description>Due to the large number of requests for the source code and my inability to respond to every request, I decided to post the link to the source code &lt;a href="http://thepintospatronus.com/deepzoom/DeepZoomOutput-Beta1.zip"&gt;here&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;I would appreciate a quick comment to this post if you do decide to download the source code. This way I get an idea of how much interest there is for the code.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style:italic;"&gt;Disclaimer: I used the project created by &lt;a href="http://www.hanselman.com/blog/TheWeeklySourceCode18DeepZoomSeadragonSilverlight2MultiScaleImageMouseWheelZoomingAndPanningEdition.aspx"&gt;Scott Hanselman&lt;/a&gt;, and parts of the code was borrowed from the &lt;a href="http://blogs.msdn.com/expression/archive/2008/03/22/deep-zoom-collections-example.aspx"&gt;Expression Team&lt;/a&gt; and &lt;a href="http://www.soulsolutions.com.au/Default.aspx?tabid=73&amp;EntryID=410"&gt;Soul Solutions&lt;/a&gt; blog. I used Notepad++ as my editor since I do not have access to Visual Studio. As a result of this and the fact that I have very limited time to dedicate to this activity, the code is as dirty as it gets!&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7411255283791998153-180754495180238633?l=projectsilverlight.blogspot.com'/&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/ProjectSilverlight/~4/Iw-RSybTJWo" height="1" width="1"/&gt;</description><link>http://projectsilverlight.blogspot.com/2008/04/dissecting-hard-rock-memorabilia-part-9.html</link><author>noreply@blogger.com (Wilfred Pinto)</author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">17</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-7411255283791998153.post-1546812786926276902</guid><pubDate>Tue, 08 Apr 2008 19:09:00 +0000</pubDate><atom:updated>2008-04-08T12:23:50.211-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Deep Zoom</category><category domain="http://www.blogger.com/atom/ns#">Silverlight</category><title>Dissecting Hard Rock Memorabilia and Silverlight Deep Zoom - Part 8</title><description>For completion sake, I decided to post the animation and randomize code here. The code to do the actual animation is lifted as is from the &lt;a href="http://blogs.msdn.com/expression/archive/2008/03/22/deep-zoom-collections-example.aspx"&gt;Expression Team&lt;/a&gt; blog but I did make a few subtle changes -&lt;br /&gt;&lt;ol&gt;&lt;li&gt;Fixed the memory leak issue by getting rid of the Storyboard after it has achieved its purpose&lt;/li&gt;&lt;li&gt;Used a single storyboard to animate multiple images. I don't know if this is better than multiple storyboards &lt;span style="font-style:italic;"&gt;(one for each image)&lt;/span&gt; so it would be nice to hear some opinions&lt;/li&gt;&lt;/ol&gt;&lt;br /&gt;Code to animate the image&lt;br /&gt;&lt;pre class="csharpcode"&gt;&lt;br /&gt;&lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; AnimateImage(MultiScaleSubImage currentImage, Point futurePosition)&lt;br /&gt;{&lt;br /&gt;    &lt;span class="rem"&gt;// Create Keyframe&lt;/span&gt;&lt;br /&gt;    SplinePointKeyFrame endKeyframe = &lt;span class="kwrd"&gt;new&lt;/span&gt; SplinePointKeyFrame();&lt;br /&gt;    endKeyframe.Value = futurePosition;&lt;br /&gt;    endKeyframe.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(1));&lt;br /&gt;&lt;br /&gt;    KeySpline ks = &lt;span class="kwrd"&gt;new&lt;/span&gt; KeySpline();&lt;br /&gt;    ks.ControlPoint1 = &lt;span class="kwrd"&gt;new&lt;/span&gt; Point(0, 1);&lt;br /&gt;    ks.ControlPoint2 = &lt;span class="kwrd"&gt;new&lt;/span&gt; Point(1, 1);&lt;br /&gt;    endKeyframe.KeySpline = ks;&lt;br /&gt;&lt;br /&gt;    &lt;span class="rem"&gt;// Create Animation&lt;/span&gt;&lt;br /&gt;    PointAnimationUsingKeyFrames moveAnimation = &lt;span class="kwrd"&gt;new&lt;/span&gt; PointAnimationUsingKeyFrames();&lt;br /&gt;    moveAnimation.KeyFrames.Add(endKeyframe);&lt;br /&gt;&lt;br /&gt;    Storyboard.SetTarget(moveAnimation, currentImage);&lt;br /&gt;    Storyboard.SetTargetProperty(moveAnimation, &lt;span class="str"&gt;"ViewportOrigin"&lt;/span&gt;);&lt;br /&gt;&lt;br /&gt;    &lt;span class="rem"&gt;// Add the animation to the Storyboard&lt;/span&gt;&lt;br /&gt;    _moveStoryboard.Children.Add(moveAnimation);&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Code to invoke the animation - &lt;span style="font-style:italic;"&gt;I decided against animating the hidden images &lt;span style="font-style:italic;"&gt;(like Hard Rock)&lt;/span&gt; since my goal is to work with large amount of images and I didn't want to incur the additional performance overhead&lt;/span&gt;&lt;br /&gt;&lt;pre class="csharpcode"&gt;&lt;br /&gt;&lt;span class="kwrd"&gt;private&lt;/span&gt; Storyboard _moveStoryboard;&lt;br /&gt;&lt;br /&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; InitStoryboard()&lt;br /&gt;{&lt;br /&gt;    _moveStoryboard = &lt;span class="kwrd"&gt;new&lt;/span&gt; Storyboard();&lt;br /&gt;    msi.Resources.Add(_moveStoryboard);&lt;br /&gt;&lt;br /&gt;    _moveStoryboard.Completed += (sender, e) =&amp;gt; msi.Resources.Remove((Storyboard)sender);&lt;br /&gt;}&lt;br /&gt;       &lt;br /&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; ArrangeImages()&lt;br /&gt;{&lt;br /&gt;    InitStoryboard();&lt;br /&gt;   &lt;br /&gt;    ...&lt;br /&gt;   &lt;br /&gt;    &lt;span class="rem"&gt;// Then display the displayable images to scale&lt;/span&gt;&lt;br /&gt;    &lt;span class="kwrd"&gt;for&lt;/span&gt; (&lt;span class="kwrd"&gt;int&lt;/span&gt; i=0; i&amp;lt;_imagesToShow.Count; i++) {&lt;br /&gt;        &lt;span class="kwrd"&gt;double&lt;/span&gt; X = rows[subImages[i].RowNum].CalcX(subImages[i].ColNum);&lt;br /&gt;        &lt;span class="kwrd"&gt;double&lt;/span&gt; Y = margin;&lt;br /&gt;        &lt;span class="kwrd"&gt;for&lt;/span&gt; (&lt;span class="kwrd"&gt;int&lt;/span&gt; j=0; j&amp;lt;subImages[i].RowNum; j++)&lt;br /&gt;            Y += spaceBetweenImages + rows[j].Height;&lt;br /&gt;       &lt;br /&gt;        _imagesToShow[i].ViewportWidth = containerAspectRatio / subImages[i].Width;&lt;br /&gt;        AnimateImage(_imagesToShow[i], &lt;span class="kwrd"&gt;new&lt;/span&gt; Point(-(X / subImages[i].Width), -(Y / subImages[i].Width)));&lt;br /&gt;        _imagesToShow[i].Opacity = 1.0;&lt;br /&gt;    }&lt;br /&gt;   &lt;br /&gt;    &lt;span class="rem"&gt;// Play Storyboard&lt;/span&gt;&lt;br /&gt;    _moveStoryboard.Begin();&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Code to Randomize the images. &lt;span style="font-style:italic;"&gt;The code for the RandomizeListOfImages is lifted from the Expression Team blog&lt;/span&gt;&lt;br /&gt;&lt;pre class="csharpcode"&gt;&lt;br /&gt;buttonRandomize.Click += (sender, e) =&amp;gt; RandomizeAndArrange();&lt;br /&gt;&lt;br /&gt;&lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; RandomizeAndArrange() &lt;br /&gt;{&lt;br /&gt;    _imagesToShow = RandomizedListOfImages();&lt;br /&gt;    ArrangeImages();&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;span class="kwrd"&gt;private&lt;/span&gt; List&amp;lt;MultiScaleSubImage&amp;gt; RandomizedListOfImages()&lt;br /&gt;{&lt;br /&gt;    List&amp;lt;MultiScaleSubImage&amp;gt; imageList = &lt;span class="kwrd"&gt;new&lt;/span&gt; List&amp;lt;MultiScaleSubImage&amp;gt;();&lt;br /&gt;    Random ranNum = &lt;span class="kwrd"&gt;new&lt;/span&gt; Random();&lt;br /&gt;&lt;br /&gt;    &lt;span class="rem"&gt;// Store List of Images&lt;/span&gt;&lt;br /&gt;    _imagesToShow.ForEach(subImage =&amp;gt; imageList.Add(subImage));&lt;br /&gt;&lt;br /&gt;    &lt;span class="rem"&gt;// Randomize Image List&lt;/span&gt;&lt;br /&gt;    &lt;span class="kwrd"&gt;int&lt;/span&gt; numImages = imageList.Count;&lt;br /&gt;    &lt;span class="kwrd"&gt;for&lt;/span&gt;(&lt;span class="kwrd"&gt;int&lt;/span&gt; i=0; i&amp;lt;numImages; i++) {&lt;br /&gt;        MultiScaleSubImage tempImage = imageList[i];&lt;br /&gt;        imageList.RemoveAt(i);&lt;br /&gt;&lt;br /&gt;        &lt;span class="kwrd"&gt;int&lt;/span&gt; ranNumSelect = ranNum.Next(imageList.Count);&lt;br /&gt;&lt;br /&gt;        imageList.Insert(ranNumSelect, tempImage);&lt;br /&gt;    }&lt;br /&gt;    &lt;span class="kwrd"&gt;return&lt;/span&gt; imageList;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7411255283791998153-1546812786926276902?l=projectsilverlight.blogspot.com'/&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/ProjectSilverlight/~4/6RZg2F2lL78" height="1" width="1"/&gt;</description><link>http://projectsilverlight.blogspot.com/2008/04/dissecting-hard-rock-memorabilia-and_08.html</link><author>noreply@blogger.com (Wilfred Pinto)</author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">6</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-7411255283791998153.post-6366147437525017322</guid><pubDate>Sun, 06 Apr 2008 20:53:00 +0000</pubDate><atom:updated>2008-04-06T13:59:38.743-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Deep Zoom</category><category domain="http://www.blogger.com/atom/ns#">Silverlight</category><title>Deep Zoom - Known issues</title><description>I spent a few days on the silverlight forums to see if there were any known issues with the current Deep Zoom beta release. The below list of my findings is mainly to help me keep track of the issues so that I don't spend a good amount of my time trying to fix what cannot be fixed (&lt;span style="font-style: italic;"&gt;or can it?&lt;/span&gt;)!&lt;br /&gt;&lt;ol&gt;&lt;li&gt;Source property change is not handled well! There seems to be a workaround for non collection images but in general it seems to be broken - &lt;a href="http://silverlight.net/forums/p/11709/44231.aspx#44231"&gt;&lt;span style="font-style: italic;"&gt;http://silverlight.net/forums/p/11709/44231.aspx#44231&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;&lt;li&gt;Cross domain not working! Hosting the application and the deep zoom images in different domains does not work - &lt;a href="http://silverlight.net/forums/p/13152/43883.aspx#43883"&gt;&lt;span style="font-style: italic;"&gt;http://silverlight.net/forums/p/13152/43883.aspx#43883&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;&lt;li&gt;MultiScaleImage loses the image resolution after ScaleTransform! I noticed this when getting in/out of full screen mode as well - &lt;a href="http://silverlight.net/forums/p/13014/42316.aspx#42316"&gt;&lt;span style="font-style: italic;"&gt;http://silverlight.net/forums/p/13014/42316.aspx#42316&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;&lt;li&gt;MultiScaleImage only supports absolute paths! See my previous post for an example of how Vertigo worked around this (&lt;span style="font-style: italic;"&gt;same domain only&lt;/span&gt;) - &lt;a href="http://silverlight.net/forums/p/12182/40164.aspx#40164"&gt;&lt;span style="font-style: italic;"&gt;http://silverlight.net/forums/p/12182/40164.aspx#40164&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;&lt;li&gt;Transparent images are not supported in collection mode? &lt;a href="http://forums.expression.microsoft.com/en-US/thread/7f5aace6-9ab1-4503-8b34-f0378b731e98"&gt;&lt;span style="font-style: italic;"&gt;http://forums.expression.microsoft.com/en-US/thread/7f5aace6-9ab1-4503-8b34-f0378b731e98&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;&lt;/ol&gt;For those of you who might be thinking of playing around with the bin file format you might want to wait a little while. The final release version of Silverlight 2 Deep Zoom is expected to support the xml file format instead of the bin file format - &lt;a href="http://silverlight.net/forums/p/12784/41724.aspx#41724"&gt;&lt;span style="font-style: italic;"&gt;http://silverlight.net/forums/p/12784/41724.aspx#41724&lt;/span&gt;&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7411255283791998153-6366147437525017322?l=projectsilverlight.blogspot.com'/&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/ProjectSilverlight/~4/X1Y2cZVRmY0" height="1" width="1"/&gt;</description><link>http://projectsilverlight.blogspot.com/2008/04/deep-zoom-known-issues.html</link><author>noreply@blogger.com (Wilfred Pinto)</author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">6</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-7411255283791998153.post-6751536421278455975</guid><pubDate>Fri, 04 Apr 2008 05:28:00 +0000</pubDate><atom:updated>2008-04-03T23:15:04.610-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Deep Zoom</category><category domain="http://www.blogger.com/atom/ns#">Silverlight</category><title>Deep Zoom - Highlighting the clicked SubImage</title><description>Having played with the Hard Rock demo extensively, I noticed that it is a little difficult to see which image is associated with the displayed metadata. In general, it is the centered image but it could get confusing sometimes. This could be alleviated if there is a highlight or a border around the image. &lt;br /&gt;&lt;br /&gt;It's not that hard actually...&lt;br /&gt;&lt;br /&gt;1. Changes to the XAML&lt;br /&gt;&lt;pre&gt;&lt;code&gt;&amp;lt;Grid x:Name="LayoutRoot"&amp;gt;&lt;br /&gt; &amp;lt;Grid.RowDefinitions&amp;gt;&lt;br /&gt;  &amp;lt;RowDefinition Height="*"/&amp;gt;&lt;br /&gt;  &amp;lt;RowDefinition Height="5"/&amp;gt;&lt;br /&gt;  &amp;lt;RowDefinition Height="30"/&amp;gt;&lt;br /&gt;  &amp;lt;RowDefinition Height="30"/&amp;gt;&lt;br /&gt; &amp;lt;/Grid.RowDefinitions&amp;gt;&lt;br /&gt; &lt;br /&gt; &amp;lt;Border x:Name="msiBorder" Grid.Row="0" BorderThickness="1" BorderBrush="Black"&amp;gt;&lt;br /&gt;  &amp;lt;MultiScaleImage x:Name="msi" UseSprings="false" Margin="2,2,2,2"/&amp;gt;&lt;br /&gt; &amp;lt;/Border&amp;gt;&lt;br /&gt; &lt;u&gt;&amp;lt;Canvas Grid.Row="0" Margin="3,3,2,2"&amp;gt;&lt;/u&gt;&lt;br /&gt;  &lt;u&gt;&amp;lt;Border x:Name="imageBorder" BorderThickness="2" BorderBrush="Black" Opacity="0" /&amp;gt;&lt;/u&gt;&lt;br /&gt; &lt;u&gt;&amp;lt;/Canvas&amp;gt;&lt;/u&gt;&lt;br /&gt;&lt;br /&gt; ...&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;2. The code to show and hide the highlight on a image&lt;br /&gt;&lt;pre class="csharpcode"&gt;&lt;br /&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; ShowImageHighlight(&lt;span class="kwrd"&gt;int&lt;/span&gt; nSubImageIndex)&lt;br /&gt;{    &lt;span class="rem"&gt;// Hightlight the image by drawing a border around it&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span class="kwrd"&gt;int&lt;/span&gt; borderWidth = 2;        &lt;span class="rem"&gt;// Setting the default border width to 2&lt;/span&gt;&lt;br /&gt;    &lt;span class="kwrd"&gt;if&lt;/span&gt; (msi.ViewportWidth &amp;lt; 1)    &lt;span class="rem"&gt;// This adjusts for zoomed images where a border of 2 is insufficient&lt;/span&gt;&lt;br /&gt;        borderWidth = (&lt;span class="kwrd"&gt;int&lt;/span&gt;) (borderWidth / msi.ViewportWidth);&lt;br /&gt;        &lt;br /&gt;    Rect borderRect = ExpandRect(msiLogicalToElementRect(GetSubImageRect(nSubImageIndex)), borderWidth);&lt;br /&gt;    &lt;br /&gt;    imageBorder.Width = borderRect.Width;&lt;br /&gt;    imageBorder.Height = borderRect.Height;&lt;br /&gt;    imageBorder.SetValue(Canvas.LeftProperty, borderRect.X);&lt;br /&gt;    imageBorder.SetValue(Canvas.TopProperty, borderRect.Y);&lt;br /&gt;    imageBorder.BorderThickness = &lt;span class="kwrd"&gt;new&lt;/span&gt; Thickness(borderWidth);&lt;br /&gt;    imageBorder.Opacity = 1.0;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; HideImageHighlight()&lt;br /&gt;{&lt;br /&gt;    imageBorder.Opacity = 0.0;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Rect msiLogicalToElementRect(Rect rect)&lt;br /&gt;{&lt;br /&gt;    &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; Rect(msi.LogicalToElementPoint(&lt;span class="kwrd"&gt;new&lt;/span&gt; Point(rect.Left, rect.Top)), &lt;br /&gt;                    msi.LogicalToElementPoint(&lt;span class="kwrd"&gt;new&lt;/span&gt; Point(rect.Right, rect.Bottom)));&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Rect ExpandRect(Rect rect, &lt;span class="kwrd"&gt;int&lt;/span&gt; expandBy)&lt;br /&gt;{&lt;br /&gt;    &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; Rect(rect.Left - expandBy, rect.Top - expandBy, rect.Width + expandBy*2, rect.Height + expandBy*2);&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;3. The hooks to invoke the above code&lt;br /&gt;&lt;pre class="csharpcode"&gt;&lt;br /&gt;&lt;span class="kwrd"&gt;int&lt;/span&gt; _clickedImageIndex = -1;&lt;br /&gt;&lt;br /&gt;msi.MotionFinished += (sender, e) =&amp;gt; { &lt;span class="kwrd"&gt;if&lt;/span&gt; (_clickedImageIndex &amp;gt;= 0) ShowImageHighlight(_clickedImageIndex); };&lt;br /&gt;&lt;br /&gt;msi.MouseLeftButtonDown += (sender, e) =&amp;gt; { _clickedImageIndex = -1; };&lt;br /&gt;&lt;span class="kwrd"&gt;new&lt;/span&gt; MouseWheelHelper(&lt;span class="kwrd"&gt;this&lt;/span&gt;).Moved += (sender, e) =&amp;gt; { _clickedImageIndex = -1; };&lt;br /&gt;&lt;br /&gt;msi.MouseLeftButtonUp += &lt;span class="kwrd"&gt;delegate&lt;/span&gt;(&lt;span class="kwrd"&gt;object&lt;/span&gt; sender, MouseButtonEventArgs e)&lt;br /&gt;{&lt;br /&gt;    &lt;span class="kwrd"&gt;if&lt;/span&gt; (mouseButtonPressed &amp;amp;&amp;amp; !dragInProgress)&lt;br /&gt;    {&lt;br /&gt;        Point p = &lt;span class="kwrd"&gt;this&lt;/span&gt;.msi.ElementToLogicalPoint(e.GetPosition(&lt;span class="kwrd"&gt;this&lt;/span&gt;.msi));&lt;br /&gt;        &lt;span class="kwrd"&gt;int&lt;/span&gt; subImageIndex = SubImageHitTest(p);&lt;br /&gt;        &lt;span class="kwrd"&gt;if&lt;/span&gt; (subImageIndex &amp;gt;= 0) {&lt;br /&gt;            &lt;u&gt;DisplaySubImageCentered(subImageIndex);&lt;/u&gt;&lt;br /&gt;            &lt;u&gt;_clickedImageIndex = subImageIndex;&lt;/u&gt;&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        &lt;span class="kwrd"&gt;bool&lt;/span&gt; shiftDown = (Keyboard.Modifiers &amp;amp; ModifierKeys.Shift) == ModifierKeys.Shift;&lt;br /&gt;        &lt;span class="kwrd"&gt;if&lt;/span&gt; (shiftDown)  Zoom(0.5, e.GetPosition(&lt;span class="kwrd"&gt;this&lt;/span&gt;.msi));&lt;br /&gt;        &lt;span class="kwrd"&gt;else&lt;/span&gt;            Zoom(2.0, e.GetPosition(&lt;span class="kwrd"&gt;this&lt;/span&gt;.msi));&lt;br /&gt;    }&lt;br /&gt;    mouseButtonPressed = &lt;span class="kwrd"&gt;false&lt;/span&gt;;&lt;br /&gt;    dragInProgress = &lt;span class="kwrd"&gt;false&lt;/span&gt;;&lt;br /&gt;};&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;I updated the previous example &lt;span style="font-style:italic;"&gt;&lt;a href="http://projectsilverlight.blogspot.com/2008/04/dissecting-hard-rock-memorabilia-and_02.html"&gt;Dissecting Hard Rock Memorabilia and Silverlight Deep Zoom - Part 7&lt;/a&gt;&lt;/span&gt; with this code so you can see how it works!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7411255283791998153-6751536421278455975?l=projectsilverlight.blogspot.com'/&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/ProjectSilverlight/~4/PVgk3zBjEbk" height="1" width="1"/&gt;</description><link>http://projectsilverlight.blogspot.com/2008/04/deep-zoom-highlight-clicked-subimage.html</link><author>noreply@blogger.com (Wilfred Pinto)</author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">8</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-7411255283791998153.post-3797977108523082827</guid><pubDate>Thu, 03 Apr 2008 21:42:00 +0000</pubDate><atom:updated>2008-04-03T14:56:22.567-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Deep Zoom</category><category domain="http://www.blogger.com/atom/ns#">Silverlight</category><title>Vertigo BigPicture (aka Hard Rock?) sample code</title><description>Vertigo has published their &lt;a href="http://www.codeplex.com/BigPicture"&gt;BigPicture&lt;/a&gt; code on codeplex. As of this time, only the mouse handler code is available but hopefully this will change. The mouse handler code is clean and well documented though so I am going to use it on my project.&lt;br /&gt;&lt;br /&gt;One of the known issues with MultiScaleImages is that it doesn't properly handle relative URI in the Source property. Vertigo has found a neat workaround by converting a relative Uri to an absolute Uri using the Uri.TryCreate method&lt;br /&gt;&lt;pre class="csharpcode"&gt;&lt;br /&gt;&lt;span style="font-style:italic;"&gt;// Directly lifted from &lt;a href="http://www.codeplex.com/BigPicture"&gt;http://www.codeplex.com/BigPicture&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;Uri collectionUri;&lt;br /&gt;&lt;br /&gt;&lt;span class="kwrd"&gt;if&lt;/span&gt; (Uri.TryCreate(App.Current.Host.Source, &lt;span class="str"&gt;"/Collection/items.bin"&lt;/span&gt;, &lt;span class="kwrd"&gt;out&lt;/span&gt; collectionUri))&lt;br /&gt;    image.Source = collectionUri;&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7411255283791998153-3797977108523082827?l=projectsilverlight.blogspot.com'/&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/ProjectSilverlight/~4/TMc2aC2XgVM" height="1" width="1"/&gt;</description><link>http://projectsilverlight.blogspot.com/2008/04/vertigo-bigpicture-aka-hard-rock-sample.html</link><author>noreply@blogger.com (Wilfred Pinto)</author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total></item></channel></rss>
