<?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:blogger="http://schemas.google.com/blogger/2008" xmlns:georss="http://www.georss.org/georss" xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr="http://purl.org/syndication/thread/1.0" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0"><channel><atom:id>tag:blogger.com,1999:blog-804082557306552579</atom:id><lastBuildDate>Mon, 29 Apr 2013 01:30:16 +0000</lastBuildDate><category>mobile</category><category>Visual Studio</category><category>Microsoft</category><category>installation</category><category>Prism</category><category>2011</category><category>Windows Live Spaces</category><category>CodeProject</category><category>UI</category><category>competition</category><category>storage</category><category>Kaxaml</category><category>enumerations</category><category>Windows</category><category>upgrade</category><category>logo</category><category>XAML</category><category>c#</category><category>sqlserver</category><category>composite</category><category>wp7</category><category>Git</category><category>source control</category><category>.net</category><category>EA</category><category>Facebook</category><category>2008</category><category>broken</category><category>message box</category><category>enum</category><category>office</category><category>threads</category><category>personal</category><category>tool</category><category>refactor</category><category>dependency properties</category><category>controls</category><category>WordPress</category><category>fracture</category><category>2010</category><category>files</category><category>music</category><category>games</category><category>extension method</category><category>screen shot</category><category>Nine Inch Nails</category><category>Spore</category><category>cloud</category><category>Blogger</category><category>blog</category><category>beta</category><category>custom</category><category>styles</category><category>multi-threading</category><category>attached properties</category><category>Live Mesh</category><category>flickr</category><category>software</category><category>Titan</category><category>databinding</category><category>add-in</category><category>change notification</category><category>Window</category><category>2008R2</category><category>testing</category><category>WPF</category><category>Silverlight</category><category>MIX</category><title>Titan</title><description>Is your head in the clouds?</description><link>http://cloudstore.blogspot.com/</link><managingEditor>noreply@blogger.com (Derek Lakin)</managingEditor><generator>Blogger</generator><openSearch:totalResults>39</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/cloudstore" /><feedburner:info uri="cloudstore" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><image><link>http://cloudstore.blogspot.com</link><url>http://fw84pq.bay.livefilestore.com/y1pC9PlYSUfDURKnZ96oHkbYSkkFwysmnQbBC_ogCYQdUMCiJ5kFQMWvzj4z4CCp2v2gSwqQ3YRqp8hPvX1dLCeyg/Titan_small.png</url><title>Titan Logo</title></image><item><guid isPermaLink="false">tag:blogger.com,1999:blog-804082557306552579.post-4742448668559850600</guid><pubDate>Mon, 04 Jul 2011 08:49:00 +0000</pubDate><atom:updated>2011-07-04T09:50:35.707+01:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">installation</category><category domain="http://www.blogger.com/atom/ns#">upgrade</category><category domain="http://www.blogger.com/atom/ns#">Microsoft</category><category domain="http://www.blogger.com/atom/ns#">sqlserver</category><category domain="http://www.blogger.com/atom/ns#">2008</category><category domain="http://www.blogger.com/atom/ns#">2008R2</category><title>Upgrading from SQL Server Express Edition</title><description>&lt;p&gt;This is more of a personal note-to-self, but hopefully it will save someone else tearing their hair out!&lt;/p&gt;  &lt;p&gt;If you already have SQL Server Express Edition installed and you decide to install a “higher” (Standard, or Enterprise) edition, then you might be surprised when you find after the installation that the complete management tools are not installed, such as SQL Server Profiler.&lt;/p&gt;  &lt;p&gt;After much trial and error (and loss of yet more hair) I found that the following worked for me:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Run the SQL Server setup.&lt;/li&gt;    &lt;li&gt;Go to the &lt;strong&gt;Maintenance&lt;/strong&gt; option, and then perform a &lt;strong&gt;Feature Upgrade&lt;/strong&gt; on the &lt;strong&gt;Shared Features&lt;/strong&gt; (select &amp;lt;&amp;lt;Upgrade shared feature components only&amp;gt;&amp;gt; when you select the edition to upgrade).&lt;/li&gt;    &lt;li&gt;Go back to setup, and then select &lt;strong&gt;New installation or add features to an existing installation&lt;/strong&gt;.&lt;/li&gt;    &lt;li&gt;During the installation, select &lt;strong&gt;Management Tools - Complete&lt;/strong&gt;.&lt;/li&gt;    &lt;li&gt;Bask in the glory of your new found management tools.&lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;I suspect (that can’t confirm) that if you perform the feature upgrade mentioned in step 2 &lt;em&gt;before&lt;/em&gt; you install the new edition then the Management Tools - Complete option will be available during the installation of the new edition.&lt;/p&gt;  &lt;p&gt;Hope this helps.&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=1DMsOrjq7do:8krUYUFEoao:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=1DMsOrjq7do:8krUYUFEoao:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?i=1DMsOrjq7do:8krUYUFEoao:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=1DMsOrjq7do:8krUYUFEoao:oCFASsrFxfc"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?d=oCFASsrFxfc" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=1DMsOrjq7do:8krUYUFEoao:Jwdi1b3fU3Q"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?d=Jwdi1b3fU3Q" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=1DMsOrjq7do:8krUYUFEoao:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?i=1DMsOrjq7do:8krUYUFEoao:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/cloudstore/~4/1DMsOrjq7do" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/cloudstore/~3/1DMsOrjq7do/upgrading-from-sql-server-express.html</link><author>noreply@blogger.com (Derek Lakin)</author><thr:total>0</thr:total><feedburner:origLink>http://cloudstore.blogspot.com/2011/07/upgrading-from-sql-server-express.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-804082557306552579.post-4334954743850421404</guid><pubDate>Fri, 21 Jan 2011 11:46:00 +0000</pubDate><atom:updated>2011-01-21T11:46:51.666Z</atom:updated><category domain="http://www.blogger.com/atom/ns#">tool</category><category domain="http://www.blogger.com/atom/ns#">wp7</category><category domain="http://www.blogger.com/atom/ns#">Visual Studio</category><title>Don’t Forget Your Windows Phone 7 Capabilities</title><description>&lt;p&gt;If you’re developing a Windows Phone 7 application and you’re being a responsible developer and cleaning up the capabilities section of your WMAppManifest.xml file&lt;sup&gt;[1]&lt;/sup&gt; and then get unexpected errors when you extend your application further (such as adding the WebBrowser control), don’t forget to rescan your capabilities to ensure they are up to date.&lt;/p&gt;  &lt;p&gt;I just did exactly that; I added the WebBrowser control to a WP7 project and got an exception that gave the error code 80010108. I had removed the ID_CAP_WEBBROWSERCOMPONENT capability from the WMAppManifest.xml file.&lt;/p&gt;  &lt;p&gt;Just thought I’d make a public not to myself and hope it saves someone else some searching.&lt;/p&gt;  &lt;p&gt;&lt;sup&gt;[1]&lt;/sup&gt; For more information about the Windows Phone Capability Detection Tool and how to run it easily from within Visual Studio, check out my &lt;a href="http://cloudstore.blogspot.com/2010/10/checking-your-wp7-application.html"&gt;earlier blog post&lt;/a&gt;.&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=Zdpawy7xgB0:bK0qEWEZmQ0:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=Zdpawy7xgB0:bK0qEWEZmQ0:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?i=Zdpawy7xgB0:bK0qEWEZmQ0:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=Zdpawy7xgB0:bK0qEWEZmQ0:oCFASsrFxfc"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?d=oCFASsrFxfc" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=Zdpawy7xgB0:bK0qEWEZmQ0:Jwdi1b3fU3Q"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?d=Jwdi1b3fU3Q" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=Zdpawy7xgB0:bK0qEWEZmQ0:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?i=Zdpawy7xgB0:bK0qEWEZmQ0:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/cloudstore/~4/Zdpawy7xgB0" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/cloudstore/~3/Zdpawy7xgB0/dont-forget-your-windows-phone-7.html</link><author>noreply@blogger.com (Derek Lakin)</author><thr:total>0</thr:total><feedburner:origLink>http://cloudstore.blogspot.com/2011/01/dont-forget-your-windows-phone-7.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-804082557306552579.post-5421252377626015894</guid><pubDate>Tue, 18 Jan 2011 11:38:00 +0000</pubDate><atom:updated>2011-01-18T11:38:08.205Z</atom:updated><category domain="http://www.blogger.com/atom/ns#">mobile</category><category domain="http://www.blogger.com/atom/ns#">wp7</category><category domain="http://www.blogger.com/atom/ns#">message box</category><title>Customizing MessageBox on Windows Phone 7</title><description>&lt;p&gt;Whilst I’m really impressed with Windows Phone 7 as a smartphone operating system and even more impressed with the ease and simplicity with which developers can produce applications for this new operation system (it’s basically Silverlight 3 with a few phone-specific tweaks and additions), there are a few omissions that can make life difficult for developers. One of these omissions is in the &lt;a href="http://msdn.microsoft.com/en-us/library/ms599804(v=VS.95).aspx"&gt;MessageBox&lt;/a&gt; API, which offers the following two Show methods:&lt;/p&gt;  &lt;pre&gt;&lt;code&gt;MessageBoxResult Show(string);&lt;/code&gt;
&lt;code&gt;MessageBoxResult Show(string, string, MessageBoxButton);&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The problem is that the &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.messageboxbutton(v=VS.95).aspx"&gt;MessageBoxButton&lt;/a&gt; enumeration only supports the &lt;code&gt;OK&lt;/code&gt; and &lt;code&gt;OKCancel&lt;/code&gt; values, which means that we’re limited to either an &lt;strong&gt;ok&lt;/strong&gt; button or an &lt;strong&gt;ok&lt;/strong&gt; and a &lt;strong&gt;cancel&lt;/strong&gt; button. The &lt;code&gt;YesNo&lt;/code&gt; and &lt;code&gt;YesNoCancel&lt;/code&gt; enumeration values are not supported. I’ve just been working on a project where these additional values would have been helpful and in fact, instead of inventing a custom UI, I wanted to be able to customize the button labels, so I set about creating my own &lt;code&gt;MessageBoxService&lt;/code&gt; class (the use of an instance class instead of static methods was mostly down to which way the wind was blowing!).&lt;/p&gt;

&lt;h2&gt;User Interface Layers&lt;/h2&gt;

&lt;p&gt;The following diagram shows the layers required on the user interface:&lt;/p&gt;

&lt;p&gt;&lt;a title="MessageBoxService Layers" href="http://www.flickr.com/photos/51035614344@N01/5364347436/"&gt;&lt;img style="display: block; float: none; margin-left: auto; margin-right: auto" border="0" alt="MessageBoxService Layers" src="http://static.flickr.com/5125/5364347436_1c7feb696c.jpg" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Basically, we need to display a semi-transparent blanking layer over the page content, and then display the message box on top of that. In order to correctly swap colors when the device theme changes there’s actually an extra layer under the message box content, too.&lt;/p&gt;

&lt;p&gt;To all intents and purposes the XAML for the user interface (shown above) looks something like this:&lt;/p&gt;

&lt;div class="csharpcode"&gt;
  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   1:  &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;Background&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;#7F000000&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;Grid&lt;/span&gt;.&lt;span class="attr"&gt;RowSpan&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;2&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   2:  &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;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   3:  &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;=&amp;quot;Auto&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   4:  &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;=&amp;quot;*&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   5:  &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;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   6:  &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;Background&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;#7F000000&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   7:  &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;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   8:  &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;=&amp;quot;*&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   9:  &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;=&amp;quot;*&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  10:  &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;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  11:  &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;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  12:  &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;=&amp;quot;Auto&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  13:  &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;=&amp;quot;Auto&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  14:  &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;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  15:  &lt;/span&gt;        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Grid.Projection&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  16:  &lt;/span&gt;            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;PlaneProjection&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  17:  &lt;/span&gt;        &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Grid.Projection&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  18:  &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;Background&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;{StaticResource PhoneForegroundBrush}&amp;quot;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  19:  &lt;/span&gt;                &lt;span class="attr"&gt;Grid&lt;/span&gt;.&lt;span class="attr"&gt;ColumnSpan&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;2&amp;quot;&lt;/span&gt; &lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  20:  &lt;/span&gt;                &lt;span class="attr"&gt;Grid&lt;/span&gt;.&lt;span class="attr"&gt;RowSpan&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;2&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  21:  &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;Background&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;#7F000000&amp;quot;&lt;/span&gt; &lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  22:  &lt;/span&gt;                &lt;span class="attr"&gt;Grid&lt;/span&gt;.&lt;span class="attr"&gt;ColumnSpan&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;2&amp;quot;&lt;/span&gt; &lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  23:  &lt;/span&gt;                &lt;span class="attr"&gt;Grid&lt;/span&gt;.&lt;span class="attr"&gt;RowSpan&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;2&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  24:  &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="attr"&gt;Grid&lt;/span&gt;.&lt;span class="attr"&gt;ColumnSpan&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;2&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;Margin&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;12,0,12,12&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  25:  &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;FontFamily&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Segoe WP Semibold&amp;quot;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  26:  &lt;/span&gt;                       &lt;span class="attr"&gt;FontSize&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;32&amp;quot;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  27:  &lt;/span&gt;                       &lt;span class="attr"&gt;Margin&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;12&amp;quot;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  28:  &lt;/span&gt;                       &lt;span class="attr"&gt;Text&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Message Caption&amp;quot;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  29:  &lt;/span&gt;                       &lt;span class="attr"&gt;TextWrapping&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Wrap&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  30:  &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;FontSize&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;24&amp;quot;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  31:  &lt;/span&gt;                       &lt;span class="attr"&gt;Margin&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;12,0,12,12&amp;quot;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  32:  &lt;/span&gt;                       &lt;span class="attr"&gt;Text&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Message Text&amp;quot;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  33:  &lt;/span&gt;                       &lt;span class="attr"&gt;TextWrapping&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Wrap&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  34:  &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;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  35:  &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;=&amp;quot;yes&amp;quot;&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;=&amp;quot;1&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  36:  &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;=&amp;quot;no&amp;quot;&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;=&amp;quot;1&amp;quot;&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;=&amp;quot;1&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  37:  &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;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  38:  &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;/pre&gt;
&lt;/div&gt;

&lt;p&gt;&lt;style type="text/css"&gt;

















.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;&lt;/p&gt;

&lt;p&gt;In actual fact I create the user interface in code so that I can update the number of columns and the column span of the elements according to the number of buttons being displayed. One of the other things that seemed odd to me with the framework MessageBox.Show methods is that if you only display an &lt;strong&gt;ok&lt;/strong&gt; button, that button only takes up half of the width of the message box, so I fixed that in my MessageBoxService so that when there is only one button, it stretches to fit.&lt;/p&gt;

&lt;h2&gt;Adding the Message Box to the Current Page&lt;/h2&gt;

&lt;p&gt;The next part in the process is to actually inject the user interface for our custom message box into the current page. To achieve this, I keep use two properties: one to get the &lt;code&gt;PhoneApplicationFrame&lt;/code&gt; that holds the application content, and another that is updated every time the message box is shown which identifies the current &lt;code&gt;PhoneApplicationPage&lt;/code&gt;, as shown below.&lt;/p&gt;

&lt;div class="csharpcode"&gt;
  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; PhoneApplicationFrame RootFrame&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;{&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   3:  &lt;/span&gt;    get&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   4:  &lt;/span&gt;    {&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   5:  &lt;/span&gt;        &lt;span class="kwrd"&gt;if&lt;/span&gt; (&lt;span class="kwrd"&gt;null&lt;/span&gt; == &lt;span class="kwrd"&gt;this&lt;/span&gt;._frame)&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   6:  &lt;/span&gt;        {&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   7:  &lt;/span&gt;            &lt;span class="kwrd"&gt;this&lt;/span&gt;._frame = Application.Current.RootVisual &lt;span class="kwrd"&gt;as&lt;/span&gt; PhoneApplicationFrame;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   8:  &lt;/span&gt;        }&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   9:  &lt;/span&gt;&amp;#160;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  10:  &lt;/span&gt;        &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;this&lt;/span&gt;._frame;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  11:  &lt;/span&gt;    }&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  12:  &lt;/span&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;style type="text/css"&gt;














.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;div class="csharpcode"&gt;
  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; PhoneApplicationPage CurrentPage&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;{&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   3:  &lt;/span&gt;    get&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   4:  &lt;/span&gt;    {&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   5:  &lt;/span&gt;        &lt;span class="kwrd"&gt;if&lt;/span&gt; ((&lt;span class="kwrd"&gt;null&lt;/span&gt; == &lt;span class="kwrd"&gt;this&lt;/span&gt;._page) &amp;amp;&amp;amp;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   6:  &lt;/span&gt;            (&lt;span class="kwrd"&gt;null&lt;/span&gt; != &lt;span class="kwrd"&gt;this&lt;/span&gt;.RootFrame))&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   7:  &lt;/span&gt;        {&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   8:  &lt;/span&gt;            &lt;span class="kwrd"&gt;this&lt;/span&gt;._page = &lt;span class="kwrd"&gt;this&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   9:  &lt;/span&gt;                .RootFrame&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  10:  &lt;/span&gt;                .GetVisualDescendants()&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  11:  &lt;/span&gt;                .OfType&amp;lt;PhoneApplicationPage&amp;gt;()&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  12:  &lt;/span&gt;                .FirstOrDefault();&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  13:  &lt;/span&gt;            &lt;span class="kwrd"&gt;if&lt;/span&gt; (&lt;span class="kwrd"&gt;null&lt;/span&gt; == &lt;span class="kwrd"&gt;this&lt;/span&gt;._page)&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  14:  &lt;/span&gt;            {&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  15:  &lt;/span&gt;                &lt;span class="kwrd"&gt;this&lt;/span&gt;._page = &lt;span class="kwrd"&gt;this&lt;/span&gt;.RootFrame.Content &lt;span class="kwrd"&gt;as&lt;/span&gt; PhoneApplicationPage;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  16:  &lt;/span&gt;            }&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  17:  &lt;/span&gt;        }&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  18:  &lt;/span&gt;&amp;#160;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  19:  &lt;/span&gt;        &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;this&lt;/span&gt;._page;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  20:  &lt;/span&gt;    }&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  21:  &lt;/span&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;style type="text/css"&gt;













.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;&lt;strong&gt;NOTE:&lt;/strong&gt; The &lt;code&gt;GetVisualDescendants&lt;/code&gt; method is an extension method that is included in the code download.&lt;/p&gt;

&lt;p&gt;Once I’ve got the current page, I then find the first visual descendant of the page that is a &lt;code&gt;Panel&lt;/code&gt;, which is invariably a &lt;code&gt;Grid&lt;/code&gt; because of the templates that Visual Studio/Expression Blend provides.&lt;/p&gt;

&lt;div class="csharpcode"&gt;
  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;&lt;span class="kwrd"&gt;private&lt;/span&gt; Panel FindRootVisual()&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;{&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   3:  &lt;/span&gt;    &lt;span class="kwrd"&gt;if&lt;/span&gt; (&lt;span class="kwrd"&gt;null&lt;/span&gt; != &lt;span class="kwrd"&gt;this&lt;/span&gt;.CurrentPage)&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   4:  &lt;/span&gt;    {&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   5:  &lt;/span&gt;        &lt;span class="rem"&gt;// Return the first Panel element.&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   6:  &lt;/span&gt;        &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;this&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   7:  &lt;/span&gt;            .CurrentPage&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   8:  &lt;/span&gt;            .GetVisualDescendants()&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   9:  &lt;/span&gt;            .OfType&amp;lt;Panel&amp;gt;()&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  10:  &lt;/span&gt;            .FirstOrDefault();&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  11:  &lt;/span&gt;    }&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  12:  &lt;/span&gt;&amp;#160;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  13:  &lt;/span&gt;    &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;null&lt;/span&gt;;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  14:  &lt;/span&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;style type="text/css"&gt;











.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;If it is a &lt;code&gt;Grid&lt;/code&gt;, I set the &lt;code&gt;Grid.ColumnSpan&lt;/code&gt; and &lt;code&gt;Grid.RowSpan&lt;/code&gt; attached properties on my own root element (for the message box) so that it completely covers the page content.&lt;/p&gt;

&lt;div class="csharpcode"&gt;
  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;&lt;span class="rem"&gt;// Make sure that our grid spans all rows and columns of it's parent, if the&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;&lt;span class="rem"&gt;// parent is a Grid.&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   3:  &lt;/span&gt;&lt;span class="kwrd"&gt;if&lt;/span&gt; (rootVisual &lt;span class="kwrd"&gt;is&lt;/span&gt; Grid)&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   4:  &lt;/span&gt;{&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   5:  &lt;/span&gt;    var parent = (Grid)rootVisual;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   6:  &lt;/span&gt;    &lt;span class="kwrd"&gt;int&lt;/span&gt; columnCount = parent.ColumnDefinitions.Count;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   7:  &lt;/span&gt;    &lt;span class="kwrd"&gt;if&lt;/span&gt; (columnCount &amp;gt; 0)&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   8:  &lt;/span&gt;    {&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   9:  &lt;/span&gt;        &lt;span class="kwrd"&gt;this&lt;/span&gt;._rootElement.SetValue(&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  10:  &lt;/span&gt;            Grid.ColumnSpanProperty,&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  11:  &lt;/span&gt;            columnCount);&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  12:  &lt;/span&gt;    }&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  13:  &lt;/span&gt;&amp;#160;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  14:  &lt;/span&gt;    &lt;span class="kwrd"&gt;int&lt;/span&gt; rowCount = parent.RowDefinitions.Count;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  15:  &lt;/span&gt;    &lt;span class="kwrd"&gt;if&lt;/span&gt; (rowCount &amp;gt; 0)&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  16:  &lt;/span&gt;    {&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  17:  &lt;/span&gt;        &lt;span class="kwrd"&gt;this&lt;/span&gt;._rootElement.SetValue(&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  18:  &lt;/span&gt;            Grid.RowSpanProperty,&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  19:  &lt;/span&gt;            rowCount);&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  20:  &lt;/span&gt;    }&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  21:  &lt;/span&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;style type="text/css"&gt;











.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;Once we’ve done all that, it’s simply a matter of adding the root element of the message box user interface to the Children collection of the Panel element.&lt;/p&gt;

&lt;h2&gt;Animating the Message Box&lt;/h2&gt;

&lt;p&gt;The normal MessageBox animates in and out using an animation that appears to make the content “swivel” around it’s horizontal center. To be as consistent as possible I wanted to do the same thing. Fortunately, the awesome &lt;a href="http://blogs.claritycon.com/blog/author/kmarshall"&gt;Kevin Marshal&lt;/a&gt; has already done the hard work in this respect in his &lt;a href="http://blogs.claritycon.com/blog/2010/10/13/wp7-page-transitions-sample/"&gt;WP7 – Page Transitions Sample&lt;/a&gt; blog post. So, I added two Storyboards that are initialised in the constructor: one for the show animation and one for the hide animation. To the naked eye, the animations are virtually indistinguishable from the normal MessageBox.&lt;/p&gt;

&lt;p&gt;Once the message box user interface is added to the current page, I update the show Storyboard so that each part targets the correct element, and then start the animation on the first layout.&lt;/p&gt;

&lt;div class="csharpcode"&gt;
  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;&lt;span class="rem"&gt;// Update and start the storyboard to show the message box.&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;&lt;span class="kwrd"&gt;foreach&lt;/span&gt; (var timeline &lt;span class="kwrd"&gt;in&lt;/span&gt; &lt;span class="kwrd"&gt;this&lt;/span&gt;._showStoryboard.Children)&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   3:  &lt;/span&gt;{&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   4:  &lt;/span&gt;    Storyboard.SetTarget(timeline, &lt;span class="kwrd"&gt;this&lt;/span&gt;._mbsRoot);&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   5:  &lt;/span&gt;}&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   6:  &lt;/span&gt;&amp;#160;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   7:  &lt;/span&gt;&lt;span class="rem"&gt;// Once the elements are ready, start the storyboard to show them.&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   8:  &lt;/span&gt;&lt;span class="kwrd"&gt;this&lt;/span&gt;._mbsRoot.InvokeOnLayoutUpdated(() =&amp;gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   9:  &lt;/span&gt;{&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  10:  &lt;/span&gt;    &lt;span class="kwrd"&gt;this&lt;/span&gt;._showStoryboard.Begin();&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  11:  &lt;/span&gt;});&lt;/pre&gt;
&lt;/div&gt;
&lt;style type="text/css"&gt;










.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;&lt;strong&gt;NOTE:&lt;/strong&gt; The InvokeLayoutUpdated method is another extension method that is included in the code download.&lt;/p&gt;

&lt;h2&gt;Handling the Back Button&lt;/h2&gt;

&lt;p&gt;The next hurdle to overcome is handling the back button. With a page loaded, pressing the back button would normally navigate backwards through the page stack, but when a message box is displayed pressing the back button should dismiss the message box instead.&lt;/p&gt;

&lt;p&gt;Fortunately, I’ve already got a reference to the current page, so I use this to hook the &lt;code&gt;BackKeyPress&lt;/code&gt; event. In the handler I check to make sure that the message box is open, then cancel the back key press and close the message box.&lt;/p&gt;

&lt;div class="csharpcode"&gt;
  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;&lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; OnBackKeyPress(&lt;span class="kwrd"&gt;object&lt;/span&gt; sender, CancelEventArgs args)&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;{&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   3:  &lt;/span&gt;    &lt;span class="kwrd"&gt;if&lt;/span&gt; (&lt;span class="kwrd"&gt;true&lt;/span&gt; == &lt;span class="kwrd"&gt;this&lt;/span&gt;.IsOpen)&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   4:  &lt;/span&gt;    {&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   5:  &lt;/span&gt;        args.Cancel = &lt;span class="kwrd"&gt;true&lt;/span&gt;;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   6:  &lt;/span&gt;        &lt;span class="kwrd"&gt;this&lt;/span&gt;.Close();&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   7:  &lt;/span&gt;    }&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   8:  &lt;/span&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;style type="text/css"&gt;









.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;h2&gt;Closing the Message Box&lt;/h2&gt;

&lt;p&gt;Closing the message box is a fairly simple process that is initiated by setting the &lt;code&gt;Result&lt;/code&gt; property. The &lt;code&gt;Result&lt;/code&gt; property is a &lt;code&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.messageboxresult(v=VS.95).aspx"&gt;MessageBoxResult&lt;/a&gt;&lt;/code&gt; property and in the setter I call the &lt;code&gt;Close&lt;/code&gt; method. The close method does a bit of tidying up, makes sure that both storyboards are stopped, updates the target for the hide animation, and then starts the hide animation. Once the hide animation has completed I raise the &lt;code&gt;Closed&lt;/code&gt; event. Each of the buttons has it’s &lt;code&gt;Click&lt;/code&gt; event wired up to an event handler that sets the &lt;code&gt;Result&lt;/code&gt; property to the appropriate value.&lt;/p&gt;

&lt;div class="csharpcode"&gt;
  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;&lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Close()&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;{&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   3:  &lt;/span&gt;    &lt;span class="kwrd"&gt;this&lt;/span&gt;.IsOpen = &lt;span class="kwrd"&gt;false&lt;/span&gt;;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   4:  &lt;/span&gt;    &lt;span class="kwrd"&gt;this&lt;/span&gt;._showStoryboard.Stop();&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   5:  &lt;/span&gt;    &lt;span class="kwrd"&gt;this&lt;/span&gt;._hideStoryboard.Stop();&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   6:  &lt;/span&gt;    &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (var timeline &lt;span class="kwrd"&gt;in&lt;/span&gt; &lt;span class="kwrd"&gt;this&lt;/span&gt;._hideStoryboard.Children)&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   7:  &lt;/span&gt;    {&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   8:  &lt;/span&gt;        Storyboard.SetTarget(timeline, &lt;span class="kwrd"&gt;this&lt;/span&gt;._mbsRoot);&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   9:  &lt;/span&gt;    }&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  10:  &lt;/span&gt;&amp;#160;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  11:  &lt;/span&gt;    &lt;span class="kwrd"&gt;this&lt;/span&gt;._hideStoryboard.Completed += &lt;span class="kwrd"&gt;this&lt;/span&gt;.HideStoryboard_Complete;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  12:  &lt;/span&gt;    &lt;span class="kwrd"&gt;this&lt;/span&gt;._hideStoryboard.Begin();&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  13:  &lt;/span&gt;}&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  14:  &lt;/span&gt;&amp;#160;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  15:  &lt;/span&gt;&amp;#160;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  16:  &lt;/span&gt;&lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; HideStoryboard_Complete(&lt;span class="kwrd"&gt;object&lt;/span&gt; sender, EventArgs e)&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  17:  &lt;/span&gt;{&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  18:  &lt;/span&gt;    &lt;span class="kwrd"&gt;if&lt;/span&gt; (&lt;span class="kwrd"&gt;null&lt;/span&gt; != &lt;span class="kwrd"&gt;this&lt;/span&gt;._hideStoryboard)&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  19:  &lt;/span&gt;    {&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  20:  &lt;/span&gt;        &lt;span class="kwrd"&gt;this&lt;/span&gt;._hideStoryboard.Completed -= &lt;span class="kwrd"&gt;this&lt;/span&gt;.HideStoryboard_Complete;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  21:  &lt;/span&gt;    }&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  22:  &lt;/span&gt;&amp;#160;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  23:  &lt;/span&gt;    &lt;span class="kwrd"&gt;this&lt;/span&gt;.RaiseClosed();&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  24:  &lt;/span&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;style type="text/css"&gt;







.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;h2&gt;Using the MessageBoxService&lt;/h2&gt;

&lt;p&gt;So far I’ve covered the major points of the MessageBoxService implementation, but not now to use it. The MessageBoxService class exposes a single &lt;code&gt;Show&lt;/code&gt; method, a &lt;code&gt;Result&lt;/code&gt; property, and a &lt;code&gt;Closed&lt;/code&gt; event. You call &lt;code&gt;Show&lt;/code&gt;, wait for the &lt;code&gt;Closed&lt;/code&gt; event to fire, and then check the value of the &lt;code&gt;Result&lt;/code&gt; property as the following code snippet shows.&lt;/p&gt;

&lt;div class="csharpcode"&gt;
  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;&lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; MessageBoxService_Click(&lt;span class="kwrd"&gt;object&lt;/span&gt; sender, RoutedEventArgs e)&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;{&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   3:  &lt;/span&gt;    &lt;span class="kwrd"&gt;this&lt;/span&gt;._service.Closed += &lt;span class="kwrd"&gt;this&lt;/span&gt;.MessageBoxService_Closed;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   4:  &lt;/span&gt;    &lt;span class="kwrd"&gt;this&lt;/span&gt;._service.Show(&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   5:  &lt;/span&gt;        &lt;span class="kwrd"&gt;this&lt;/span&gt;._message.Text,&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   6:  &lt;/span&gt;        &lt;span class="kwrd"&gt;this&lt;/span&gt;._caption.Text,&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   7:  &lt;/span&gt;        MessageBoxServiceButton.YesNoCancel);&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   8:  &lt;/span&gt;}&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   9:  &lt;/span&gt;&amp;#160;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  10:  &lt;/span&gt;&lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; MessageBoxService_Closed(&lt;span class="kwrd"&gt;object&lt;/span&gt; sender, EventArgs e)&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  11:  &lt;/span&gt;{&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  12:  &lt;/span&gt;    &lt;span class="kwrd"&gt;this&lt;/span&gt;._service.Closed -= &lt;span class="kwrd"&gt;this&lt;/span&gt;.MessageBoxService_Closed;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  13:  &lt;/span&gt;    &lt;span class="kwrd"&gt;this&lt;/span&gt;._result.Text = &lt;span class="kwrd"&gt;this&lt;/span&gt;._service.Result.ToString();&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  14:  &lt;/span&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;style type="text/css"&gt;




.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;You can also customize the button labels (which was one of my original goals) by passing in a List&amp;lt;string&amp;gt; of button labels. When the MessageBoxService creates the buttons it checks to see if a custom label has been provided and uses that instead. The other labels are stored in a Resources file to make localization easier.&lt;/p&gt;

&lt;p&gt;The following code example shows how to specify custom button labels. Each label is used to replace the corresponding button in the supplied &lt;code&gt;MessageBoxServiceButton&lt;/code&gt; enumeration value. In the following example, &lt;strong&gt;abort&lt;/strong&gt; corresponds to &lt;strong&gt;yes&lt;/strong&gt; and the &lt;code&gt;Result&lt;/code&gt; property will be &lt;code&gt;MessageBoxResult.Yes&lt;/code&gt;, &lt;strong&gt;and retry&lt;/strong&gt; corresponds to &lt;strong&gt;no&lt;/strong&gt; and the &lt;code&gt;Result&lt;/code&gt; property will be &lt;code&gt;MessageBoxResult.No&lt;/code&gt;.&lt;/p&gt;

&lt;div class="csharpcode"&gt;
  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;&lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; MessageBoxService_Click(&lt;span class="kwrd"&gt;object&lt;/span&gt; sender, RoutedEventArgs e)&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;{&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   3:  &lt;/span&gt;    &lt;span class="kwrd"&gt;this&lt;/span&gt;._service.Closed += &lt;span class="kwrd"&gt;this&lt;/span&gt;.MessageBoxService_Closed;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   4:  &lt;/span&gt;    &lt;span class="kwrd"&gt;this&lt;/span&gt;._service.Show(&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   5:  &lt;/span&gt;        &lt;span class="kwrd"&gt;this&lt;/span&gt;._message.Text,&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   6:  &lt;/span&gt;        &lt;span class="kwrd"&gt;this&lt;/span&gt;._caption.Text,&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   7:  &lt;/span&gt;        MessageBoxServiceButton.YesNoCancel&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   8:  &lt;/span&gt;        &lt;span class="kwrd"&gt;new&lt;/span&gt; List&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt; { &lt;span class="str"&gt;&amp;quot;abort&amp;quot;&lt;/span&gt;, &lt;span class="str"&gt;&amp;quot;retry&amp;quot;&lt;/span&gt;, &lt;span class="str"&gt;&amp;quot;cancel&amp;quot;&lt;/span&gt; });&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   9:  &lt;/span&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;style type="text/css"&gt;



.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;h2&gt;Known Issues&lt;/h2&gt;

&lt;p&gt;The standard MessageBox has better access to the operating system than us lowly developers do, so there are a couple of things that I wasn’t able to achieve in my MessageBoxService implementation:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;There is no sound played when the message box is shown. The sound files that the operating system uses have not (yet?) been made publicly available, so I wasn’t able to include this. You could use your own sound, but I opted to go without for now. If you want to add your own sound, or when the Metro sound files are released, you can play a sound by using the XNA &lt;code&gt;SoundEffect&lt;/code&gt; class, as described on &lt;a href="http://msdn.microsoft.com/en-us/library/bb195053.aspx"&gt;MSDN&lt;/a&gt;. &lt;/li&gt;

  &lt;li&gt;When the system tray is visible, I’ve got no way to blank it out like the standard message box does, so the system tray remains visible. In the application I was working on, the system tray wasn’t visible, so not a big deal for me, and unlikely to be a problem more generally, but it still niggles. &lt;/li&gt;

  &lt;li&gt;Similarly, there’s no way to extend the blanker overlay over the application bar, which is provided by the operating system. As a workaround for this, the MessageBoxService class remembers whether the application bar was visible when it was shown, and then hides it. When it is closed, the application bar is shown again. Again, not an ideal solution, but better than having an enabled application bar. &lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;Tips&lt;/h2&gt;

&lt;p&gt;A few other things I learned along the way:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;If you want to use a semi-bold font weight for the default Segoe font, you need to actually change the FontFamily to &lt;strong&gt;Segoe WP Semibold&lt;/strong&gt; (it’s used for the title of the message box). &lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;The Code&lt;/h2&gt;

&lt;p&gt;You can access the code from GitHub: &lt;a title="https://github.com/dereklakin/MessageBoxService" href="https://github.com/dereklakin/MessageBoxService"&gt;https://github.com/dereklakin/MessageBoxService&lt;/a&gt; or you can download a ZIP of the code from SkyDrive:&lt;/p&gt;
&lt;iframe style="padding-bottom: 0px; background-color: #fcfcfc; padding-left: 0px; width: 98px; padding-right: 0px; height: 115px; padding-top: 0px" title="Preview" marginheight="0" src="http://cid-c7e795d90fd8af29.office.live.com/embedicon.aspx/Code/MessageBoxService.zip" frameborder="0" marginwidth="0" scrolling="no"&gt;&lt;/iframe&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=eV1jAirsNak:2T6IEUCzBEY:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=eV1jAirsNak:2T6IEUCzBEY:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?i=eV1jAirsNak:2T6IEUCzBEY:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=eV1jAirsNak:2T6IEUCzBEY:oCFASsrFxfc"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?d=oCFASsrFxfc" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=eV1jAirsNak:2T6IEUCzBEY:Jwdi1b3fU3Q"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?d=Jwdi1b3fU3Q" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=eV1jAirsNak:2T6IEUCzBEY:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?i=eV1jAirsNak:2T6IEUCzBEY:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/cloudstore/~4/eV1jAirsNak" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/cloudstore/~3/eV1jAirsNak/customizing-messagebox-on-windows-phone.html</link><author>noreply@blogger.com (Derek Lakin)</author><thr:total>9</thr:total><feedburner:origLink>http://cloudstore.blogspot.com/2011/01/customizing-messagebox-on-windows-phone.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-804082557306552579.post-3085051261621736109</guid><pubDate>Thu, 28 Oct 2010 18:06:00 +0000</pubDate><atom:updated>2010-10-28T19:06:17.497+01:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">personal</category><category domain="http://www.blogger.com/atom/ns#">2011</category><category domain="http://www.blogger.com/atom/ns#">wp7</category><category domain="http://www.blogger.com/atom/ns#">Silverlight</category><title>New Year, New Start</title><description>&lt;p&gt;Today is the first day of Microsoft’s Professional Developer Conference (PDC), which is being hosted on Microsoft’s Campus in Seattle right now as I type. I’m really excited to be here at such an exciting time for Microsoft development, even more so having just been told by Steve Balmer that we’ll all be getting our very own Windows Phone 7 device and free registration in the Windows Phone 7 Application Marketplace!&lt;/p&gt;  &lt;p&gt;However, that’s not the reason of this post (though bragging was definitely a motivation). The other reason that I’m excited today was announced in a &lt;a href="http://twitter.com/#!/ingebretsen/status/29001674302"&gt;tweet&lt;/a&gt; from &lt;a href="http://nerdplusart.com"&gt;Robby Ingebretsen&lt;/a&gt; that no doubt got lost in amongst all the PDC tweets. He and I are really pleased to announce that at the start of 2011 I will be an employee of &lt;a href="http://thinkpixellab.com/"&gt;Pixel Lab&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;This is a fantastic opportunity for me and I’m really pleased to be able turn what has already been a successful contract relationship into a permanent fixture. Robby, &lt;a href="http://work.j832.com/"&gt;Kevin Moore&lt;/a&gt;, and &lt;a href="http://adamkinney.com/"&gt;Adam Kinney&lt;/a&gt; have been working on some great projects and I’ve worked on a few recently including Windows Phone 7 applications, Silverlight projects such as the &lt;a href="http://timheuer.com/blog/archive/2010/09/09/silverlight-jetpack-theme-released.aspx"&gt;JetPack&lt;/a&gt; theme and the &lt;a href="http://halo.xbox.com/en-us"&gt;HALO web site&lt;/a&gt;, and much more. 2011 is going to be a great year and I can’t for it to get here!&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=-QscqxxUImU:GYveP4eLGw8:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=-QscqxxUImU:GYveP4eLGw8:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?i=-QscqxxUImU:GYveP4eLGw8:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=-QscqxxUImU:GYveP4eLGw8:oCFASsrFxfc"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?d=oCFASsrFxfc" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=-QscqxxUImU:GYveP4eLGw8:Jwdi1b3fU3Q"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?d=Jwdi1b3fU3Q" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=-QscqxxUImU:GYveP4eLGw8:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?i=-QscqxxUImU:GYveP4eLGw8:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/cloudstore/~4/-QscqxxUImU" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/cloudstore/~3/-QscqxxUImU/new-year-new-start.html</link><author>noreply@blogger.com (Derek Lakin)</author><thr:total>2</thr:total><feedburner:origLink>http://cloudstore.blogspot.com/2010/10/new-year-new-start.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-804082557306552579.post-5534544884990787959</guid><pubDate>Fri, 22 Oct 2010 00:57:00 +0000</pubDate><atom:updated>2010-10-22T23:03:41.957+01:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">tool</category><category domain="http://www.blogger.com/atom/ns#">wp7</category><category domain="http://www.blogger.com/atom/ns#">.net</category><category domain="http://www.blogger.com/atom/ns#">CodeProject</category><category domain="http://www.blogger.com/atom/ns#">Silverlight</category><category domain="http://www.blogger.com/atom/ns#">Microsoft</category><title>Checking Your WP7 Application Capabilities</title><description>&lt;p$1&gt;If you’re doing Windows Phone 7 application development then part of the submission process replaces the capabilities in the manifest file with those capabilities that it actually requires. To potentially save yourself some time and testing effort, you should make sure that you fully test your application using the correct set of capabilities before it gets to the submission process. This step just got a little easier in the &lt;a href="http://www.microsoft.com/downloads/en/details.aspx?FamilyID=49B9D0C5-6597-4313-912A-F0CCA9C7D277&amp;amp;displaylang=en"&gt;Windows Phone Developer Tools October 2010 Update&lt;/a&gt;, which includes the &lt;a href="http://msdn.microsoft.com/en-us/library/gg180730(v=VS.92).aspx"&gt;Windows Phone Capability Detection Tool&lt;/a&gt;.&lt;br /&gt;
&lt;p$1&gt;You use the Capability Detection Tool against your application XAP file to verify which capabilities you actually need so that you can update your manifest accordingly. As the above MSDN article explains, it’s a command line tool which you use like this:&lt;br /&gt;
&lt;p$1&gt;&lt;code&gt;CapabilityDetection.exe Rules.xml [Path to bin folder]&lt;/code&gt; &lt;br /&gt;
&lt;p$1&gt;&lt;br /&gt;
&lt;p$1&gt;To make my life a little easier I turned this into an External Tool in Visual Studio. Just set the &lt;strong&gt;Command&lt;/strong&gt; to &lt;code&gt;C:\Program Files (x86)\Microsoft SDKs\Windows Phone\v7.0\Tools\CapDetect\CapabilityDetection.exe&lt;/code&gt;, the &lt;strong&gt;Arguments&lt;/strong&gt; to &lt;code&gt;Rules.xml $(BinDir)&lt;/code&gt;, and the &lt;strong&gt;InitialDirectory&lt;/strong&gt; to &lt;code&gt;C:\Program Files (x86)\Microsoft SDKs\Windows Phone\v7.0\Tools\CapDetect\&lt;/code&gt;. You should also check the &lt;strong&gt;Use Output Window&lt;/strong&gt; checkbox.&lt;br /&gt;
&lt;p$1&gt;The settings and example output are shown in the following picture.&lt;br /&gt;
&lt;p$1&gt;&lt;a href="http://www.flickr.com/photos/51035614344@N01/5103188665/" title="Capability Detection Tool"&gt;&lt;img alt="Capability Detection Tool" border="0" src="http://static.flickr.com/1221/5103188665_68a66bbb0e.jpg" /&gt;&lt;/a&gt;&lt;br /&gt;
&lt;p$1&gt;&lt;br /&gt;
&lt;h2&gt;

Update&lt;/h2&gt;
&lt;p$1&gt;&lt;strong&gt;Note&lt;/strong&gt;: Under some circumstances (such as local instantiation of a Uri) the capability detection tool will report the ID_CAP_NETWORKING capability. If you really don't need this capability you can safely remove it, but you should make sure you test fully after removing it.&lt;br /&gt;
&lt;p$1&gt;&lt;br /&gt;
&lt;h2&gt;

Aside&lt;/h2&gt;
&lt;p$1&gt;The October Update also includes the &lt;a href="http://go.microsoft.com/fwlink/?LinkId=204622"&gt;Windows Phone Connect Tool&lt;/a&gt;, which enables you to connect your phone to a PC when the Zune software is not running and debug applications that use media APIs and unspecified improvements to gesture performance when using the Bing Maps Silverlight control.&lt;/p$1&gt;&lt;/p$1&gt;&lt;/p$1&gt;&lt;/p$1&gt;&lt;/p$1&gt;&lt;/p$1&gt;&lt;/p$1&gt;&lt;/p$1&gt;&lt;/p$1&gt;&lt;/p$1&gt;&lt;/p$1&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=pQtkZeWntH8:_TaY66UV-GM:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=pQtkZeWntH8:_TaY66UV-GM:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?i=pQtkZeWntH8:_TaY66UV-GM:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=pQtkZeWntH8:_TaY66UV-GM:oCFASsrFxfc"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?d=oCFASsrFxfc" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=pQtkZeWntH8:_TaY66UV-GM:Jwdi1b3fU3Q"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?d=Jwdi1b3fU3Q" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=pQtkZeWntH8:_TaY66UV-GM:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?i=pQtkZeWntH8:_TaY66UV-GM:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/cloudstore/~4/pQtkZeWntH8" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/cloudstore/~3/pQtkZeWntH8/checking-your-wp7-application.html</link><author>noreply@blogger.com (Derek Lakin)</author><thr:total>0</thr:total><feedburner:origLink>http://cloudstore.blogspot.com/2010/10/checking-your-wp7-application.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-804082557306552579.post-3809450378327263436</guid><pubDate>Tue, 14 Sep 2010 01:14:00 +0000</pubDate><atom:updated>2010-10-22T23:03:27.529+01:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Facebook</category><category domain="http://www.blogger.com/atom/ns#">wp7</category><category domain="http://www.blogger.com/atom/ns#">.net</category><category domain="http://www.blogger.com/atom/ns#">CodeProject</category><category domain="http://www.blogger.com/atom/ns#">Silverlight</category><title>Clearing Cookies on Windows Phone 7 or How to Log Out of Facebook</title><description>&lt;p$1&gt;&lt;br /&gt;
&lt;p$1&gt;&lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
 font-size: small;
 color: black;
 font-family: consolas, "Courier New", courier, monospace;
 background-color: #ffffff;
 /*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
 background-color: #f4f4f4;
 width: 100%;
 margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;Like many people it seems I’ve been working on an application for Windows Phone 7 that integrates with &lt;a href="http://www.facebook.com/"&gt;Facebook&lt;/a&gt;. Now that I’m getting close to completion I was looking at the use cases that fall outside of the core area such as logging out of &lt;a href="http://www.facebook.com/"&gt;Facebook&lt;/a&gt; to enable the user to use different credentials. Traditionally, you’d get the cookies for the relevant &lt;a href="http://www.facebook.com/"&gt;Facebook&lt;/a&gt; URLs and clear them out. Many people on the forums appear to have hit the same problem that I did in that there is no direct API in Windows Phone 7 to access cookies for the &lt;a href="http://msdn.microsoft.com/en-us/library/microsoft.phone.controls.webbrowser(v=VS.92).aspx"&gt;WebBrowser&lt;/a&gt; control. I managed to find a way round this and here’s how I did it:&lt;br /&gt;
&lt;p$1&gt;&lt;br /&gt;
&lt;h2&gt;
Keeping Track of Cookies&lt;/h2&gt;
&lt;p$1&gt;&lt;br /&gt;
&lt;p$1&gt;There’s no direct API to get the cookies for the &lt;a href="http://msdn.microsoft.com/en-us/library/microsoft.phone.controls.webbrowser(v=VS.92).aspx"&gt;WebBrowser&lt;/a&gt; control, but you can get access to the cookies for a specific web request by providing a value for the &lt;a href="http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.cookiecontainer(v=VS.95).aspx"&gt;CookieContainer&lt;/a&gt; property:&lt;br /&gt;
&lt;p$1&gt;&lt;br /&gt;
&lt;div class="csharpcode"&gt;
&lt;p$1&gt;&lt;br /&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;&lt;span class="kwrd"&gt;private&lt;/span&gt; HttpWebRequest _webRequest;&lt;/pre&gt;
&lt;p$1&gt;&lt;br /&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;&lt;span class="kwrd"&gt;private&lt;/span&gt; CookieContainer _cookieContainer = &lt;span class="kwrd"&gt;new&lt;/span&gt; CookieContainer();&lt;/pre&gt;
&lt;p$1&gt;&lt;br /&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   3:  &lt;/span&gt;...&lt;/pre&gt;
&lt;p$1&gt;&lt;br /&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;   4:  &lt;/span&gt;&lt;span class="kwrd"&gt;this&lt;/span&gt;._webRequest = (HttpWebRequest)HttpWebRequest.Create(uri);&lt;/pre&gt;
&lt;p$1&gt;&lt;br /&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   5:  &lt;/span&gt;&lt;span class="kwrd"&gt;this&lt;/span&gt;._webRequest.CookieContainer = &lt;span class="kwrd"&gt;this&lt;/span&gt;._cookieContainer;&lt;/pre&gt;
&lt;p$1&gt;&lt;/p$1&gt;&lt;/p$1&gt;&lt;/p$1&gt;&lt;/p$1&gt;&lt;/p$1&gt;&lt;/p$1&gt;&lt;/div&gt;
&lt;p$1&gt;&lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
 font-size: small;
 color: black;
 font-family: consolas, "Courier New", courier, monospace;
 background-color: #ffffff;
 /*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
 background-color: #f4f4f4;
 width: 100%;
 margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;

&lt;br /&gt;
&lt;p$1&gt;What you’ll notice here is that I’m creating an &lt;a href="http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest(v=VS.95).aspx"&gt;HttpWebRequest&lt;/a&gt; and an associated &lt;a href="http://msdn.microsoft.com/en-us/library/fkh73a15(v=VS.95).aspx"&gt;CookieContainer&lt;/a&gt; and passing that &lt;a href="http://msdn.microsoft.com/en-us/library/fkh73a15(v=VS.95).aspx"&gt;CookieContainer&lt;/a&gt; to the web request. What you’ll need to do is to keep hold of this web request for the lifetime of your application, or at the very least keep hold of the last web request that you used to access &lt;a href="http://www.facebook.com/"&gt;Facebook&lt;/a&gt; (depending on how busy your application is and what you’re doing with web requests. I managed to change my application code to use a single web request for the whole application lifetime). Then you can use the &lt;a href="http://msdn.microsoft.com/en-us/library/fkh73a15(v=VS.95).aspx"&gt;CookieContainer&lt;/a&gt; instance to find the relevant cookies.&lt;br /&gt;
&lt;p$1&gt;&lt;br /&gt;
&lt;h2&gt;
Finding and Clearing Facebook’s Cookies&lt;/h2&gt;
&lt;p$1&gt;&lt;br /&gt;
&lt;p$1&gt;In order to track down &lt;a href="http://www.facebook.com/"&gt;Facebook’s&lt;/a&gt; cookies so that you can clear them out you need to ask the &lt;a href="http://msdn.microsoft.com/en-us/library/fkh73a15(v=VS.95).aspx"&gt;CookieContainer&lt;/a&gt; for the cookies that match a certain URL. I found that asking for &lt;a href="https://login.facebook.com/login.php" title="https://login.facebook.com/login.php"&gt;https://login.facebook.com/login.php&lt;/a&gt; was all I needed to do, but your mileage may vary. I use this code in my WebClientHelper class (which holds my web request) to clear cookies for a specified URL:&lt;br /&gt;
&lt;p$1&gt;&lt;br /&gt;
&lt;div class="csharpcode"&gt;
&lt;p$1&gt;&lt;br /&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; ClearCookies(Uri uri)&lt;/pre&gt;
&lt;p$1&gt;&lt;br /&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;{&lt;/pre&gt;
&lt;p$1&gt;&lt;br /&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   3:  &lt;/span&gt;    var cookies = &lt;span class="kwrd"&gt;this&lt;/span&gt;._cookieContainer.GetCookies(uri);&lt;/pre&gt;
&lt;p$1&gt;&lt;br /&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;   4:  &lt;/span&gt;    &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (Cookie cookie &lt;span class="kwrd"&gt;in&lt;/span&gt; cookies)&lt;/pre&gt;
&lt;p$1&gt;&lt;br /&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   5:  &lt;/span&gt;    {&lt;/pre&gt;
&lt;p$1&gt;&lt;br /&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;   6:  &lt;/span&gt;        cookie.Discard = &lt;span class="kwrd"&gt;true&lt;/span&gt;;&lt;/pre&gt;
&lt;p$1&gt;&lt;br /&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   7:  &lt;/span&gt;        cookie.Expired = &lt;span class="kwrd"&gt;true&lt;/span&gt;;&lt;/pre&gt;
&lt;p$1&gt;&lt;br /&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;   8:  &lt;/span&gt;    }&lt;/pre&gt;
&lt;p$1&gt;&lt;br /&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   9:  &lt;/span&gt;}&lt;/pre&gt;
&lt;p$1&gt;&lt;/p$1&gt;&lt;/p$1&gt;&lt;/p$1&gt;&lt;/p$1&gt;&lt;/p$1&gt;&lt;/p$1&gt;&lt;/p$1&gt;&lt;/p$1&gt;&lt;/p$1&gt;&lt;/p$1&gt;&lt;/div&gt;
&lt;p$1&gt;&lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
 font-size: small;
 color: black;
 font-family: consolas, "Courier New", courier, monospace;
 background-color: #ffffff;
 /*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
 background-color: #f4f4f4;
 width: 100%;
 margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;

&lt;br /&gt;
&lt;p$1&gt;I found that setting both the &lt;a href="http://msdn.microsoft.com/en-us/library/system.net.cookie.discard(v=VS.95).aspx"&gt;Discard&lt;/a&gt; and &lt;a href="http://msdn.microsoft.com/en-us/library/system.net.cookie.expired(v=VS.95).aspx"&gt;Expired&lt;/a&gt; properties to true was sufficient to clear the cookies. It may well be that either one of them on their own is adequate; I haven’t had the opportunity to verify that.&lt;br /&gt;
&lt;p$1&gt;&lt;br /&gt;
&lt;p$1&gt;So, the code that calls this method looks like this:&lt;br /&gt;
&lt;p$1&gt;&lt;br /&gt;
&lt;div class="csharpcode"&gt;
&lt;p$1&gt;&lt;br /&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;&lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;readonly&lt;/span&gt; Uri FacebookCookieUri = &lt;span class="kwrd"&gt;new&lt;/span&gt; Uri(&lt;span class="str"&gt;"https://login.facebook.com/login.php"&lt;/span&gt;);&lt;/pre&gt;
&lt;p$1&gt;&lt;br /&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;...&lt;/pre&gt;
&lt;p$1&gt;&lt;br /&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   3:  &lt;/span&gt;&lt;span class="kwrd"&gt;this&lt;/span&gt;._helper.ClearCookies(FacebookCookieUri);&lt;/pre&gt;
&lt;p$1&gt;&lt;/p$1&gt;&lt;/p$1&gt;&lt;/p$1&gt;&lt;/p$1&gt;&lt;/div&gt;
&lt;p$1&gt;&lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
 font-size: small;
 color: black;
 font-family: consolas, "Courier New", courier, monospace;
 background-color: #ffffff;
 /*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
 background-color: #f4f4f4;
 width: 100%;
 margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;

&lt;br /&gt;
&lt;p$1&gt;If you then send the &lt;a href="http://msdn.microsoft.com/en-us/library/microsoft.phone.controls.webbrowser(v=VS.92).aspx"&gt;WebBrowser&lt;/a&gt; control to the login URL for &lt;a href="http://www.facebook.com/"&gt;Facebook&lt;/a&gt; as you would normally, then you should find that the cookies are cleared and the user is presented with the login dialog as usual.&lt;br /&gt;
&lt;p$1&gt;&lt;br /&gt;
&lt;p$1&gt;I hope this helps.&lt;br /&gt;
&lt;p$1&gt;&lt;/p$1&gt;&lt;/p$1&gt;&lt;/p$1&gt;&lt;/p$1&gt;&lt;/p$1&gt;&lt;/p$1&gt;&lt;/p$1&gt;&lt;/p$1&gt;&lt;/p$1&gt;&lt;/p$1&gt;&lt;/p$1&gt;&lt;/p$1&gt;&lt;/p$1&gt;&lt;/p$1&gt;&lt;/p$1&gt;&lt;/p$1&gt;&lt;/p$1&gt;&lt;/p$1&gt;&lt;/p$1&gt;&lt;/p$1&gt;&lt;/p$1&gt;&lt;/p$1&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=fIahBhZoIUg:n1RPYCH9aqs:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=fIahBhZoIUg:n1RPYCH9aqs:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?i=fIahBhZoIUg:n1RPYCH9aqs:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=fIahBhZoIUg:n1RPYCH9aqs:oCFASsrFxfc"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?d=oCFASsrFxfc" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=fIahBhZoIUg:n1RPYCH9aqs:Jwdi1b3fU3Q"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?d=Jwdi1b3fU3Q" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=fIahBhZoIUg:n1RPYCH9aqs:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?i=fIahBhZoIUg:n1RPYCH9aqs:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/cloudstore/~4/fIahBhZoIUg" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/cloudstore/~3/fIahBhZoIUg/clearing-cookies-on-windows-phone-7-or.html</link><author>noreply@blogger.com (Derek Lakin)</author><thr:total>16</thr:total><feedburner:origLink>http://cloudstore.blogspot.com/2010/09/clearing-cookies-on-windows-phone-7-or.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-804082557306552579.post-1447100097504239839</guid><pubDate>Mon, 07 Dec 2009 15:03:00 +0000</pubDate><atom:updated>2009-12-07T15:03:53.140Z</atom:updated><category domain="http://www.blogger.com/atom/ns#">WPF</category><category domain="http://www.blogger.com/atom/ns#">.net</category><category domain="http://www.blogger.com/atom/ns#">threads</category><category domain="http://www.blogger.com/atom/ns#">c#</category><category domain="http://www.blogger.com/atom/ns#">UI</category><title>Application.DoEvents in WPF</title><description>&lt;p&gt;Recently I’ve been trying to make some thumbnail generation code synchronous. I’m trying to grab the first frame from a Shockwave Flash (SWF) or Flash Video (FLV) file and save it as a thumbnail, but in order to do that I needed to create a Window to host an ActiveX control that renders the Flash file so that I can then use a RenderTargetBitmap to grab a frame.&lt;/p&gt;  &lt;p&gt;The code sits inside a handler for the ContentRendered event of the Window and is initialised something like this:&lt;/p&gt;  &lt;div class="csharpcode"&gt;   &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;bool&lt;/span&gt; CreateThumbnail(&lt;span class="kwrd"&gt;string&lt;/span&gt; sourcePath, &lt;span class="kwrd"&gt;string&lt;/span&gt; targetPath)&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;{&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   3:  &lt;/span&gt;    &lt;span class="rem"&gt;// NOTE: Loads of code missed for brevity.&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   4:  &lt;/span&gt;    ManualResetEvent waitHandle = &lt;span class="kwrd"&gt;new&lt;/span&gt; ManualResetEvent(&lt;span class="kwrd"&gt;false&lt;/span&gt;);&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   5:  &lt;/span&gt;    &lt;span class="kwrd"&gt;bool&lt;/span&gt; generated = &lt;span class="kwrd"&gt;false&lt;/span&gt;;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   6:  &lt;/span&gt;&amp;#160;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   7:  &lt;/span&gt;    var win = &lt;span class="kwrd"&gt;new&lt;/span&gt; Window()&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   8:  &lt;/span&gt;    {&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   9:  &lt;/span&gt;        AllowsTransparency = &lt;span class="kwrd"&gt;true&lt;/span&gt;,&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  10:  &lt;/span&gt;        Opacity = 0.0,&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  11:  &lt;/span&gt;        Left = 0,&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  12:  &lt;/span&gt;        Top = 0,&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  13:  &lt;/span&gt;        SizeToContent = SizeToContent.WidthAndHeight,&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  14:  &lt;/span&gt;        ShowInTaskbar = &lt;span class="kwrd"&gt;false&lt;/span&gt;,&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  15:  &lt;/span&gt;        WindowStyle = WindowStyle.None&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  16:  &lt;/span&gt;    };&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  17:  &lt;/span&gt;    win.ContentRendered += (sender, e) =&amp;gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  18:  &lt;/span&gt;    {&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  19:  &lt;/span&gt;        &lt;span class="rem"&gt;// Use RenderTargetBitmap to get the frame and save it.&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  20:  &lt;/span&gt;        generated = &lt;span class="kwrd"&gt;true&lt;/span&gt;;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  21:  &lt;/span&gt;        waitHandle.Set();&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  22:  &lt;/span&gt;    }&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  23:  &lt;/span&gt;&amp;#160;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  24:  &lt;/span&gt;    win.Show();&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  25:  &lt;/span&gt;    waitHandle.WaitOne(5000);&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  26:  &lt;/span&gt;    &lt;span class="kwrd"&gt;return&lt;/span&gt; generated;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  27:  &lt;/span&gt;}&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;&lt;style type="text/css"&gt;

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;&lt;/p&gt;

&lt;p&gt;The problem is that the ContentRendered event doesn’t fire until after the WaitOne call on the ManualResetEvent, effectively meaning that thumbnail generation fails all the time. Basically, the UI thread is blocked waiting for the wait handle to be signalled, so it doesn’t get round to rendering the Window until after this method has called.&lt;/p&gt;

&lt;p&gt;For VB programmers out there, you may be thinking that you simply call Application.DoEvents() to free up the message loop and unfortunately WPF doesn’t provide the same API. However, there is a way to do this in WPF. By pushing a nested message loop we can cause this nested message loop to be processed immediately, allowing the Window’s content to be rendered and our thumbnail to be generated. I wouldn’t recommend using nested message loops and neither would many other people, but in this case it works for me. All I needed to do was to add the following line of code between the win.Show() call and the waitHandle.WaitOne(5000) call above:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;Application.Current.Dispatcher.Invoke(
    DispatcherPriority.Background, 
    &lt;span class="kwrd"&gt;new&lt;/span&gt; ThreadStart(&lt;span class="kwrd"&gt;delegate&lt;/span&gt; { }));&lt;/pre&gt;
&lt;style type="text/css"&gt;

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;Thanks to &lt;a href="http://shevaspace.spaces.live.com/blog/cns!FD9A0F1F8DD06954!526.entry#trackback" target="_blank"&gt;Zhou Young’s post&lt;/a&gt; for the simplest implementation of DoEvents in WPF that I’ve seen. As you can see, he’s put it in his Application class, but personally I think that’s just encouraging you to use this approach and in most cases I think there’s a better solution for you.&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=CgTUvjJD0Is:mluQ2W3ScOI:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=CgTUvjJD0Is:mluQ2W3ScOI:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?i=CgTUvjJD0Is:mluQ2W3ScOI:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=CgTUvjJD0Is:mluQ2W3ScOI:oCFASsrFxfc"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?d=oCFASsrFxfc" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=CgTUvjJD0Is:mluQ2W3ScOI:Jwdi1b3fU3Q"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?d=Jwdi1b3fU3Q" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=CgTUvjJD0Is:mluQ2W3ScOI:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?i=CgTUvjJD0Is:mluQ2W3ScOI:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/cloudstore/~4/CgTUvjJD0Is" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/cloudstore/~3/CgTUvjJD0Is/applicationdoevents-in-wpf.html</link><author>noreply@blogger.com (Derek Lakin)</author><thr:total>0</thr:total><feedburner:origLink>http://cloudstore.blogspot.com/2009/12/applicationdoevents-in-wpf.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-804082557306552579.post-1486459125570372088</guid><pubDate>Fri, 04 Dec 2009 10:46:00 +0000</pubDate><atom:updated>2009-12-04T10:49:53.597Z</atom:updated><category domain="http://www.blogger.com/atom/ns#">2010</category><category domain="http://www.blogger.com/atom/ns#">software</category><category domain="http://www.blogger.com/atom/ns#">office</category><category domain="http://www.blogger.com/atom/ns#">beta</category><category domain="http://www.blogger.com/atom/ns#">Microsoft</category><title>Installing Office 2010 Beta – Part 2</title><description>&lt;p&gt;After eventually managing to get Office 2010 Beta to install as described in my &lt;a href="http://cloudstore.blogspot.com/2009/11/installing-office-2010-beta.html" target="_blank"&gt;previous post&lt;/a&gt;, I then had problems with the actual applications themselves such that every time I tried to run one of the applications it would go through a lengthy configuration process, so I posted some &lt;a href="https://connect.microsoft.com/office/feedback/ViewFeedback.aspx?FeedbackID=514357#details" target="_blank"&gt;feedback&lt;/a&gt; on the Microsoft Connect site and have been dealing with Sean Francis at Microsoft since to try and resolve my problems.&lt;/p&gt;  &lt;h3&gt;Uninstalling Office&lt;/h3&gt;  &lt;p&gt;One thing that I have learnt along the way is that my previous suggestion of using the Windows Installer CleanUp Utility is a bit outdated. Office 2007 and above no longer uses a single MSI for the installation, instead they use multiple MSIs and in actual fact, the Installer CleanUp Utility doesn’t delete any files, it just removes registry entries.&lt;/p&gt;  &lt;p&gt;I don’t know if there’s an officially supported approach to cleaning up previous versions of Office, but Sean was good enough to attach a couple of VB scripts to the feedback item on Microsoft Connect. One of them is for cleaning Office 2007 and the other is for cleaning Office 2010 (scroll down to just above the comments to find the attached files).&lt;/p&gt;  &lt;p&gt;Run the relevant script from a command prompt (if you have UAC enabled, make sure you open the command prompt as Administrator) and replace the text in the prompt with “ALL, OSE” (without the quotes) and then let it do it’s funky thing.&lt;/p&gt;  &lt;h3&gt;Installing Again&lt;/h3&gt;  &lt;p&gt;After successfully uninstalling Office 2007, then Office 2010, I was ready to install Office 2010 Beta again, but unfortunately my problems didn’t end here :(&lt;/p&gt;  &lt;p&gt;&lt;a title="Office 2010 Installation Failure" href="http://www.flickr.com/photos/51035614344@N01/4157023191/"&gt;&lt;img style="display: inline; margin-left: 0px; margin-right: 0px" border="0" alt="Office 2010 Installation Failure" align="right" src="http://static.flickr.com/2578/4157023191_d96d392c5e_m.jpg" /&gt;&lt;/a&gt;My problem now was all down to registry permissions. For some bizarre reason, there were a number of registry keys that the Office installation was trying to access that simply didn’t have any permissions, hence the problem as shown in this image.&lt;/p&gt;  &lt;p&gt;After a lot more to-ing and fro-ing with Sean, I ended up having to manually take ownership of the parent key, then add my user account with Full Control to the parent key and it’s sub-keys and then deleting the key.&lt;/p&gt;  &lt;p&gt;(NOTE: Sean managed to work out that the key in question was: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Components, in case you’re interested.)&lt;/p&gt;  &lt;p&gt;After six attempts at doing this with a different problem key every time, I decided to try something slightly different; I took ownership of the Components key one level up and then added my user account with Full Control to that key and all sub-keys. Although RegEdit said that it didn’t manage it on all sub-keys, I carried on any way and thankfully the install completed successfully this time and thankfully, there were no more post-install configuration problems either!&lt;/p&gt;  &lt;h3&gt;Summary&lt;/h3&gt;  &lt;p&gt;To install Office 2010 Beta in the first place, you need to make sure you’ve purged Office 2007 and Office 2010 CTP from your system, which you should do using the scripts attached to my &lt;a href="https://connect.microsoft.com/office/feedback/ViewFeedback.aspx?FeedbackID=514357#details" target="_blank"&gt;feedback&lt;/a&gt; on the Microsoft Connect site.&lt;/p&gt;  &lt;p&gt;If your install fails because of registry permissions as described above, take ownership of the Components key, add your user account with Full Control to it and all sub-leys, then retry the installation.&lt;/p&gt;  &lt;p&gt;Once you’ve done either or both of the above, you should be good to go.&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=-bt6jG8VDDs:Kq5QITrYbh4:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=-bt6jG8VDDs:Kq5QITrYbh4:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?i=-bt6jG8VDDs:Kq5QITrYbh4:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=-bt6jG8VDDs:Kq5QITrYbh4:oCFASsrFxfc"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?d=oCFASsrFxfc" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=-bt6jG8VDDs:Kq5QITrYbh4:Jwdi1b3fU3Q"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?d=Jwdi1b3fU3Q" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=-bt6jG8VDDs:Kq5QITrYbh4:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?i=-bt6jG8VDDs:Kq5QITrYbh4:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/cloudstore/~4/-bt6jG8VDDs" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/cloudstore/~3/-bt6jG8VDDs/installing-office-2010-beta-part-2.html</link><author>noreply@blogger.com (Derek Lakin)</author><thr:total>4</thr:total><feedburner:origLink>http://cloudstore.blogspot.com/2009/12/installing-office-2010-beta-part-2.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-804082557306552579.post-2713162519895680661</guid><pubDate>Wed, 18 Nov 2009 08:25:00 +0000</pubDate><atom:updated>2009-12-04T10:48:12.827Z</atom:updated><category domain="http://www.blogger.com/atom/ns#">2010</category><category domain="http://www.blogger.com/atom/ns#">software</category><category domain="http://www.blogger.com/atom/ns#">office</category><category domain="http://www.blogger.com/atom/ns#">beta</category><category domain="http://www.blogger.com/atom/ns#">Microsoft</category><title>Installing Office 2010 Beta</title><description>&lt;h3&gt;Update&lt;/h3&gt;  &lt;p&gt;If you’re having trouble removing Office 2007/2010 CTP, don’t use the Windows Installer CleanUp Utility. See my &lt;a href="http://cloudstore.blogspot.com/2009/12/installing-office-2010-beta-part-2.html" target="_blank"&gt;subsequent post&lt;/a&gt; for updated information.&lt;/p&gt;  &lt;hr /&gt;  &lt;p&gt;The beta release of Office 2010 was released yesterday on MSDN, Technet, and Connect, so like a good geek I rushed out and downloaded it. First things first, if you have the Community Technology Preview installed, you’ll need to uninstall it, which I did. However, after doing that and rebooting I still got the following error message:&lt;/p&gt;  &lt;p&gt;&lt;a title="Setup Errors When Installing Office 2010 Beta" href="http://www.flickr.com/photos/51035614344@N01/4113823235/"&gt;&lt;img border="0" alt="Setup Errors When Installing Office 2010 Beta" src="http://static.flickr.com/2747/4113823235_315e3938d3.jpg" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;As we had already established “Microsoft Office 2010 does not support upgrading from a pre-release version of Microsoft Office 2010.” so I was at a bit of a loss as to the cause of the problem.&lt;/p&gt;  &lt;p&gt;To cut a long (and stressful) story short, I downloaded the &lt;a href="http://support.microsoft.com/kb/290301" target="_blank"&gt;Windows Installer CleanUp Utility&lt;/a&gt; and managed to locate and uninstall a couple of stray Office 2007 components that still existed but weren’t listed in Control Panel and voila! It worked. Hopefully this post will save a few other people some time and hassle.&lt;/p&gt;  &lt;h3&gt;P.S.&lt;/h3&gt;  &lt;p&gt;I had the same problem with the 64-bit version of Office 2010 Beta, but decided against installing, because it won’t work with 32-bit plug-ins and I think it will be a while before any of the applications that I have that integrate with office produce a 64-bit version of their plug-ins.&lt;/p&gt;  &lt;h3&gt;Product Activation Failed&lt;/h3&gt;  &lt;p&gt;After successfully getting Office 2010 installed (watch out for the Junk Email Filter Update in the Windows Installer CleanUp Utility list) the next problem was that I got a “Product Activation Failed” message for all of the applications. The solution to this problem is thankfully much simpler: Go to Control Panel and choose to “Change” the application (rather than Uninstall). In the dialog box, select “Enter a Product Key” and provide the key that you have (from MSDN/TechNet/Connect) and then carry on (click “Continue” until the end). Another problem solved.&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=4-DAPMv-uTU:z6x1jL_IS5w:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=4-DAPMv-uTU:z6x1jL_IS5w:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?i=4-DAPMv-uTU:z6x1jL_IS5w:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=4-DAPMv-uTU:z6x1jL_IS5w:oCFASsrFxfc"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?d=oCFASsrFxfc" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=4-DAPMv-uTU:z6x1jL_IS5w:Jwdi1b3fU3Q"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?d=Jwdi1b3fU3Q" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=4-DAPMv-uTU:z6x1jL_IS5w:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?i=4-DAPMv-uTU:z6x1jL_IS5w:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/cloudstore/~4/4-DAPMv-uTU" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/cloudstore/~3/4-DAPMv-uTU/installing-office-2010-beta.html</link><author>noreply@blogger.com (Derek Lakin)</author><thr:total>11</thr:total><feedburner:origLink>http://cloudstore.blogspot.com/2009/11/installing-office-2010-beta.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-804082557306552579.post-4168923958657022852</guid><pubDate>Thu, 11 Jun 2009 09:17:00 +0000</pubDate><atom:updated>2009-06-12T07:45:36.687+01:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">WPF</category><category domain="http://www.blogger.com/atom/ns#">.net</category><category domain="http://www.blogger.com/atom/ns#">CodeProject</category><category domain="http://www.blogger.com/atom/ns#">UI</category><category domain="http://www.blogger.com/atom/ns#">controls</category><title>Free WPF DataGrid from Xceed</title><description>&lt;p&gt;I just registered for the free Xceed DataGrid for WPF, and there’s only 3 days left to do it. &lt;a href="http://xceed.com/freegrid"&gt;http://xceed.com/freegrid&lt;/a&gt;. Get it now before it becomes the Standard Edition priced at $300 and get a free upgrade to the Standard Edition!&lt;/p&gt;&lt;div class="wlWriterHeaderFooter" style="margin:0px; padding:0px 0px 0px 0px;"&gt;This work is licensed under a &lt;a href="http://creativecommons.org/licenses/by/3.0/"&gt;Creative Commons Attribution By license.&lt;/a&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=BgnDeeGt8y0:b9nBAa9rjvI:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=BgnDeeGt8y0:b9nBAa9rjvI:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?i=BgnDeeGt8y0:b9nBAa9rjvI:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=BgnDeeGt8y0:b9nBAa9rjvI:oCFASsrFxfc"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?d=oCFASsrFxfc" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=BgnDeeGt8y0:b9nBAa9rjvI:Jwdi1b3fU3Q"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?d=Jwdi1b3fU3Q" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=BgnDeeGt8y0:b9nBAa9rjvI:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?i=BgnDeeGt8y0:b9nBAa9rjvI:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/cloudstore/~4/BgnDeeGt8y0" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/cloudstore/~3/BgnDeeGt8y0/free-wpf-datagrid-from-xceed.html</link><author>noreply@blogger.com (Derek Lakin)</author><thr:total>0</thr:total><feedburner:origLink>http://cloudstore.blogspot.com/2009/06/free-wpf-datagrid-from-xceed.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-804082557306552579.post-3248548025815787442</guid><pubDate>Wed, 10 Jun 2009 16:26:00 +0000</pubDate><atom:updated>2009-06-12T07:45:26.680+01:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">dependency properties</category><category domain="http://www.blogger.com/atom/ns#">.net</category><category domain="http://www.blogger.com/atom/ns#">CodeProject</category><category domain="http://www.blogger.com/atom/ns#">testing</category><category domain="http://www.blogger.com/atom/ns#">c#</category><category domain="http://www.blogger.com/atom/ns#">Visual Studio</category><category domain="http://www.blogger.com/atom/ns#">attached properties</category><title>Testing Private Members in Visual Studio</title><description>&lt;p&gt;I’m currently working on a &lt;code&gt;CommandBehaviour&lt;/code&gt; class to enable me to fire commands in response to arbitrary routed events on elements that don’t natively support commands, inspired by Sacha Barber’s post &lt;a title="WPF: Attached Commands" href="http://sachabarber.net/?p=514"&gt;WPF: Attached Commands&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;Whilst trying to apply some unit tests to what I’m writing I came across the age old problem of how to test things which are private by design. Under normal circumstances I would probably have made them protected and written a &lt;code&gt;TestableCommandBehaviour&lt;/code&gt; class in the test project that inherits from &lt;code&gt;CommandBehaviour&lt;/code&gt; and exposes the protected members that I wanted to test.&lt;/p&gt;  &lt;p&gt;However, in this particular instance, I’d already written the code so I used the &lt;a title="Create Unit Tests" href="http://msdn.microsoft.com/en-us/library/ms182524.aspx"&gt;Create Unit Tests&lt;/a&gt; feature in Visual Studio to generate some unit tests for me to get me started. What I didn’t realise before was that when you do this, it creates a “Test Reference”, which provides you with a &lt;em&gt;private accessor&lt;/em&gt; that you use to access the private code*.&lt;/p&gt;  &lt;p&gt;Here’s a cut down version of the &lt;code&gt;CommandBehaviour&lt;/code&gt; class:&lt;/p&gt;  &lt;div class="csharpcode"&gt;   &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;&lt;span class="kwrd"&gt;namespace&lt;/span&gt; DerekLakin.Libraries.Presentation&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;{&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   3:  &lt;/span&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; CommandBehaviour&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   4:  &lt;/span&gt;    {&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   5:  &lt;/span&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;readonly&lt;/span&gt; DependencyProperty CommandProperty =&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   6:  &lt;/span&gt;          DependencyProperty.RegisterAttached(&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   7:  &lt;/span&gt;            &lt;span class="str"&gt;&amp;quot;Command&amp;quot;&lt;/span&gt;,&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   8:  &lt;/span&gt;            &lt;span class="kwrd"&gt;typeof&lt;/span&gt;(ICommand),&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   9:  &lt;/span&gt;            &lt;span class="kwrd"&gt;typeof&lt;/span&gt;(CommandBehaviour),&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  10:  &lt;/span&gt;            &lt;span class="kwrd"&gt;new&lt;/span&gt; UIPropertyMetadata(&lt;span class="kwrd"&gt;null&lt;/span&gt;));&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  11:  &lt;/span&gt;&amp;#160;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  12:  &lt;/span&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;readonly&lt;/span&gt; DependencyProperty CommandParameterProperty =&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  13:  &lt;/span&gt;          DependencyProperty.RegisterAttached(&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  14:  &lt;/span&gt;            &lt;span class="str"&gt;&amp;quot;CommandParameter&amp;quot;&lt;/span&gt;,&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  15:  &lt;/span&gt;            &lt;span class="kwrd"&gt;typeof&lt;/span&gt;(&lt;span class="kwrd"&gt;object&lt;/span&gt;),&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  16:  &lt;/span&gt;            &lt;span class="kwrd"&gt;typeof&lt;/span&gt;(CommandBehaviour),&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  17:  &lt;/span&gt;            &lt;span class="kwrd"&gt;new&lt;/span&gt; UIPropertyMetadata(&lt;span class="kwrd"&gt;null&lt;/span&gt;));&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  18:  &lt;/span&gt;&amp;#160;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  19:  &lt;/span&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;readonly&lt;/span&gt; DependencyProperty EventNameProperty =&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  20:  &lt;/span&gt;          DependencyProperty.RegisterAttached(&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  21:  &lt;/span&gt;            &lt;span class="str"&gt;&amp;quot;EventName&amp;quot;&lt;/span&gt;,&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  22:  &lt;/span&gt;            &lt;span class="kwrd"&gt;typeof&lt;/span&gt;(&lt;span class="kwrd"&gt;string&lt;/span&gt;),&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  23:  &lt;/span&gt;            &lt;span class="kwrd"&gt;typeof&lt;/span&gt;(CommandBehaviour),&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  24:  &lt;/span&gt;            &lt;span class="kwrd"&gt;new&lt;/span&gt; UIPropertyMetadata(&lt;span class="kwrd"&gt;string&lt;/span&gt;.Empty, &lt;span class="kwrd"&gt;new&lt;/span&gt; PropertyChangedCallback(EventNameChanged)));&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  25:  &lt;/span&gt;&amp;#160;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  26:  &lt;/span&gt;        &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;readonly&lt;/span&gt; DependencyProperty CommandBehaviourProperty =&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  27:  &lt;/span&gt;          DependencyProperty.RegisterAttached(&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  28:  &lt;/span&gt;            &lt;span class="str"&gt;&amp;quot;CommandBehaviour&amp;quot;&lt;/span&gt;,&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  29:  &lt;/span&gt;            &lt;span class="kwrd"&gt;typeof&lt;/span&gt;(CommandBehaviour),&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  30:  &lt;/span&gt;            &lt;span class="kwrd"&gt;typeof&lt;/span&gt;(CommandBehaviour),&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  31:  &lt;/span&gt;            &lt;span class="kwrd"&gt;new&lt;/span&gt; UIPropertyMetadata(&lt;span class="kwrd"&gt;null&lt;/span&gt;));&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  32:  &lt;/span&gt;&amp;#160;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  33:  &lt;/span&gt;        &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;readonly&lt;/span&gt; WeakReference sourceElement;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  34:  &lt;/span&gt;        &lt;span class="kwrd"&gt;private&lt;/span&gt; EventInfo eventInformation;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  35:  &lt;/span&gt;        &lt;span class="kwrd"&gt;private&lt;/span&gt; Delegate targetDelegate;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  36:  &lt;/span&gt;&amp;#160;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  37:  &lt;/span&gt;        &lt;span class="kwrd"&gt;private&lt;/span&gt; CommandBehaviour()&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  38:  &lt;/span&gt;        {&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  39:  &lt;/span&gt;        }&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  40:  &lt;/span&gt;&amp;#160;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  41:  &lt;/span&gt;        &lt;span class="kwrd"&gt;private&lt;/span&gt; CommandBehaviour(DependencyObject source)&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  42:  &lt;/span&gt;        {&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  43:  &lt;/span&gt;            &lt;span class="kwrd"&gt;this&lt;/span&gt;.sourceElement = &lt;span class="kwrd"&gt;new&lt;/span&gt; WeakReference(source);&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  44:  &lt;/span&gt;        }&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  45:  &lt;/span&gt;        ...&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  46:  &lt;/span&gt;    }&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  47:  &lt;/span&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;style type="text/css"&gt;



.csharpcode, .csharpcode pre
{
 font-size: small;
 color: black;
 font-family: consolas, "Courier New", courier, monospace;
 background-color: #ffffff;
 /*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
 background-color: #f4f4f4;
 width: 100%;
 margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;&lt;style type="text/css"&gt;



.csharpcode, .csharpcode pre
{
 font-size: small;
 color: black;
 font-family: consolas, "Courier New", courier, monospace;
 background-color: #ffffff;
 /*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
 background-color: #f4f4f4;
 width: 100%;
 margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;A &lt;/code&gt;&lt;code&gt;CommandBehaviour&lt;/code&gt; instance is created when the &lt;code&gt;EventName&lt;/code&gt; attached property is set and the &lt;code&gt;targetDelegate&lt;/code&gt; member is set when the relevant event has been hooked. In my unit test, I wanted to check that this member was actually being set and here’s how I did it using the accessor:&lt;/p&gt;

&lt;div class="csharpcode"&gt;
  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;[TestMethod]&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;[DeploymentItem(&lt;span class="str"&gt;&amp;quot;DerekLakin.Libraries.Presentation.dll&amp;quot;&lt;/span&gt;)]&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   3:  &lt;/span&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; RemoveEventHandlerTest()&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   4:  &lt;/span&gt;{&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   5:  &lt;/span&gt;    Grid source = &lt;span class="kwrd"&gt;new&lt;/span&gt; Grid();&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   6:  &lt;/span&gt;    source.SetValue(&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   7:  &lt;/span&gt;        CommandBehaviour.CommandProperty,&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   8:  &lt;/span&gt;        ApplicationCommands.Open);&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   9:  &lt;/span&gt;    source.SetValue(&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  10:  &lt;/span&gt;        CommandBehaviour.EventNameProperty,&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  11:  &lt;/span&gt;        &lt;span class="str"&gt;&amp;quot;MouseLeftButtonUp&amp;quot;&lt;/span&gt;);&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  12:  &lt;/span&gt;    CommandBehaviour real = (CommandBehaviour)&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  13:  &lt;/span&gt;        source.GetValue(&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  14:  &lt;/span&gt;            CommandBehaviour_Accessor.CommandBehaviourProperty);&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  15:  &lt;/span&gt;    CommandBehaviour_Accessor target = &lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  16:  &lt;/span&gt;        &lt;span class="kwrd"&gt;new&lt;/span&gt; CommandBehaviour_Accessor(&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  17:  &lt;/span&gt;            &lt;span class="kwrd"&gt;new&lt;/span&gt; PrivateObject(real));&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  18:  &lt;/span&gt;    Assert.IsNotNull(target.targetDelegate);&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  19:  &lt;/span&gt;    target.RemoveEventHandler();&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  20:  &lt;/span&gt;    Assert.IsNull(target.targetDelegate);&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  21:  &lt;/span&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;style type="text/css"&gt;

.csharpcode, .csharpcode pre
{
 font-size: small;
 color: black;
 font-family: consolas, "Courier New", courier, monospace;
 background-color: #ffffff;
 /*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
 background-color: #f4f4f4;
 width: 100%;
 margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;First, I create a &lt;code&gt;Grid&lt;/code&gt; instance and set the &lt;code&gt;Command&lt;/code&gt; and &lt;code&gt;EventName&lt;/code&gt; attached properties on it. Next, I get the &lt;code&gt;CommandBehaviour&lt;/code&gt; instance from the &lt;code&gt;Grid&lt;/code&gt; instance by using the accessor’s &lt;code&gt;CommandBehaviourProperty&lt;/code&gt; (which is normally private). Then, I create a &lt;code&gt;CommandBehaviour_Accessor&lt;/code&gt; instance that wraps the &lt;code&gt;CommandBehaviour&lt;/code&gt; instance by using the &lt;code&gt;PrivateObject&lt;/code&gt; class. Finally, I use regular &lt;code&gt;Assert&lt;/code&gt; statements against the accessor to check the private members. Job done!&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;sup&gt;*&lt;/sup&gt; For more information about testing private methods, see &lt;a title="How to: Test a Private Method" href="http://msdn.microsoft.com/en-us/library/ms184807.aspx"&gt;How to: Test a Private Method&lt;/a&gt; on the MSDN web site.&lt;/p&gt;&lt;div class="wlWriterHeaderFooter" style="margin:0px; padding:0px 0px 0px 0px;"&gt;This work is licensed under a &lt;a href="http://creativecommons.org/licenses/by/3.0/"&gt;Creative Commons Attribution By license.&lt;/a&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=zvz_Jd4GYUY:10d3CF7vX_E:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=zvz_Jd4GYUY:10d3CF7vX_E:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?i=zvz_Jd4GYUY:10d3CF7vX_E:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=zvz_Jd4GYUY:10d3CF7vX_E:oCFASsrFxfc"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?d=oCFASsrFxfc" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=zvz_Jd4GYUY:10d3CF7vX_E:Jwdi1b3fU3Q"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?d=Jwdi1b3fU3Q" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=zvz_Jd4GYUY:10d3CF7vX_E:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?i=zvz_Jd4GYUY:10d3CF7vX_E:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/cloudstore/~4/zvz_Jd4GYUY" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/cloudstore/~3/zvz_Jd4GYUY/testing-private-members-in-visual.html</link><author>noreply@blogger.com (Derek Lakin)</author><thr:total>1</thr:total><feedburner:origLink>http://cloudstore.blogspot.com/2009/06/testing-private-members-in-visual.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-804082557306552579.post-3721648998341835732</guid><pubDate>Mon, 08 Jun 2009 09:21:00 +0000</pubDate><atom:updated>2009-06-12T07:45:00.384+01:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Live Mesh</category><category domain="http://www.blogger.com/atom/ns#">Git</category><category domain="http://www.blogger.com/atom/ns#">cloud</category><category domain="http://www.blogger.com/atom/ns#">CodeProject</category><category domain="http://www.blogger.com/atom/ns#">add-in</category><category domain="http://www.blogger.com/atom/ns#">Visual Studio</category><category domain="http://www.blogger.com/atom/ns#">source control</category><title>Cloud-Based Source Control using Live Mesh and Git</title><description>&lt;p&gt;I’ve been working on a couple of projects recently where I’ve been storing the source in the cloud using &lt;a title="Live Mesh" href="http://www.mesh.com" target="_blank"&gt;Live Mesh&lt;/a&gt; so that I could access the solution from any of the PCs and laptops that litter the house. On the whole this approach has worked fairly well, although it results in a lot of changes through Mesh and occasionally locks files. The other drawback is that there is no file versioning and I like to be able to rollback some changes if I decide the approach I’ve taken isn’t working out for me.&lt;/p&gt;  &lt;p&gt;I’ve had prior history of working with a number of different source control solutions and though that &lt;a title="Subversion" href="http://subversion.tigris.org/" target="_blank"&gt;Subversion&lt;/a&gt; might be a good fit for a Mesh-based repository. Unfortunately, after creating a repository in the Mesh, &lt;a title="AnkSVN" href="http://ankhsvn.open.collab.net/" target="_blank"&gt;AnkhSVN&lt;/a&gt; wouldn’t recognise the Mesh folder as a valid repository, so I couldn’t connect to it. Having given up on the possibility of getting working version control in the Mesh, I found &lt;a title="Ten steps on how to store Git repositories in Live Mesh!" href="http://blog.fossmo.net/post/Ten-steps-on-how-to-store-Git-repositories-in-Live-Mesh!.aspx" target="_blank"&gt;Ten steps on how to store Git repositories in Live Mesh!&lt;/a&gt; by &lt;a title="Pål Fossmo" href="http://blog.fossmo.net/" target="_blank"&gt;Pål Fossmo&lt;/a&gt;. I’d seen a lot of buzz about &lt;a title="Git" href="http://git-scm.com/" target="_blank"&gt;Git&lt;/a&gt;, but never actually tried it, so it though I’d give it a whirl. I was also interested in some kind of integration in Visual Studio and found the &lt;a title="Git Extensions" href="http://code.google.com/p/gitextensions" target="_blank"&gt;Git Extensions&lt;/a&gt;, which include an add-in for Visual Studio, so I modified the original approach slightly and came up with my own:&lt;/p&gt;  &lt;h3&gt;Ten Steps to Storing Git Repositories in the in Live Mesh&lt;/h3&gt;  &lt;ol&gt;   &lt;li&gt;&lt;strong&gt;Install&lt;/strong&gt;.&lt;img style="border-right-width: 0px; margin: 0px 0px 4px 4px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" align="right" src="http://www.gstatic.com/codesite/ph/images/defaultlogo.png" width="48" height="48" /&gt; Download and install Git Extensions from &lt;a href="http://code.google.com/p/gitextensions"&gt;http://code.google.com/p/gitextensions&lt;/a&gt; (I used 1.62, but there is a version 1.64 as I write this post), which includes Git 1.6.2.2, by using the default values during installation. &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;Mesh Account&lt;/strong&gt;. Create a Live Mesh account if you don’t already have one at &lt;a href="http://www.mesh.com"&gt;http://www.mesh.com&lt;/a&gt;. &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;&lt;a title="Mesh Folder" href="http://www.flickr.com/photos/51035614344@N01/3606963980/"&gt;&lt;img style="margin: 0px 0px 4px 4px" border="0" alt="Mesh Folder" align="right" src="http://static.flickr.com/3635/3606963980_8ffedd6e05_t.jpg" /&gt;&lt;/a&gt;Mesh Folder&lt;/strong&gt;. Create a folder in the Mesh and synchronise it with the required devices. I called mine &lt;strong&gt;Repository&lt;/strong&gt;. &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;Local Repository&lt;/strong&gt;. To create a local repository, navigate to the folder containing your source code, right-click, click &lt;strong&gt;Git GUI Here&lt;/strong&gt;, and then click &lt;strong&gt;Create New Repository&lt;/strong&gt;. In the &lt;strong&gt;Git Gui&lt;/strong&gt; dialog, select the target folder, and then click &lt;strong&gt;Create&lt;/strong&gt;. Git displays a dialog showing the files that will be added.       &lt;br /&gt;&lt;a title="Git Gui - Unstaged Changes" href="http://www.flickr.com/photos/51035614344@N01/3606156291/"&gt;&lt;img border="0" alt="Git Gui - Unstaged Changes" src="http://static.flickr.com/3382/3606156291_9d5a3d6d48_m.jpg" /&gt;&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;Exclude Files&lt;/strong&gt;. To exclude files that you don’t want to be version controlled, edit the file named &lt;strong&gt;exclude&lt;/strong&gt; in: &amp;lt;New repository&amp;gt;\.git\info\. My exclude file uses the defaults for Visual Studio plus a few extras, such as *.vsmdi. &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;Commit Initial Version&lt;/strong&gt;. In the &lt;strong&gt;Git Gui&lt;/strong&gt; dialog (from Step 4), click &lt;strong&gt;Rescan&lt;/strong&gt; to update the list of files to be added, type “&lt;strong&gt;Initial version.&lt;/strong&gt;” into the &lt;strong&gt;Commit Message&lt;/strong&gt; box, and then click &lt;strong&gt;Commit&lt;/strong&gt;.       &lt;br /&gt;&lt;a title="Git Gui - Staged Changes" href="http://www.flickr.com/photos/51035614344@N01/3606992860/"&gt;&lt;img style="display: inline; margin-left: 0px; margin-right: 0px" border="0" alt="Git Gui - Staged Changes" src="http://static.flickr.com/3556/3606992860_5e50e4208f_m.jpg" /&gt;&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;&lt;a title="Clone Repository" href="http://www.flickr.com/photos/51035614344@N01/3606189235/"&gt;&lt;img style="display: inline; margin-left: 0px; margin-right: 0px" border="0" alt="Clone Repository" align="right" src="http://static.flickr.com/3664/3606189235_554629934f_m.jpg" /&gt;&lt;/a&gt;Clone the Repository into the Mesh&lt;/strong&gt;. Open your solution in Visual Studio, and then open a file (any source file it doesn’t matter&lt;sup&gt;*&lt;/sup&gt;). On the &lt;strong&gt;Git&lt;/strong&gt; menu, click &lt;strong&gt;Clone repository&lt;/strong&gt;. In the &lt;strong&gt;Clone&lt;/strong&gt; dialog, make sure the &lt;strong&gt;Repository to clone&lt;/strong&gt; folder is correct, select the destination folder, which is your Mesh folder, enter the name of the &lt;strong&gt;Subdirectory to create&lt;/strong&gt;, select &lt;strong&gt;Central repository, no working dir (--bare)&lt;/strong&gt;, and then click &lt;strong&gt;Clone&lt;/strong&gt;. &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;&lt;a title="Push to Mesh" href="http://www.flickr.com/photos/51035614344@N01/3607015032/"&gt;&lt;img style="display: inline; margin-left: 0px; margin-right: 0px" border="0" alt="Push to Mesh" align="right" src="http://static.flickr.com/3302/3607015032_b38d9b4926_m.jpg" /&gt;&lt;/a&gt;Push Changes to the Mesh&lt;/strong&gt;. Commit local changes as usual by using the &lt;strong&gt;Commit&lt;/strong&gt; button on the Git Extensions toolbar. When you are ready to push some changes into the Mesh: in Visual Studio, click &lt;strong&gt;Push changes to remote repository&lt;/strong&gt; on the Git Extensions toolbar. In the &lt;strong&gt;Push&lt;/strong&gt; dialog, select &lt;strong&gt;Url&lt;/strong&gt;, click &lt;strong&gt;Browse&lt;/strong&gt; to select the Mesh folder to push to, select &lt;strong&gt;master&lt;/strong&gt; from the &lt;strong&gt;Branch to push&lt;/strong&gt; list, and then click &lt;strong&gt;Push&lt;/strong&gt;. &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;Get Source Files on Different PC&lt;/strong&gt;. Install Git Extensions as described in Step 1. Create a folder to contain the source files, and then create a local repository as described in Step 4. Update the exclude file as described in Step 5. &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;Pull the Source From the Repository&lt;/strong&gt;. Right-click the folder for the new repository, and then click &lt;strong&gt;Git Bash Here&lt;/strong&gt;. In the command prompt, type:       &lt;br /&gt;&lt;strong&gt;&lt;code&gt;git pull C:/Users/&amp;lt;user&amp;gt;/Desktop/Repository/&amp;lt;SubFolder&amp;gt; master&lt;/code&gt;         &lt;br /&gt;&lt;/strong&gt;You now have the same source files on both PCs. You can use the push and pull buttons on the Git Extensions toolbar in Visual Studio to transfer changes via the Mesh. &lt;strong&gt;&lt;a title="Pull from Repository" href="http://www.flickr.com/photos/51035614344@N01/3606209415/"&gt;&lt;img style="display: inline; margin-left: 0px; margin-right: 0px" border="0" alt="Pull from Repository" src="http://static.flickr.com/3610/3606209415_01b5a31363_m.jpg" /&gt;&lt;/a&gt;&lt;/strong&gt; &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;&amp;#160;&lt;sup&gt;*&lt;/sup&gt; The Git Extensions add-in for Visual Studio is a regular add-in, not a source control provider. For any command to work, you must have a source file open.&lt;/p&gt;  &lt;h3&gt;Side Note&lt;/h3&gt;  &lt;p&gt;If you want to see your own name in the version history, click &lt;strong&gt;Settings&lt;/strong&gt; on the Git Extensions toolbar, and enter your details on the &lt;strong&gt;Global Settings&lt;/strong&gt; tab. You can also change the merge tool on this tab (I personally prefer &lt;a title="SourceGear’s DiffMerge" href="http://www.sourcegear.com/diffmerge/" target="_blank"&gt;SourceGear’s DiffMerge&lt;/a&gt;).&lt;/p&gt;&lt;div class="wlWriterHeaderFooter" style="margin:0px; padding:0px 0px 0px 0px;"&gt;This work is licensed under a &lt;a href="http://creativecommons.org/licenses/by/3.0/"&gt;Creative Commons Attribution By license.&lt;/a&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=1Kf9EE-SbYM:vE5aTs4cvOc:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=1Kf9EE-SbYM:vE5aTs4cvOc:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?i=1Kf9EE-SbYM:vE5aTs4cvOc:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=1Kf9EE-SbYM:vE5aTs4cvOc:oCFASsrFxfc"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?d=oCFASsrFxfc" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=1Kf9EE-SbYM:vE5aTs4cvOc:Jwdi1b3fU3Q"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?d=Jwdi1b3fU3Q" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=1Kf9EE-SbYM:vE5aTs4cvOc:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?i=1Kf9EE-SbYM:vE5aTs4cvOc:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/cloudstore/~4/1Kf9EE-SbYM" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/cloudstore/~3/1Kf9EE-SbYM/cloud-based-source-control-using-live.html</link><author>noreply@blogger.com (Derek Lakin)</author><thr:total>0</thr:total><feedburner:origLink>http://cloudstore.blogspot.com/2009/06/cloud-based-source-control-using-live.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-804082557306552579.post-6517936030962012633</guid><pubDate>Tue, 21 Apr 2009 08:58:00 +0000</pubDate><atom:updated>2009-04-21T09:58:55.899+01:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">personal</category><category domain="http://www.blogger.com/atom/ns#">fracture</category><category domain="http://www.blogger.com/atom/ns#">flickr</category><category domain="http://www.blogger.com/atom/ns#">broken</category><title>Fractured Metacarpal</title><description>&lt;p&gt;&lt;a title="Fractured Metacarpal" href="http://www.flickr.com/photos/51035614344@N01/3462371856/"&gt;&lt;img style="margin: 0px 5px 5px 0px" alt="Fractured Metacarpal" src="http://static.flickr.com/3603/3462371856_3b80f39b36_m.jpg" align="left" border="0" /&gt;&lt;/a&gt;Not wanting to be outdone by my Mum who broke her arm in New Zealand &lt;a title="Eventful weekend" href="http://lindalakin.blogspot.com/2009/03/eventful-weekend.html" target="_blank"&gt;recently&lt;/a&gt;, yesterday (after 33 years with no broken bones) I managed to break the left little finger metacarpal.&lt;/p&gt;  &lt;p&gt;I was cycling back from town when the chain slipped off the gears throwing the bike to the left and me into some iron railings. My little finger hyper flexed into my palm and snapped the metacarpal in the process.&lt;/p&gt;  &lt;p&gt;I'm now bandaged up (no cast) and typing with one hand plus two fingers and a thumb!&lt;/p&gt;&lt;div class="wlWriterHeaderFooter" style="margin:0px; padding:0px 0px 0px 0px;"&gt;This work is licensed under a &lt;a href="http://creativecommons.org/licenses/by/3.0/"&gt;Creative Commons Attribution By license.&lt;/a&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=zYpKNl3NAv4:hRRO_ApG50E:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=zYpKNl3NAv4:hRRO_ApG50E:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?i=zYpKNl3NAv4:hRRO_ApG50E:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=zYpKNl3NAv4:hRRO_ApG50E:oCFASsrFxfc"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?d=oCFASsrFxfc" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=zYpKNl3NAv4:hRRO_ApG50E:Jwdi1b3fU3Q"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?d=Jwdi1b3fU3Q" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=zYpKNl3NAv4:hRRO_ApG50E:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?i=zYpKNl3NAv4:hRRO_ApG50E:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/cloudstore/~4/zYpKNl3NAv4" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/cloudstore/~3/zYpKNl3NAv4/fractured-metacarpal.html</link><author>noreply@blogger.com (Derek Lakin)</author><thr:total>1</thr:total><feedburner:origLink>http://cloudstore.blogspot.com/2009/04/fractured-metacarpal.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-804082557306552579.post-1575070593350112879</guid><pubDate>Tue, 14 Apr 2009 16:24:00 +0000</pubDate><atom:updated>2009-04-14T17:49:23.369+01:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">WPF</category><category domain="http://www.blogger.com/atom/ns#">custom</category><category domain="http://www.blogger.com/atom/ns#">.net</category><category domain="http://www.blogger.com/atom/ns#">XAML</category><category domain="http://www.blogger.com/atom/ns#">CodeProject</category><category domain="http://www.blogger.com/atom/ns#">c#</category><category domain="http://www.blogger.com/atom/ns#">styles</category><category domain="http://www.blogger.com/atom/ns#">UI</category><title>Defining the Default Style for a Lookless Control</title><description>&lt;p&gt;&lt;/p&gt;  &lt;p&gt;Microsoft introduced the concept of “lookless” controls in WPF, which means that the control defines its behaviour without any information about how it actually looks, which is where templates and styles come in. However, all of the default controls provide a default look, which is in keeping with the current Windows theme (Aero in Windows Vista, Luna, Metallic, or Homestead in Windows XP and so on). If you are creating lookless controls in a class library for general consumption, it would be helpful to also provide a default look for your controls. To achieve this, there are three things that you need to do.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; This article refers specifically to custom controls (i.e. those that inherit from &lt;a title="Control Class" href="http://msdn2.microsoft.com/ms609826.aspx"&gt;Control&lt;/a&gt;, &lt;a title="FrameworkElement Class" href="http://msdn2.microsoft.com/ms602714.aspx"&gt;FrameworkElement&lt;/a&gt; or similar, not user controls that inherit from &lt;a title="UserControl Class" href="http://msdn2.microsoft.com/ms617852.aspx"&gt;UserControl&lt;/a&gt;). For more information about creating controls for WPF, see &lt;a title="Control Authoring Overview" href="http://msdn.microsoft.com/en-us/library/ms745025.aspx" target="_blank"&gt;Control Authoring Overview&lt;/a&gt; on the MSDN web site.&lt;/p&gt;  &lt;h3&gt;1. Override the Metadata for the DefaultStyleKey Property&lt;/h3&gt;  &lt;p&gt;In a static constructor for your control, set the default style key to the type name, which is used to do style lookups for your control. The following code example shows the static constructor for a Wizard class that I’m creating.&lt;/p&gt;  &lt;div class="csharpcode"&gt;   &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;&lt;span class="kwrd"&gt;static&lt;/span&gt; Wizard()&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;{&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   3:  &lt;/span&gt;    DefaultStyleKeyProperty.OverrideMetadata(&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   4:  &lt;/span&gt;        &lt;span class="kwrd"&gt;typeof&lt;/span&gt;(Wizard),&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   5:  &lt;/span&gt;        &lt;span class="kwrd"&gt;new&lt;/span&gt; FrameworkPropertyMetadata(&lt;span class="kwrd"&gt;typeof&lt;/span&gt;(Wizard)));&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   6:  &lt;/span&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;style type="text/css"&gt;





.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;h3&gt;2. Define Your Default Style&lt;/h3&gt;

&lt;p&gt;You can create a default style for each of the different Windows themes. To do this you need to create resource dictionary with a specific name in a Themes folder that is a subfolder of the folder that contains your control in your class library. The following table provides the file names of the theme-specific resource dictionaries.&lt;/p&gt;

&lt;table cellspacing="0" cellpadding="2" width="494" border="1"&gt;&lt;tbody&gt;
    &lt;tr&gt;
      &lt;td valign="top" width="196"&gt;&lt;strong&gt;Resource dictionary&lt;/strong&gt;&lt;/td&gt;

      &lt;td valign="top" width="296"&gt;&lt;strong&gt;Windows theme&lt;/strong&gt;&lt;/td&gt;
    &lt;/tr&gt;

    &lt;tr&gt;
      &lt;td valign="top" width="252"&gt;Classic.xaml&lt;/td&gt;

      &lt;td valign="top" width="296"&gt;“Classic” Windows 9x/2000 look on Windows XP&lt;/td&gt;
    &lt;/tr&gt;

    &lt;tr&gt;
      &lt;td valign="top" width="252"&gt;Luna.NormalColor.xaml&lt;/td&gt;

      &lt;td valign="top" width="296"&gt;Default blue theme on Windows XP&lt;/td&gt;
    &lt;/tr&gt;

    &lt;tr&gt;
      &lt;td valign="top" width="252"&gt;Luna.Homestead.xaml&lt;/td&gt;

      &lt;td valign="top" width="296"&gt;Olive theme on Windows XP&lt;/td&gt;
    &lt;/tr&gt;

    &lt;tr&gt;
      &lt;td valign="top" width="252"&gt;Luna.Metallic.xaml&lt;/td&gt;

      &lt;td valign="top" width="296"&gt;Silver theme on Windows XP&lt;/td&gt;
    &lt;/tr&gt;

    &lt;tr&gt;
      &lt;td valign="top" width="252"&gt;Royale.NormalColor.xaml&lt;/td&gt;

      &lt;td valign="top" width="296"&gt;Default theme on Windows XP Media Center Edition&lt;/td&gt;
    &lt;/tr&gt;

    &lt;tr&gt;
      &lt;td valign="top" width="252"&gt;Aero.NormalColor.xaml&lt;/td&gt;

      &lt;td valign="top" width="296"&gt;Default theme on Windows Vista&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;&lt;/table&gt;

&lt;p&gt;You don’t need to provide a style for every theme. If there is no theme-specific resource, then the generic resource is used for the control, which is defined in the Themes\generic.xaml resource dictionary.&lt;/p&gt;

&lt;p&gt;The following XAML code example shows the default style in generic.xaml for the Wizard class described above.&lt;/p&gt;

&lt;div class="csharpcode"&gt;
  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;&amp;lt;ResourceDictionary xmlns=&lt;span class="str"&gt;&amp;quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&amp;quot;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;                    xmlns:local=&lt;span class="str"&gt;&amp;quot;clr-namespace:DerekLakin.Libraries.Presentation&amp;quot;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   3:  &lt;/span&gt;                    xmlns:x=&lt;span class="str"&gt;&amp;quot;http://schemas.microsoft.com/winfx/2006/xaml&amp;quot;&lt;/span&gt;&amp;gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   4:  &lt;/span&gt;    &amp;lt;Style TargetType=&lt;span class="str"&gt;&amp;quot;{x:Type local:Wizard}&amp;quot;&lt;/span&gt;&amp;gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   5:  &lt;/span&gt;        &amp;lt;Setter Property=&lt;span class="str"&gt;&amp;quot;Template&amp;quot;&lt;/span&gt;&amp;gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   6:  &lt;/span&gt;            &amp;lt;Setter.Value&amp;gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   7:  &lt;/span&gt;                &amp;lt;ControlTemplate TargetType=&lt;span class="str"&gt;&amp;quot;{x:Type local:Wizard}&amp;quot;&lt;/span&gt;&amp;gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   8:  &lt;/span&gt;                    &amp;lt;DockPanel LastChildFill=&lt;span class="str"&gt;&amp;quot;True&amp;quot;&lt;/span&gt;&amp;gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   9:  &lt;/span&gt;                        &amp;lt;WrapPanel DockPanel.Dock=&lt;span class="str"&gt;&amp;quot;Bottom&amp;quot;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  10:  &lt;/span&gt;                                   HorizontalAlignment=&lt;span class="str"&gt;&amp;quot;Right&amp;quot;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  11:  &lt;/span&gt;                                   Orientation=&lt;span class="str"&gt;&amp;quot;Horizontal&amp;quot;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  12:  &lt;/span&gt;                                   Margin=&lt;span class="str"&gt;&amp;quot;10&amp;quot;&lt;/span&gt;&amp;gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  13:  &lt;/span&gt;                            &amp;lt;Button x:Name=&lt;span class="str"&gt;&amp;quot;PART_Back&amp;quot;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  14:  &lt;/span&gt;                                    Content=&lt;span class="str"&gt;&amp;quot;Back&amp;quot;&lt;/span&gt; /&amp;gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  15:  &lt;/span&gt;                            &amp;lt;Button x:Name=&lt;span class="str"&gt;&amp;quot;PART_Next&amp;quot;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  16:  &lt;/span&gt;                                    Content=&lt;span class="str"&gt;&amp;quot;Next&amp;quot;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  17:  &lt;/span&gt;                                    Margin=&lt;span class="str"&gt;&amp;quot;4,0,0,0&amp;quot;&lt;/span&gt; /&amp;gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  18:  &lt;/span&gt;                            &amp;lt;Button x:Name=&lt;span class="str"&gt;&amp;quot;PART_Cancel&amp;quot;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  19:  &lt;/span&gt;                                    Content=&lt;span class="str"&gt;&amp;quot;Cancel&amp;quot;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  20:  &lt;/span&gt;                                    Margin=&lt;span class="str"&gt;&amp;quot;4,0,0,0&amp;quot;&lt;/span&gt; /&amp;gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  21:  &lt;/span&gt;                            &amp;lt;Button x:Name=&lt;span class="str"&gt;&amp;quot;PART_Finish&amp;quot;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  22:  &lt;/span&gt;                                    Content=&lt;span class="str"&gt;&amp;quot;Finish&amp;quot;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  23:  &lt;/span&gt;                                    Margin=&lt;span class="str"&gt;&amp;quot;4,0,0,0&amp;quot;&lt;/span&gt; /&amp;gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  24:  &lt;/span&gt;                        &amp;lt;/WrapPanel&amp;gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  25:  &lt;/span&gt;                        &amp;lt;Frame x:Name=&lt;span class="str"&gt;&amp;quot;PART_Frame&amp;quot;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  26:  &lt;/span&gt;                               NavigationUIVisibility=&lt;span class="str"&gt;&amp;quot;Hidden&amp;quot;&lt;/span&gt; /&amp;gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  27:  &lt;/span&gt;                    &amp;lt;/DockPanel&amp;gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  28:  &lt;/span&gt;                &amp;lt;/ControlTemplate&amp;gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  29:  &lt;/span&gt;            &amp;lt;/Setter.Value&amp;gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  30:  &lt;/span&gt;        &amp;lt;/Setter&amp;gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  31:  &lt;/span&gt;    &amp;lt;/Style&amp;gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  32:  &lt;/span&gt;&amp;lt;/ResourceDictionary&amp;gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;&lt;style type="text/css"&gt;





.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;&lt;/p&gt;

&lt;h3&gt;3. Add the ThemeInfo Attribute to AssemblyInfo&lt;/h3&gt;

&lt;p&gt;The final part is to publicise the fact that your assembly contains control-specific resources, which you do by using the &lt;a title="ThemeInfoAttribute Class" href="http://msdn2.microsoft.com/ms603269.aspx"&gt;ThemeInfo&lt;/a&gt; attribute. The &lt;a title="ThemeInfoAttribute..::.GenericDictionaryLocation Property " href="http://msdn2.microsoft.com/ms602083.aspx"&gt;GenericDictionaryLocation&lt;/a&gt; property defines where the generic resources are and the &lt;a title="ThemeInfoAttribute..::.ThemeDictionaryLocation Property " href="http://msdn2.microsoft.com/ms602084.aspx"&gt;ThemeDictionaryLocation&lt;/a&gt; property defines where the themed resources are. The value for both properties is a &lt;a title="ResourceDictionaryLocation Enumeration" href="http://msdn2.microsoft.com/ms589727.aspx"&gt;ResourceDictionaryLocation&lt;/a&gt; enumeration, which is &lt;a title="None Field" href="http://msdn2.microsoft.com/bb353975.aspx"&gt;None&lt;/a&gt;, &lt;a title="SourceAssembly Field" href="http://msdn2.microsoft.com/bb298251.aspx"&gt;SourceAssembly&lt;/a&gt;, or &lt;a title="ExternalAssembly Field" href="http://msdn2.microsoft.com/bb358714.aspx"&gt;ExternalAssembly&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The following code example shows the &lt;a title="ThemeInfoAttribute Class" href="http://msdn2.microsoft.com/ms603269.aspx"&gt;ThemeInfo&lt;/a&gt; attribute for the class library project that contains the Wizard class described previously, which has no theme-specific resources, but does specify a generic resource.&lt;/p&gt;

&lt;div class="csharpcode"&gt;
  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;[assembly: ThemeInfo(ResourceDictionaryLocation.None, &lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;    ResourceDictionaryLocation.SourceAssembly)]&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;h3&gt;Side Note&lt;/h3&gt;

&lt;p&gt;If your custom control has specific parts that are key to the operation of the control (such as the buttons and frame in the Wizard example described previously), then the convention is to name them using the “PART_” prefix in the control template. For each required part in your template, you should add a &lt;a title="TemplatePartAttribute Class" href="http://msdn2.microsoft.com/ms603208.aspx"&gt;TemplatePart&lt;/a&gt; attribute to the class definition as shown in the following code example.&lt;/p&gt;

&lt;div class="csharpcode"&gt;
  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;[TemplatePart(Name = &lt;span class="str"&gt;&amp;quot;PART_Frame&amp;quot;&lt;/span&gt;, Type = &lt;span class="kwrd"&gt;typeof&lt;/span&gt;(Frame))]&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;[TemplatePart(Name = &lt;span class="str"&gt;&amp;quot;PART_Back&amp;quot;&lt;/span&gt;, Type = &lt;span class="kwrd"&gt;typeof&lt;/span&gt;(Button))]&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   3:  &lt;/span&gt;[TemplatePart(Name = &lt;span class="str"&gt;&amp;quot;PART_Cancel&amp;quot;&lt;/span&gt;, Type = &lt;span class="kwrd"&gt;typeof&lt;/span&gt;(Button))]&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   4:  &lt;/span&gt;[TemplatePart(Name = &lt;span class="str"&gt;&amp;quot;PART_Finish&amp;quot;&lt;/span&gt;, Type = &lt;span class="kwrd"&gt;typeof&lt;/span&gt;(Button))]&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   5:  &lt;/span&gt;[TemplatePart(Name = &lt;span class="str"&gt;&amp;quot;PART_Next&amp;quot;&lt;/span&gt;, Type = &lt;span class="kwrd"&gt;typeof&lt;/span&gt;(Button))]&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   6:  &lt;/span&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; Wizard : Window&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;&lt;style type="text/css"&gt;





.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;&lt;/p&gt;

&lt;p&gt;You should get a reference to these named template parts in the &lt;strong&gt;OnApplyTemplate&lt;/strong&gt; override of your class because this is the point where the control template has actually been applied. It is common &lt;strong&gt;not&lt;/strong&gt; to specifically handle missing template parts so that an exception (typically a NullReferenceException) gets raised at runtime, which clearly indicates that something is broken.&lt;/p&gt;

&lt;p&gt;The following code example shows the &lt;strong&gt;OnApplyTemplate&lt;/strong&gt; override for the Wizard class described previously.&lt;/p&gt;

&lt;div class="csharpcode"&gt;
  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; OnApplyTemplate()&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;{&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   3:  &lt;/span&gt;    &lt;span class="kwrd"&gt;base&lt;/span&gt;.OnApplyTemplate();&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   4:  &lt;/span&gt;&amp;#160;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   5:  &lt;/span&gt;    &lt;span class="rem"&gt;// Get the template parts.&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   6:  &lt;/span&gt;    &lt;span class="kwrd"&gt;this&lt;/span&gt;.navigationFrame = &lt;span class="kwrd"&gt;this&lt;/span&gt;.GetTemplateChild(&lt;span class="str"&gt;&amp;quot;PART_Frame&amp;quot;&lt;/span&gt;) &lt;span class="kwrd"&gt;as&lt;/span&gt; Frame;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   7:  &lt;/span&gt;    &lt;span class="kwrd"&gt;this&lt;/span&gt;.back = &lt;span class="kwrd"&gt;this&lt;/span&gt;.GetTemplateChild(&lt;span class="str"&gt;&amp;quot;PART_Back&amp;quot;&lt;/span&gt;) &lt;span class="kwrd"&gt;as&lt;/span&gt; Button;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   8:  &lt;/span&gt;    &lt;span class="kwrd"&gt;this&lt;/span&gt;.cancel = &lt;span class="kwrd"&gt;this&lt;/span&gt;.GetTemplateChild(&lt;span class="str"&gt;&amp;quot;PART_Cancel&amp;quot;&lt;/span&gt;) &lt;span class="kwrd"&gt;as&lt;/span&gt; Button;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   9:  &lt;/span&gt;    &lt;span class="kwrd"&gt;this&lt;/span&gt;.finish = &lt;span class="kwrd"&gt;this&lt;/span&gt;.GetTemplateChild(&lt;span class="str"&gt;&amp;quot;PART_Finish&amp;quot;&lt;/span&gt;) &lt;span class="kwrd"&gt;as&lt;/span&gt; Button;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  10:  &lt;/span&gt;    &lt;span class="kwrd"&gt;this&lt;/span&gt;.next = &lt;span class="kwrd"&gt;this&lt;/span&gt;.GetTemplateChild(&lt;span class="str"&gt;&amp;quot;PART_Next&amp;quot;&lt;/span&gt;) &lt;span class="kwrd"&gt;as&lt;/span&gt; Button;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  11:  &lt;/span&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;style type="text/css"&gt;





.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;For more information about designing lookless controls, see &lt;a title="Guidelines for Designing Stylable Controls" href="http://msdn.microsoft.com/en-us/library/ms752339.aspx" target="_blank"&gt;Guidelines for Designing Stylable Controls&lt;/a&gt; on the MSDN web site.&lt;/p&gt;&lt;div class="wlWriterHeaderFooter" style="margin:0px; padding:0px 0px 0px 0px;"&gt;This work is licensed under a &lt;a href="http://creativecommons.org/licenses/by/3.0/"&gt;Creative Commons Attribution By license.&lt;/a&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=QETE8SahkzQ:QP7HhTwCk0c:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=QETE8SahkzQ:QP7HhTwCk0c:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?i=QETE8SahkzQ:QP7HhTwCk0c:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=QETE8SahkzQ:QP7HhTwCk0c:oCFASsrFxfc"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?d=oCFASsrFxfc" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=QETE8SahkzQ:QP7HhTwCk0c:Jwdi1b3fU3Q"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?d=Jwdi1b3fU3Q" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=QETE8SahkzQ:QP7HhTwCk0c:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?i=QETE8SahkzQ:QP7HhTwCk0c:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/cloudstore/~4/QETE8SahkzQ" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/cloudstore/~3/QETE8SahkzQ/defining-default-style-for-lookless.html</link><author>noreply@blogger.com (Derek Lakin)</author><thr:total>0</thr:total><feedburner:origLink>http://cloudstore.blogspot.com/2009/04/defining-default-style-for-lookless.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-804082557306552579.post-3111536739610426147</guid><pubDate>Thu, 26 Mar 2009 20:50:00 +0000</pubDate><atom:updated>2009-03-26T20:59:16.853Z</atom:updated><title>Appeal for IT Professional</title><description>&lt;p&gt;In a departure from my usual posts (if you can call not posting for nearly six months "usual"!), I'd like to make an appeal on behalf of my wife's company for someone with IT infrastructure/system adminstration experience who would be willing to help them out. The specification for the work is as follows:&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;We are a cutting edge Technology Company based on the Cambridge Science Park.  We have been at this facility for five years in October 2009 and now require a business analysis to be carried out on our existing business processes and information systems.&lt;/p&gt;
&lt;p&gt;We are therefore seeking an Independent IT Professional who is NOT tied to an agency or IT company.  This is strictly for an independent review of our business systems to enable us to go out to the market for quotes for the necessary work to be carried out.&lt;/p&gt;
&lt;p&gt;We will be looking for recommendations on processes and information system improvements to carry us through the next five years.  Presently our IT is out-sourced to a local company and aided internally by our Office Administrator with the Direction of our Director of HR &amp; Administration who has responsibility for this area of the business.&lt;/p&gt;
&lt;p&gt;Project Detail&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;To conduct a business analysis with input from key people within the business&lt;/li&gt;
&lt;li&gt;Recording and analysis of interviews with key staff&lt;/li&gt;
&lt;li&gt;Analysis of the use of existing business process and systems&lt;/li&gt;
&lt;li&gt;An appropriate costed solution to meet the long term requirements and business challenges of the organisation&lt;/li&gt;
&lt;li&gt;A GAP analysis&lt;/li&gt;
&lt;li&gt;A proposal for the solution to meet future business needs&lt;/li&gt;
&lt;/ul&gt;&lt;/p&gt; 
&lt;p&gt;If this mini-project is of interest to you, please contact: Julie Lakin, Director of HR &amp; Administration at &lt;a href="mailto:julie.lakin@smartholograms.com"&gt;Julie.lakin@SmartHolograms.com&lt;/a&gt; or by telephone on 01223 393400.&lt;/p&gt;&lt;/blockquote&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=T9mluGB4Q78:ephqa3gah4M:4cEx4HpKnUU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?i=T9mluGB4Q78:ephqa3gah4M:4cEx4HpKnUU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=T9mluGB4Q78:ephqa3gah4M:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=T9mluGB4Q78:ephqa3gah4M:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?i=T9mluGB4Q78:ephqa3gah4M:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=T9mluGB4Q78:ephqa3gah4M:oCFASsrFxfc"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?d=oCFASsrFxfc" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=T9mluGB4Q78:ephqa3gah4M:Jwdi1b3fU3Q"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?d=Jwdi1b3fU3Q" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=T9mluGB4Q78:ephqa3gah4M:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?i=T9mluGB4Q78:ephqa3gah4M:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/cloudstore/~4/T9mluGB4Q78" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/cloudstore/~3/T9mluGB4Q78/appeal-for-it-professional.html</link><author>noreply@blogger.com (Derek Lakin)</author><thr:total>0</thr:total><feedburner:origLink>http://cloudstore.blogspot.com/2009/03/appeal-for-it-professional.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-804082557306552579.post-2646628483464746233</guid><pubDate>Mon, 06 Oct 2008 11:52:00 +0000</pubDate><atom:updated>2009-03-31T10:54:23.486+01:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">WPF</category><category domain="http://www.blogger.com/atom/ns#">Prism</category><category domain="http://www.blogger.com/atom/ns#">composite</category><category domain="http://www.blogger.com/atom/ns#">.net</category><category domain="http://www.blogger.com/atom/ns#">XAML</category><category domain="http://www.blogger.com/atom/ns#">CodeProject</category><category domain="http://www.blogger.com/atom/ns#">screen shot</category><category domain="http://www.blogger.com/atom/ns#">c#</category><category domain="http://www.blogger.com/atom/ns#">UI</category><category domain="http://www.blogger.com/atom/ns#">Microsoft</category><category domain="http://www.blogger.com/atom/ns#">refactor</category><title>Migrating a Legacy WPF Application to Prism - Part 2</title><description>&lt;p&gt;&lt;img style="border-bottom: 0px; border-left: 0px; border-top: 0px; border-right: 0px" border="0" alt="Prism.FirstView.Structure" align="left" src="http://lh5.ggpht.com/derek.lakin/SOoLXD9inbI/AAAAAAAAAGc/XvP59vSS0S0/Prism.FirstView.Structure%5B5%5D.png?imgmax=800" width="266" height="500" /&gt;After my initial successes in moving to a Prism-style bootstrapper in &lt;a href="http://cloudstore.blogspot.com/2008/10/migrating-legacy-wpf-application-to.html"&gt;Part 1&lt;/a&gt; it was time to move onto the next step. But in the case of a legacy application, what's the next step?&lt;/p&gt;  &lt;h3&gt;Application Structure Overview&lt;/h3&gt;  &lt;p&gt;Our legacy application consists primarily of a WPF user interface, a WCF service that provides access to a SQL Server database and a few support libraries. One of those support libraries provides some classes that deal with the interaction between the user interface and the WCF service and is my prime candidate for making some improvements using the Prism guidance.&lt;/p&gt;  &lt;p&gt;There are two main entities, one that relates to a Project that is handled by the application and one that relates to a Pages, which make up the contents of a Project. So these seemed to me to be good choices for modules. But, the existing infrastructure merges the roles of Service and ViewModel into a single class, which I'd like to separate.&lt;/p&gt;  &lt;p&gt;So, my plan (so far at least) is to create Prism Modules for the Project and Page and to create the relevant Views, ViewModels, Services, and Controllers that are required to implement the functionality. Rather than having to fully re-write the underlying code that handles UI/WCF Service interaction, I'm planning on writing a Prism-facade that will simply call out to the existing infrastructure, which I can eventually replace as time progresses. This gives me the testability advantages of Prism without having to rip out the heart of the application and re-write it completely, which would be a costly and time consuming task.&lt;/p&gt;  &lt;h3&gt;Getting Started&lt;/h3&gt;  &lt;p&gt;&lt;img style="border-right-width: 0px; margin: 5px 0px 5px 5px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="Prism.FirstView" align="right" src="http://lh4.ggpht.com/derek.lakin/SOn77arVzzI/AAAAAAAAAF8/aIRFEQip6sA/Prism.FirstView%5B4%5D.png?imgmax=800" width="260" height="254" /&gt; For my next step I'm focusing on the Project aspects of the application, so (as you can see in the screen shot above) I've created a Project module containing the ProjectModule, a ProjectService, ProjectTreeView, ProjectTreeViewModel and a ProjectController, which will handle the interactions between the different views of a project (when I get that far).&lt;/p&gt;  &lt;p&gt;Each of these classes implements an interface, which enables me to easily mock these implementations to test specific aspects of the application. At this stage my implementations are very simple in that they just initialise the relevant Views, ViewModels, etc. The View itself is simply a &lt;a title="UserControl Class" href="http://msdn2.microsoft.com/ms617852.aspx"&gt;UserControl&lt;/a&gt; that contains a root &lt;a title="Grid Class" href="http://msdn2.microsoft.com/ms610550.aspx"&gt;Grid&lt;/a&gt; element with a pink background. The important thing is to get it loaded and displayed first.&lt;/p&gt;  &lt;h3&gt;Implementation Specifics&lt;/h3&gt;  &lt;p&gt;In the application's shell, the existing user control was removed and replaced with the following region definition.&lt;/p&gt;  &lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;ContentControl &lt;/span&gt;&lt;span style="color: red"&gt;x&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: red"&gt;Name&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;_navigation&amp;quot;
                &lt;/span&gt;&lt;span style="color: red"&gt;cal&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: red"&gt;RegionManager.RegionName&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color: #a31515"&gt;x&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;Static &lt;/span&gt;&lt;span style="color: red"&gt;inf&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: red"&gt;RegionNames&lt;/span&gt;&lt;span style="color: blue"&gt;.Navigation}&amp;quot;
                &lt;/span&gt;&lt;span style="color: red"&gt;DockPanel.Dock&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;Left&amp;quot; /&amp;gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;The &amp;quot;cal&amp;quot; XML namespace resolves to &amp;quot;http://www.codeplex.com/CompositeWPF&amp;quot; and the &amp;quot;inf&amp;quot; XML namespace resolves to an infrastructure assembly that contains constants for the region names.&lt;/p&gt;

&lt;p&gt;The ProjectController class retrieves the relevant region that is the destination of the View and adds the View for the associated ViewModel to that region and then activates it as shown in the following code example.&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;public void &lt;/span&gt;Run()
{
    &lt;span style="color: #2b91af"&gt;IRegion &lt;/span&gt;region = &lt;span style="color: blue"&gt;this&lt;/span&gt;._regionManager.Regions[&lt;span style="color: #2b91af"&gt;RegionNames&lt;/span&gt;.Navigation];
    region.Add(&lt;span style="color: blue"&gt;this&lt;/span&gt;._projectTreeViewModel.View);
    region.Activate(&lt;span style="color: blue"&gt;this&lt;/span&gt;._projectTreeViewModel.View);
}&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;The call to the Activate method is essential if you want to be able to see your View. Until the Activate method is called, you will not be able to see your View.&lt;/p&gt;

&lt;p&gt;The Run method of the ProjectController is called in the Initialize method of the ProjectModule after registering the required views and services, as shown in the following code example.&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;#region &lt;/span&gt;Private Methods&amp;#160; &lt;span style="color: blue"&gt;private void &lt;/span&gt;RegisterViewsAndServices()
{
    &lt;span style="color: green"&gt;// NOTE: The ContainerControlledLifetimeManager ensures that the same
    //       instance is returned by any call to Resolve or ResolveAll.
    &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;._container.RegisterType&amp;lt;&lt;span style="color: #2b91af"&gt;IProjectService&lt;/span&gt;, &lt;span style="color: #2b91af"&gt;ProjectService&lt;/span&gt;&amp;gt;(&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;ContainerControlledLifetimeManager&lt;/span&gt;());
    &lt;span style="color: blue"&gt;this&lt;/span&gt;._container.RegisterType&amp;lt;&lt;span style="color: #2b91af"&gt;IProjectController&lt;/span&gt;, &lt;span style="color: #2b91af"&gt;ProjectController&lt;/span&gt;&amp;gt;(&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;ContainerControlledLifetimeManager&lt;/span&gt;());
    &lt;span style="color: blue"&gt;this&lt;/span&gt;._container.RegisterType&amp;lt;&lt;span style="color: #2b91af"&gt;IProjectTreeView&lt;/span&gt;, &lt;span style="color: #2b91af"&gt;ProjectTreeView&lt;/span&gt;&amp;gt;();
    &lt;span style="color: blue"&gt;this&lt;/span&gt;._container.RegisterType&amp;lt;&lt;span style="color: #2b91af"&gt;IProjectTreeViewModel&lt;/span&gt;, &lt;span style="color: #2b91af"&gt;ProjectTreeViewModel&lt;/span&gt;&amp;gt;();
}

&lt;span style="color: blue"&gt;#endregion &lt;/span&gt;Private Methods&amp;#160; &lt;span style="color: blue"&gt;#region &lt;/span&gt;IModule Members

&lt;span style="color: blue"&gt;public void &lt;/span&gt;Initialize()
{
    RegisterViewsAndServices();
    &lt;span style="color: #2b91af"&gt;IProjectController &lt;/span&gt;controller = &lt;span style="color: blue"&gt;this&lt;/span&gt;._container.Resolve&amp;lt;&lt;span style="color: #2b91af"&gt;IProjectController&lt;/span&gt;&amp;gt;();
    controller.Run();
}

&lt;span style="color: blue"&gt;#endregion
&lt;/span&gt;&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;As you can see in the screen shot above, apart from writing all the tests, putting some simple content in the ViewModel, a bit of work on the infrastructure and doing a lot of head scratching, that's it! Granted it's just a pink rectangle at the moment, but I now have a View that is loaded into the right place.&lt;/p&gt;

&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px" id="scid:53649e20-5a41-11dd-ae16-0800200c9a66:d98814d5-23df-40de-867b-a52046f26543" class="wlWriterSmartContent"&gt;&lt;/div&gt;
My next step is to put some useful UI code into the View and try to gradually incorporate some of the visual functionality of it's predecessor.&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=u9m-wrbLSVE:BQSPLxhgp1k:4cEx4HpKnUU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?i=u9m-wrbLSVE:BQSPLxhgp1k:4cEx4HpKnUU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=u9m-wrbLSVE:BQSPLxhgp1k:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=u9m-wrbLSVE:BQSPLxhgp1k:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?i=u9m-wrbLSVE:BQSPLxhgp1k:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=u9m-wrbLSVE:BQSPLxhgp1k:oCFASsrFxfc"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?d=oCFASsrFxfc" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=u9m-wrbLSVE:BQSPLxhgp1k:Jwdi1b3fU3Q"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?d=Jwdi1b3fU3Q" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=u9m-wrbLSVE:BQSPLxhgp1k:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?i=u9m-wrbLSVE:BQSPLxhgp1k:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/cloudstore/~4/u9m-wrbLSVE" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/cloudstore/~3/u9m-wrbLSVE/migrating-legacy-wpf-application-to_06.html</link><author>noreply@blogger.com (Derek Lakin)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://lh5.ggpht.com/derek.lakin/SOoLXD9inbI/AAAAAAAAAGc/XvP59vSS0S0/s72-c/Prism.FirstView.Structure%5B5%5D.png?imgmax=800" height="72" width="72" /><thr:total>2</thr:total><feedburner:origLink>http://cloudstore.blogspot.com/2008/10/migrating-legacy-wpf-application-to_06.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-804082557306552579.post-7326445858931690860</guid><pubDate>Thu, 02 Oct 2008 09:13:00 +0000</pubDate><atom:updated>2009-03-31T10:54:06.405+01:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">WPF</category><category domain="http://www.blogger.com/atom/ns#">Prism</category><category domain="http://www.blogger.com/atom/ns#">composite</category><category domain="http://www.blogger.com/atom/ns#">.net</category><category domain="http://www.blogger.com/atom/ns#">XAML</category><category domain="http://www.blogger.com/atom/ns#">CodeProject</category><category domain="http://www.blogger.com/atom/ns#">c#</category><category domain="http://www.blogger.com/atom/ns#">Visual Studio</category><category domain="http://www.blogger.com/atom/ns#">UI</category><category domain="http://www.blogger.com/atom/ns#">Microsoft</category><category domain="http://www.blogger.com/atom/ns#">refactor</category><title>Migrating a Legacy WPF Application to Prism - Part 1</title><description>&lt;p&gt;This is the first of several posts on my journey migrating a legacy application to use the Composite Application Guidance for WPF, which (like &lt;a href="http://www.softinsight.com/bnoyes/2008/07/03/CompositeApplicationGuidanceForWPFAkaPrismShips.aspx"&gt;Brian Noyes&lt;/a&gt;) I prefer to call Prism, mainly because it's shorter, but it's also cooler!&lt;/p&gt;  &lt;p&gt;I've watched the &amp;quot;&lt;a href="http://www.dnrtv.com/default.aspx?showNum=124"&gt;Brian Noyes on Prism&lt;/a&gt;&amp;quot; dnr TV episode intently, read through the guidance documentation, I've done the hands-on lab, all of the quick starts and dissected and analysed the StockTraderRI sample application, so now I figure I'm ready to start cranking some Prism code for our legacy application&lt;sup&gt;1&lt;/sup&gt;.&lt;/p&gt;  &lt;p&gt;&lt;sup&gt;1&lt;/sup&gt;By &amp;quot;legacy&amp;quot; I mean that it's a regular WPF application that was not created using the Prism (or any other specific) guidance, so it's not a green field project.&lt;/p&gt;  &lt;h3&gt;Understanding the Terminology&lt;/h3&gt;  &lt;p&gt;I don't pretend to be completely clued up on all aspects of design patterns, but I'm aware of the key concepts behind &lt;a href="http://en.wikipedia.org/wiki/Model-view-controller"&gt;Model-View-Controller&lt;/a&gt; (MVC) and it's numerous variants, so when I opened up the StockTraderRI sample application I was initially a bit confused to see a combination of Presenters from &lt;a href="http://msdn.microsoft.com/en-us/magazine/cc188690.aspx"&gt;Model-View-Presenter&lt;/a&gt; (MVP; also referred to as Supervising Controller in the guidance), Controllers from MVC, and PresentationModels from &lt;a href="http://www.martinfowler.com/eaaDev/PresentationModel.html"&gt;Presentation Model&lt;/a&gt;, or &lt;a href="http://blogs.sqlxml.org/bryantlikes/archive/2006/09/27/WPF-Patterns.aspx"&gt;Model-View-ViewModel&lt;/a&gt; (MVVM) to give it its more WPF-focused name.&lt;/p&gt;  &lt;p&gt;After a bit of digging it was clear that the Prism team were using a mixture of approaches and for good reason (of course), which I thought I'd just quickly explain for my own recording purposes if nothing else.&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;strong&gt;Model&lt;/strong&gt;: The underlying business entities that represent the data in your system (pretty much standard throughout all of the MV* patterns). E.g. &lt;code&gt;StockTraderRI.Infrastructure.Models.NewsArticle&lt;/code&gt; class in the StockTraderRI sample. &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;View&lt;/strong&gt;: The user interface representation of the underlying Model (also pretty much standard throughout all of the MV* patterns). E.g. &lt;code&gt;StockTraderRI.Modules.News.Article.ArticleView&lt;/code&gt; class in the StockTraderRI sample. &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;Presenter&lt;/strong&gt;: When the Model can provide the data that the View requires without any complex manipulation or transformation, then the View binds directly to the Model and the Presenter handles the state of the View in the cases where complex user interface logic is required, such as changing colours of controls and showing/hiding controls. E.g. &lt;code&gt;StockTraderRI.Modules.News.Article.NewsReaderPresenter&lt;/code&gt; class in the StockTraderRI sample. The &lt;code&gt;NewsReader&lt;/code&gt; View binds directly to properties of the &lt;code&gt;NewsArticle&lt;/code&gt; Model class, which is supplied by the &lt;code&gt;NewsReaderPresenter&lt;/code&gt;. &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;PresentationModel&lt;/strong&gt;: When the View cannot bind directly to the Model, a PresentationModel class is used to provide the Model in a format more easily consumed by the View acting as a fa&amp;#231;ade. The PresentationModel class also manages UI-specific state and behaviour. E.g. &lt;code&gt;StockTraderRI.Modules.News.Article.ArticlePresentationModel&lt;/code&gt; class in the StockTraderRI sample. The &lt;code&gt;ArticleView&lt;/code&gt; class binds Articles property exposed by the &lt;code&gt;ArticlePresentationModel&lt;/code&gt; class. Note: Given that MVVM is a WPF-specific variation of&amp;#160; Martin Fowler's Presentation Model pattern, I prefer the term ViewModel to PresentationModel; if nothing else it's shorter :) &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;Controller&lt;/strong&gt;: The StockTraderRI sample application uses Controller classes to manage the interaction between multiple views. E.g. &lt;code&gt;StockTraderRI.Modules.News.Controllers.NewsController&lt;/code&gt; class, which manages interactions between the &lt;code&gt;ArticleView&lt;/code&gt; and the &lt;code&gt;NewsReader&lt;/code&gt; View via the &lt;code&gt;ArticlePresentationModel&lt;/code&gt; and &lt;code&gt;NewsReaderPresenter&lt;/code&gt;. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;There is a discussion about the patterns used in Prism (and hence the sample application) in the guidance documentation, but the above helped to put things straight in my mind.&lt;/p&gt;  &lt;h3&gt;Getting Started&lt;/h3&gt;  &lt;p&gt;The first thing I did to get me started down the road to a Prism-based application was to implement the Bootstrapper, which I did as follows:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Added references to the following Prism assemblies in my main (shell) project:      &lt;ul&gt;       &lt;li&gt;Microsoft.Practices.Composite.dll &lt;/li&gt;        &lt;li&gt;Microsoft.Practices.Composite.Wpf.dll &lt;/li&gt;        &lt;li&gt;Microsoft.Practices.UnityExcetions.dll &lt;/li&gt;        &lt;li&gt;Microsoft.Practices.Unit.dll &lt;/li&gt;        &lt;li&gt;Microsoft.Practices.ObjectBuilder.dll &lt;/li&gt;     &lt;/ul&gt;   &lt;/li&gt;    &lt;li&gt;Added a new class called &lt;code&gt;MyApplicationBootstrapper&lt;/code&gt;&lt;sup&gt;2&lt;/sup&gt;, which inherits from &lt;code&gt;UnityBootstrapper&lt;/code&gt; as shown in the following code example.       &lt;pre class="code"&gt;    &lt;span style="color: blue"&gt;public class &lt;/span&gt;&lt;span style="color: #2b91af"&gt;MyApplicationBootstrapper &lt;/span&gt;: &lt;span style="color: #2b91af"&gt;UnityBootstrapper
    &lt;/span&gt;{
        &lt;span style="color: blue"&gt;protected override &lt;/span&gt;&lt;span style="color: #2b91af"&gt;DependencyObject &lt;/span&gt;CreateShell()
        {
            &lt;span style="color: #2b91af"&gt;MainWindow &lt;/span&gt;window = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;MainWindow&lt;/span&gt;();
            window.Show();
            &lt;span style="color: blue"&gt;return &lt;/span&gt;window;
        }

        &lt;span style="color: blue"&gt;protected override &lt;/span&gt;&lt;span style="color: #2b91af"&gt;IModuleEnumerator &lt;/span&gt;GetModuleEnumerator()
        {
            &lt;span style="color: blue"&gt;return &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;StaticModuleEnumerator&lt;/span&gt;();
        }&lt;br /&gt;&amp;#160;&amp;#160; }&lt;/pre&gt;
    &lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;/li&gt;

  &lt;li&gt;Removed the &lt;code&gt;StartupUri&lt;/code&gt; property from App.xaml. &lt;/li&gt;

  &lt;li&gt;Created an instance of&amp;#160; in the &lt;code&gt;Application.Startup&lt;/code&gt; event handler as shown in the following code example. &lt;/li&gt;

  &lt;pre class="code"&gt;&lt;span style="color: blue"&gt;private void &lt;/span&gt;Application_Startup(&lt;span style="color: blue"&gt;object &lt;/span&gt;sender, &lt;span style="color: #2b91af"&gt;StartupEventArgs &lt;/span&gt;e)
{
    &lt;span style="color: #2b91af"&gt;MyApplicationBootstrapper &lt;/span&gt;bootstrapper = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;MyApplicationBootstrapper&lt;/span&gt;();
    bootstrapper.Run();
}&lt;/pre&gt;
  &lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;/ol&gt;

&lt;p&gt;&lt;sup&gt;2&lt;/sup&gt; I've substituted &amp;quot;MyApplication&amp;quot; for the name of the actual application to protect the interests of my &lt;a href="http://www.contentmaster.com"&gt;employer&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;So far so good. The application runs as it did before but now it uses a Bootstrapper. Nothing dramatic and no big benefits yet, but it works. Next step, start writing some tests and a some modules to contain the existing UI controls as views in a more Prism-like approach.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; I welcome (encourage even) any corrections/comments/etc about the approach that I'm taking or on any of the detail that I've included in this post (and future posts).&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=Z-a8pOgUDgI:cmMCUh_DR4Q:4cEx4HpKnUU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?i=Z-a8pOgUDgI:cmMCUh_DR4Q:4cEx4HpKnUU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=Z-a8pOgUDgI:cmMCUh_DR4Q:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=Z-a8pOgUDgI:cmMCUh_DR4Q:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?i=Z-a8pOgUDgI:cmMCUh_DR4Q:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=Z-a8pOgUDgI:cmMCUh_DR4Q:oCFASsrFxfc"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?d=oCFASsrFxfc" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=Z-a8pOgUDgI:cmMCUh_DR4Q:Jwdi1b3fU3Q"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?d=Jwdi1b3fU3Q" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=Z-a8pOgUDgI:cmMCUh_DR4Q:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?i=Z-a8pOgUDgI:cmMCUh_DR4Q:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/cloudstore/~4/Z-a8pOgUDgI" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/cloudstore/~3/Z-a8pOgUDgI/migrating-legacy-wpf-application-to.html</link><author>noreply@blogger.com (Derek Lakin)</author><thr:total>3</thr:total><feedburner:origLink>http://cloudstore.blogspot.com/2008/10/migrating-legacy-wpf-application-to.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-804082557306552579.post-460355854989448963</guid><pubDate>Tue, 16 Sep 2008 16:21:00 +0000</pubDate><atom:updated>2009-03-31T10:53:30.928+01:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">WPF</category><category domain="http://www.blogger.com/atom/ns#">custom</category><category domain="http://www.blogger.com/atom/ns#">XAML</category><category domain="http://www.blogger.com/atom/ns#">CodeProject</category><title>Changing the Caret Colour in WPF</title><description>&lt;p&gt;In WPF, you don’t have direct control over the colour of the caret in a &lt;a title="TextBox Class" href="http://msdn2.microsoft.com/ms617604.aspx"&gt;TextBox&lt;/a&gt; or a &lt;a title="RichTextBox Class" href="http://msdn2.microsoft.com/ms612650.aspx"&gt;RichTextBox&lt;/a&gt;. What the framework does is to use the inverse of the colour that you choose for the &lt;a title="TextBox..::.Background Property " href="http://msdn2.microsoft.com/cc190319.aspx"&gt;Background&lt;/a&gt; property. I’ve seen a few examples of styles that explicitly set the &lt;a title="TextBox..::.Background Property " href="http://msdn2.microsoft.com/cc190319.aspx"&gt;Background&lt;/a&gt; property to &lt;code&gt;{x:Null}&lt;/code&gt; to completely remove the background from the &lt;a title="TextBox Class" href="http://msdn2.microsoft.com/ms617604.aspx"&gt;TextBox&lt;/a&gt;, which enables you to use the same style when then the &lt;a title="TextBox Class" href="http://msdn2.microsoft.com/ms617604.aspx"&gt;TextBox&lt;/a&gt; is used on top of different backgrounds that you want to show through.&lt;/p&gt;  &lt;p&gt;Because the framework uses the inverse of the &lt;a title="TextBox..::.Background Property " href="http://msdn2.microsoft.com/cc190319.aspx"&gt;Background&lt;/a&gt; colour to set the colour of the caret, if you set the &lt;a title="TextBox..::.Background Property " href="http://msdn2.microsoft.com/cc190319.aspx"&gt;Background&lt;/a&gt; property to &lt;code&gt;{x:Null}&lt;/code&gt;, then you will end up with the default black caret, which on a black background can be particularly difficult to see!&lt;/p&gt;  &lt;h2&gt;The Solution&lt;/h2&gt;  &lt;p&gt;The simple solution to this problem is to use actually specify a value for the &lt;a title="TextBox..::.Background Property " href="http://msdn2.microsoft.com/cc190319.aspx"&gt;Background&lt;/a&gt; property. In the case where you have a black background and want a white caret, then you can set the value of the &lt;a title="TextBox..::.Background Property " href="http://msdn2.microsoft.com/cc190319.aspx"&gt;Background&lt;/a&gt; property to &lt;code&gt;#00000000&lt;/code&gt;, which is completely transparent black (if that makes sense!). The framework appears to ignore the opacity component of the colour so you end up with a transparent background and a white caret!&lt;/p&gt;  &lt;h2&gt;Taking it One Step Further&lt;/h2&gt;  &lt;p&gt;I haven’t tried this yet, but I assume that you can take this approach one step further to customise the colour of your caret by setting the Background to different colours with an opacity value of zero. This would then be a simpler solution that completely overriding the style as described by &lt;a href="http://blogs.msdn.com/llobo/default.aspx"&gt;Lester&lt;/a&gt; in his &lt;a href="http://blogs.msdn.com/llobo/archive/2007/02/08/changing-caret-color-in-textbox.aspx"&gt;Changing caret color in (Rich)TextBox&lt;/a&gt; post.&lt;/p&gt;&lt;div class="wlWriterHeaderFooter" style="margin:0px; padding:0px 0px 0px 0px;"&gt;This work is licensed under a &lt;a href="http://creativecommons.org/licenses/by/3.0/"&gt;Creative Commons Attribution By license.&lt;/a&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=LIu3ko0Cl_M:-nRvUfRGhyE:4cEx4HpKnUU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?i=LIu3ko0Cl_M:-nRvUfRGhyE:4cEx4HpKnUU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=LIu3ko0Cl_M:-nRvUfRGhyE:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=LIu3ko0Cl_M:-nRvUfRGhyE:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?i=LIu3ko0Cl_M:-nRvUfRGhyE:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=LIu3ko0Cl_M:-nRvUfRGhyE:oCFASsrFxfc"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?d=oCFASsrFxfc" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=LIu3ko0Cl_M:-nRvUfRGhyE:Jwdi1b3fU3Q"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?d=Jwdi1b3fU3Q" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=LIu3ko0Cl_M:-nRvUfRGhyE:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?i=LIu3ko0Cl_M:-nRvUfRGhyE:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/cloudstore/~4/LIu3ko0Cl_M" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/cloudstore/~3/LIu3ko0Cl_M/changing-caret-colour-in-wpf.html</link><author>noreply@blogger.com (Derek Lakin)</author><thr:total>2</thr:total><feedburner:origLink>http://cloudstore.blogspot.com/2008/09/changing-caret-colour-in-wpf.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-804082557306552579.post-1312816992723539821</guid><pubDate>Mon, 21 Jul 2008 15:52:00 +0000</pubDate><atom:updated>2008-07-21T16:52:57.818+01:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Titan</category><category domain="http://www.blogger.com/atom/ns#">extension method</category><category domain="http://www.blogger.com/atom/ns#">.net</category><category domain="http://www.blogger.com/atom/ns#">c#</category><title>Determining the Relative Path in XLinq with Extension Methods</title><description>&lt;h3&gt;Introduction&lt;/h3&gt;  &lt;p&gt;In Titan, I’m edging closer and closer to releasing a beta 1 for public consumption and one of the tasks that I’m working on to get me there is a lazy-loading folder browser dialog box that enables you to browse through the folder structure of a particular service without having to load the whole folder structure in one go. This is used specifically for specifying new service configurations and is of particular concern for the local file system provider. Have you ever tried to retrieve your whole hard disk structure in one go!?&lt;/p&gt;  &lt;p&gt;My service methods were already using some XLinq to parse the XML response from the &lt;a href="http://box.net"&gt;Box.net&lt;/a&gt; service call and the local file system provider, but for the &lt;a href="http://box.net"&gt;Box.net&lt;/a&gt; service provider I needed a way of finding a particular folder based on it’s relative path. The contents of a fictitious &lt;a href="http://box.net"&gt;Box.net&lt;/a&gt; folder structure could look like the following XML example.&lt;/p&gt;  &lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;folder &lt;/span&gt;&lt;span style="color: red"&gt;id&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;0&lt;/span&gt;&amp;quot; &lt;span style="color: red"&gt;name&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&amp;quot; &lt;span style="color: red"&gt;shared&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;0&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;&amp;gt;
  &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;tags&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;tags&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
  &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;files&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;files&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
  &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;folders&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
     &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;folder &lt;/span&gt;&lt;span style="color: red"&gt;id&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;4384&lt;/span&gt;&amp;quot; &lt;span style="color: red"&gt;name&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;Incoming&lt;/span&gt;&amp;quot; &lt;span style="color: red"&gt;shared&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;0&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;&amp;gt;
        &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;tags&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
           &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;tag &lt;/span&gt;&lt;span style="color: red"&gt;id&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;34&lt;/span&gt;&amp;quot; &lt;span style="color: blue"&gt;/&amp;gt;
         &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;tags&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
         &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;files&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
            &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;file &lt;/span&gt;&lt;span style="color: red"&gt;id&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;68736&lt;/span&gt;&amp;quot; &lt;span style="color: red"&gt;file_name&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;cows.w3g&lt;/span&gt;&amp;quot; &lt;span style="color: red"&gt;keyword&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&amp;quot; &lt;span style="color: red"&gt;shared&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;0&lt;/span&gt;&amp;quot; &lt;span style="color: red"&gt;size&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;232386&lt;/span&gt;&amp;quot; &lt;span style="color: red"&gt;created&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;1129537520&lt;/span&gt;&amp;quot; &lt;span style="color: red"&gt;updated&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;1129537520&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;&amp;gt;
               &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;tags&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
               &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;tags&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
            &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;file&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
            &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;file &lt;/span&gt;&lt;span style="color: red"&gt;id&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;68737&lt;/span&gt;&amp;quot; &lt;span style="color: red"&gt;file_name&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;silver.html&lt;/span&gt;&amp;quot; &lt;span style="color: red"&gt;keyword&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&amp;quot; &lt;span style="color: red"&gt;shared&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;0&lt;/span&gt;&amp;quot; &lt;span style="color: red"&gt;size&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;15805&lt;/span&gt;&amp;quot; &lt;span style="color: red"&gt;created&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;1129537520&lt;/span&gt;&amp;quot; &lt;span style="color: red"&gt;updated&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;1129537520&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;&amp;gt;
               &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;tags&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
                  &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;tag &lt;/span&gt;&lt;span style="color: red"&gt;id&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;35&lt;/span&gt;&amp;quot; &lt;span style="color: blue"&gt;/&amp;gt;
               &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;tags&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
            &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;file&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
         &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;files&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
         &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;folders&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
             &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;folder &lt;/span&gt;&lt;span style="color: red"&gt;id&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;1234&lt;/span&gt;&amp;quot; &lt;span style="color: red"&gt;name&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;Test&lt;/span&gt;&amp;quot; &lt;span style="color: red"&gt;shared&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;0&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;&amp;gt;
                &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;folders&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
                    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;folder &lt;/span&gt;&lt;span style="color: red"&gt;id&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;2345&lt;/span&gt;&amp;quot; &lt;span style="color: red"&gt;name&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;wibble&lt;/span&gt;&amp;quot; &lt;span style="color: red"&gt;shared&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;0&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;&amp;gt;
                        &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;folders &lt;/span&gt;&lt;span style="color: blue"&gt;/&amp;gt;
                    &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;folder&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
                    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;folder &lt;/span&gt;&lt;span style="color: red"&gt;id&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;5432&lt;/span&gt;&amp;quot; &lt;span style="color: red"&gt;name&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;wobble&lt;/span&gt;&amp;quot; &lt;span style="color: red"&gt;shared&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;0&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;&amp;gt;
                        &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;folders &lt;/span&gt;&lt;span style="color: blue"&gt;/&amp;gt;
                    &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;folder&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
                &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;folders&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
            &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;folder&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
            &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;folder &lt;/span&gt;&lt;span style="color: red"&gt;id&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;4321&lt;/span&gt;&amp;quot; &lt;span style="color: red"&gt;name&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;Test2&lt;/span&gt;&amp;quot; &lt;span style="color: red"&gt;shared&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;0&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;&amp;gt;
                &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;folders &lt;/span&gt;&lt;span style="color: blue"&gt;/&amp;gt;
            &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;folder&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
         &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;folders&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
      &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;folder&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
   &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;folders&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;folder&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;h3&gt;The Problem&lt;/h3&gt;

&lt;p&gt;So, if I want to retrieve the folder contents of the folder named Test, which has a relative path of “\Incoming\Test”, how do I find that in XLinq? Well, I looked at all kinds of different approaches using the &lt;a title="Extensions..::.Descendants Method " href="http://msdn2.microsoft.com/bb156019.aspx"&gt;Descendants&lt;/a&gt; and &lt;a title="Extensions..::.Ancestors Method " href="http://msdn2.microsoft.com/bb340711.aspx"&gt;Ancestors&lt;/a&gt; methods, but none of them managed to produce the goods, because I needed a single string that I could compare against.&lt;/p&gt;

&lt;h3&gt;The Solution&lt;/h3&gt;

&lt;p&gt;To solve the problem I decided to use an extension method to produce a single string from a collection. The results of an XLinq query are &lt;a href="http://msdn.microsoft.com/en-gb/9eekhta0.aspx"&gt;IEnumerable&amp;lt;T&amp;gt;&lt;/a&gt;, where T depends on the exact nature of the query. In my case, I was pulling out the name attribute, so I had IEnumerable&amp;lt;string&amp;gt;. The extension method shown in the following code example uses a &lt;a title="StringBuilder Class" href="http://msdn2.microsoft.com/y9sxk6fy.aspx"&gt;StringBuilder&lt;/a&gt; to build up the single string.&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: gray"&gt;/// &amp;lt;summary&amp;gt;
/// &lt;/span&gt;&lt;span style="color: green"&gt;Converts the IEnumerable&lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;string&amp;gt; &lt;/span&gt;&lt;span style="color: green"&gt;to a single string.
&lt;/span&gt;&lt;span style="color: gray"&gt;/// &amp;lt;/summary&amp;gt;
/// &amp;lt;param name=&amp;quot;source&amp;quot;&amp;gt;&lt;/span&gt;&lt;span style="color: green"&gt;The source IEnumerable&lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;string&amp;gt;&lt;/span&gt;&lt;span style="color: green"&gt;.&lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;/param&amp;gt;
/// &amp;lt;returns&amp;gt;&lt;/span&gt;&lt;span style="color: green"&gt;A single string that represents the contents of the IEnumberable&lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;string&amp;gt;&amp;lt;/returns&amp;gt;
&lt;/span&gt;&lt;span style="color: blue"&gt;public static string &lt;/span&gt;ToOneString(&lt;span style="color: blue"&gt;this &lt;/span&gt;&lt;span style="color: #2b91af"&gt;IEnumerable&lt;/span&gt;&amp;lt;&lt;span style="color: blue"&gt;string&lt;/span&gt;&amp;gt; source)
{
    &lt;span style="color: #2b91af"&gt;StringBuilder &lt;/span&gt;builder = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;StringBuilder&lt;/span&gt;();

    &lt;span style="color: green"&gt;// Add each item.
    &lt;/span&gt;&lt;span style="color: blue"&gt;foreach &lt;/span&gt;(&lt;span style="color: blue"&gt;string &lt;/span&gt;item &lt;span style="color: blue"&gt;in &lt;/span&gt;source)
    {
        &lt;span style="color: blue"&gt;if &lt;/span&gt;(item.Length &amp;gt; 0)
        {
            builder.Append(item);
        }
    }

    &lt;span style="color: blue"&gt;return &lt;/span&gt;builder.ToString();
}&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;This didn’t quite solve the problem, because for my scenario described above, this produces a single string of “IncomingTest”, which isn’t quite a relative path. So, I added an overload for the method that accepts a string separator to produce the following.&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: gray"&gt;/// &amp;lt;summary&amp;gt;
/// &lt;/span&gt;&lt;span style="color: green"&gt;Converts the IEnumerable&lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;string&amp;gt; &lt;/span&gt;&lt;span style="color: green"&gt;to a single string.
&lt;/span&gt;&lt;span style="color: gray"&gt;/// &amp;lt;/summary&amp;gt;
/// &amp;lt;param name=&amp;quot;source&amp;quot;&amp;gt;&lt;/span&gt;&lt;span style="color: green"&gt;The source IEnumerable&lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;string&amp;gt;&lt;/span&gt;&lt;span style="color: green"&gt;.&lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;/param&amp;gt;
/// &amp;lt;returns&amp;gt;&lt;/span&gt;&lt;span style="color: green"&gt;A single string that represents the contents of the IEnumberable&lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;string&amp;gt;&amp;lt;/returns&amp;gt;
&lt;/span&gt;&lt;span style="color: blue"&gt;public static string &lt;/span&gt;ToOneString(&lt;span style="color: blue"&gt;this &lt;/span&gt;&lt;span style="color: #2b91af"&gt;IEnumerable&lt;/span&gt;&amp;lt;&lt;span style="color: blue"&gt;string&lt;/span&gt;&amp;gt; source)
{
    &lt;span style="color: blue"&gt;return &lt;/span&gt;source.ToOneString(&lt;span style="color: blue"&gt;string&lt;/span&gt;.Empty);
}

&lt;span style="color: gray"&gt;/// &amp;lt;summary&amp;gt;
/// &lt;/span&gt;&lt;span style="color: green"&gt;Converts the IEnumerable&lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;string&amp;gt; &lt;/span&gt;&lt;span style="color: green"&gt;to a single string.
&lt;/span&gt;&lt;span style="color: gray"&gt;/// &amp;lt;/summary&amp;gt;
/// &amp;lt;param name=&amp;quot;source&amp;quot;&amp;gt;&lt;/span&gt;&lt;span style="color: green"&gt;The source IEnumerable&lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;string&amp;gt;&lt;/span&gt;&lt;span style="color: green"&gt;.&lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;/param&amp;gt;
/// &amp;lt;param name=&amp;quot;separator&amp;quot;&amp;gt;&lt;/span&gt;&lt;span style="color: green"&gt;A separator to be placed between each item in the string.&lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;/param&amp;gt;
/// &amp;lt;returns&amp;gt;&lt;/span&gt;&lt;span style="color: green"&gt;A single string that represents the contents of the IEnumberable&lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;string&amp;gt;&amp;lt;/returns&amp;gt;
&lt;/span&gt;&lt;span style="color: blue"&gt;public static string &lt;/span&gt;ToOneString(&lt;span style="color: blue"&gt;this &lt;/span&gt;&lt;span style="color: #2b91af"&gt;IEnumerable&lt;/span&gt;&amp;lt;&lt;span style="color: blue"&gt;string&lt;/span&gt;&amp;gt; source, &lt;span style="color: blue"&gt;string &lt;/span&gt;separator)
{
    &lt;span style="color: #2b91af"&gt;StringBuilder &lt;/span&gt;builder = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;StringBuilder&lt;/span&gt;();

    &lt;span style="color: green"&gt;// Add each item and the separator.
    &lt;/span&gt;&lt;span style="color: blue"&gt;foreach &lt;/span&gt;(&lt;span style="color: blue"&gt;string &lt;/span&gt;item &lt;span style="color: blue"&gt;in &lt;/span&gt;source)
    {
        &lt;span style="color: blue"&gt;if &lt;/span&gt;(item.Length &amp;gt; 0)
        {
            builder.Append(item);
            builder.Append(separator);
        }
    }

    &lt;span style="color: green"&gt;// Remove the final separator.
    &lt;/span&gt;&lt;span style="color: blue"&gt;if &lt;/span&gt;(builder.Length &amp;gt;= separator.Length)
    {
        builder.Remove(builder.Length - separator.Length, separator.Length);
    }

    &lt;span style="color: blue"&gt;return &lt;/span&gt;builder.ToString();
}&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;In my reusable library, I’ve also created a version of ToOneString for &lt;a href="http://msdn.microsoft.com/en-gb/9eekhta0.aspx"&gt;IEnumerable&amp;lt;T&amp;gt;&lt;/a&gt;, which simply appends item.ToString() to the &lt;a title="StringBuilder Class" href="http://msdn2.microsoft.com/y9sxk6fy.aspx"&gt;StringBuilder&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;And Finally&lt;/h3&gt;

&lt;p&gt;So, my final XLinq query that builds up the relative path and returns me the folders for a specific relative path looks like the following code example, where &lt;code&gt;relativePath&lt;/code&gt; is a string parameter to the method that specifies the relative path to the folder that I want to retrieve the child folders.&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;query = 
    (&lt;span style="color: blue"&gt;from &lt;/span&gt;d &lt;span style="color: blue"&gt;in &lt;/span&gt;xRoot.DescendantsAndSelf(&lt;span style="color: #a31515"&gt;&amp;quot;folder&amp;quot;&lt;/span&gt;)
     &lt;span style="color: blue"&gt;where &lt;/span&gt;&lt;span style="color: #a31515"&gt;&amp;quot;\\&amp;quot; &lt;/span&gt;+ (&lt;span style="color: blue"&gt;from &lt;/span&gt;a &lt;span style="color: blue"&gt;in &lt;/span&gt;d.AncestorsAndSelf(&lt;span style="color: #a31515"&gt;&amp;quot;folder&amp;quot;&lt;/span&gt;)
                   &lt;span style="color: blue"&gt;select &lt;/span&gt;a.Attribute(&lt;span style="color: #a31515"&gt;&amp;quot;name&amp;quot;&lt;/span&gt;).Value).Reverse().ToOneString(&lt;span style="color: #a31515"&gt;&amp;quot;\\&amp;quot;&lt;/span&gt;) == relativePath
     &lt;span style="color: blue"&gt;select &lt;/span&gt;d.Element(&lt;span style="color: #a31515"&gt;&amp;quot;folders&amp;quot;&lt;/span&gt;).Elements(&lt;span style="color: #a31515"&gt;&amp;quot;folder&amp;quot;&lt;/span&gt;)).First();&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;If there are any folders in the specified folder, then I can enumerate the resulting &lt;a title="XElement Class" href="http://msdn2.microsoft.com/bb340098.aspx"&gt;XElement&lt;/a&gt; collection and build up instances of my &lt;code&gt;File&lt;/code&gt; class.&lt;/p&gt;&lt;div class="wlWriterHeaderFooter" style="margin:0px; padding:0px 0px 0px 0px;"&gt;This work is licensed under a &lt;a href="http://creativecommons.org/licenses/by/3.0/"&gt;Creative Commons Attribution By license.&lt;/a&gt;&lt;/div&gt;&lt;div class="wlWriterHeaderFooter" style="margin:0px; padding:0px 0px 0px 0px;"&gt;&lt;a href="http://www.dotnetkicks.com/kick/?url=http://cloudstore.blogspot.com/2008/07/determining-relative-path-in-xlinq-with.html"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://cloudstore.blogspot.com/2008/07/determining-relative-path-in-xlinq-with.html&amp;amp;bgcolor=0080C0&amp;amp;fgcolor=FFFFFF&amp;amp;border=000000&amp;amp;cbgcolor=D4E1ED&amp;amp;cfgcolor=000000" border="0/"&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class="wlWriterHeaderFooter" style="text-align:left; margin:0px; padding:4px 4px 4px 4px;"&gt;&lt;script type="text/javascript"&gt;var dzone_url = 'http://cloudstore.blogspot.com/2008/07/determining-relative-path-in-xlinq-with.html';&lt;/script&gt;&lt;script type="text/javascript"&gt;var dzone_title = 'Determining the Relative Path in XLinq with Extension Methods';&lt;/script&gt;&lt;script type="text/javascript"&gt;var dzone_blurb = 'Determining the Relative Path in XLinq with Extension Methods';&lt;/script&gt;&lt;script type="text/javascript"&gt;var dzone_style = '2';&lt;/script&gt;&lt;script language="javascript" src="http://widgets.dzone.com/widgets/zoneit.js"&gt;&lt;/script&gt; &lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=EiXThwAOhho:I5J3cD600IU:4cEx4HpKnUU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?i=EiXThwAOhho:I5J3cD600IU:4cEx4HpKnUU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=EiXThwAOhho:I5J3cD600IU:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=EiXThwAOhho:I5J3cD600IU:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?i=EiXThwAOhho:I5J3cD600IU:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=EiXThwAOhho:I5J3cD600IU:oCFASsrFxfc"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?d=oCFASsrFxfc" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=EiXThwAOhho:I5J3cD600IU:Jwdi1b3fU3Q"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?d=Jwdi1b3fU3Q" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=EiXThwAOhho:I5J3cD600IU:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?i=EiXThwAOhho:I5J3cD600IU:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/cloudstore/~4/EiXThwAOhho" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/cloudstore/~3/EiXThwAOhho/determining-relative-path-in-xlinq-with.html</link><author>noreply@blogger.com (Derek Lakin)</author><thr:total>0</thr:total><feedburner:origLink>http://cloudstore.blogspot.com/2008/07/determining-relative-path-in-xlinq-with.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-804082557306552579.post-7092663023665171348</guid><pubDate>Thu, 26 Jun 2008 07:17:00 +0000</pubDate><atom:updated>2009-03-31T10:53:05.485+01:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">WPF</category><category domain="http://www.blogger.com/atom/ns#">Titan</category><category domain="http://www.blogger.com/atom/ns#">.net</category><category domain="http://www.blogger.com/atom/ns#">XAML</category><category domain="http://www.blogger.com/atom/ns#">CodeProject</category><category domain="http://www.blogger.com/atom/ns#">styles</category><title>Creating a Custom View Mode that Supports a Template Selector</title><description>&lt;h3&gt;Background&lt;/h3&gt;  &lt;p&gt;The controls that inherit from &lt;a title="ItemsControl Class" href="http://msdn2.microsoft.com/ms611045.aspx"&gt;ItemsControl&lt;/a&gt; (such as &lt;a title="ListBox Class" href="http://msdn2.microsoft.com/ms611062.aspx"&gt;ListBox&lt;/a&gt;, &lt;a title="ListView Class" href="http://msdn2.microsoft.com/ms611074.aspx"&gt;ListView&lt;/a&gt;, and so on) expose an &lt;a title="ItemsControl..::.ItemTemplateSelector Property " href="http://msdn2.microsoft.com/ms593020.aspx"&gt;ItemTemplateSelector&lt;/a&gt; property that you can use instead of the &lt;a title="ItemsControl..::.ItemTemplate Property " href="http://msdn2.microsoft.com/ms593017.aspx"&gt;ItemTemplate&lt;/a&gt; property to specify a &lt;a title="DataTemplateSelector Class" href="http://msdn2.microsoft.com/ms609837.aspx"&gt;DataTemplateSelector&lt;/a&gt;. The &lt;a title="DataTemplateSelector Class" href="http://msdn2.microsoft.com/ms609837.aspx"&gt;DataTemplateSelector&lt;/a&gt; enables you to specify your own custom logic that determines which &lt;a title="DataTemplate Class" href="http://msdn2.microsoft.com/ms589297.aspx"&gt;DataTemplate&lt;/a&gt; should be applied to each item.&lt;/p&gt;  &lt;p&gt;There are a number of blog posts out there already that give good instructions on how to implement a &lt;a title="DataTemplateSelector Class" href="http://msdn2.microsoft.com/ms609837.aspx"&gt;DataTemplateSelector&lt;/a&gt;, typically for tasks such as selected item highlighting or alternate background colours for list boxes, so I won’t go into the details there. The Queen of Data Binding: &lt;a href="http://www.beacosta.com/blog"&gt;Bea Costa&lt;/a&gt;, has a great post on the subject: &lt;a href="http://www.beacosta.com/blog/?p=16"&gt;How do I display items in an ItemsControl using different templates?&lt;/a&gt;&lt;/p&gt;  &lt;h3&gt;The Problem&lt;/h3&gt;  &lt;p&gt;However, there seems to be very few resources (none that I could find) that show you how to implement a custom view mode for the &lt;a title="ListView Class" href="http://msdn2.microsoft.com/ms611074.aspx"&gt;ListView&lt;/a&gt; control that implements that same template selection functionality, which brings me to the purpose of this post.&lt;/p&gt;  &lt;p&gt;&lt;a title="Custom View Mode with Template Selection" href="http://www.flickr.com/photos/51035614344@N01/2609832041/"&gt;&lt;img style="margin: 0px 5px 0px 0px" alt="Custom View Mode with Template Selection" src="http://static.flickr.com/3088/2609832041_2c6a01737c_m.jpg" align="left" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;In Titan, the main files and folders view is created by using a &lt;a title="ListView Class" href="http://msdn2.microsoft.com/ms611074.aspx"&gt;ListView&lt;/a&gt; control that uses a custom view mode (like &lt;a title="GridView Class" href="http://msdn2.microsoft.com/ms610560.aspx"&gt;GridView&lt;/a&gt;, but this one does a Windows Explorer style tile view). The problem I had was that I wanted to always use the same icon for a folder, but to use a different icon for a file depending on it’s file extension. I managed to achieve this initially by using triggers, but then I realised that I wanted to provide different commands for files and folders.&lt;/p&gt;  &lt;p&gt;The available commands are bound onto the &lt;a title="ContextMenu Class" href="http://msdn2.microsoft.com/ms609810.aspx"&gt;ContextMenu&lt;/a&gt; for each item and the triggers approach just wasn’t working for trying to change the context menu, so I came to the realisation that what I actually wanted was a separate &lt;a title="DataTemplate Class" href="http://msdn2.microsoft.com/ms589297.aspx"&gt;DataTemplate&lt;/a&gt; for files and folders. The problem was that because I was using a custom view mode, I couldn’t use the &lt;a title="ItemsControl..::.ItemTemplateSelector Property " href="http://msdn2.microsoft.com/ms593020.aspx"&gt;ItemTemplateSelector&lt;/a&gt; on the &lt;a title="ListView Class" href="http://msdn2.microsoft.com/ms611074.aspx"&gt;ListView&lt;/a&gt; itself. Looking at the implementation of the &lt;a title="GridView Class" href="http://msdn2.microsoft.com/ms610560.aspx"&gt;GridView&lt;/a&gt; I realised that I could do what I wanted by implementing template selection on my custom view mode, which is what the &lt;a title="GridView Class" href="http://msdn2.microsoft.com/ms610560.aspx"&gt;GridView&lt;/a&gt; does by using the &lt;a title="GridView..::.ColumnHeaderTemplateSelector Property " href="http://msdn2.microsoft.com/ms592698.aspx"&gt;ColumnHeaderTemplateSelector&lt;/a&gt;.&lt;/p&gt;  &lt;h3&gt;The Solution&lt;/h3&gt;  &lt;h5&gt;1. Implement a Custom View Mode&lt;/h5&gt;  &lt;p&gt;To implement a custom view mode, you create a class that inherits from the &lt;a title="ViewBase Class" href="http://msdn2.microsoft.com/ms617879.aspx"&gt;ViewBase&lt;/a&gt; class. For more information on custom view modes, see &lt;a href="http://msdn.microsoft.com/en-us/library/ms748859.aspx"&gt;How to: Create a Custom View Mode for a ListView&lt;/a&gt; on the MSDN web site.&lt;/p&gt;  &lt;p&gt;There are three important additional steps to take to enable template selection for your custom view mode:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Add a new dependency property to expose the &lt;a title="DataTemplateSelector Class" href="http://msdn2.microsoft.com/ms609837.aspx"&gt;DataTemplateSelector&lt;/a&gt;. &lt;/li&gt;    &lt;li&gt;Change the dependency property definition for the existing &lt;code&gt;ItemTemplate&lt;/code&gt; dependency property to use a &lt;a title="PropertyChangedCallback Delegate" href="http://msdn2.microsoft.com/ms602989.aspx"&gt;PropertyChangedCallback&lt;/a&gt; that checks to see if both the &lt;code&gt;ItemTemplate&lt;/code&gt; and &lt;code&gt;ItemTemplateSelector&lt;/code&gt; have been specified. &lt;/li&gt;    &lt;li&gt;Override the &lt;a title="ViewBase..::.PrepareItem Method " href="http://msdn2.microsoft.com/ms590046.aspx"&gt;PrepareItem&lt;/a&gt; method. This is called for each item in advance of it’s display, which gives you the opportunity to call &lt;a title="DataTemplateSelector..::.SelectTemplate Method " href="http://msdn2.microsoft.com/ms558169.aspx"&gt;SelectTemplate&lt;/a&gt; on the supplied &lt;a title="DataTemplateSelector Class" href="http://msdn2.microsoft.com/ms609837.aspx"&gt;DataTemplateSelector&lt;/a&gt;.&lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;The following code example shows the relevant parts of my custom view mode.&lt;/p&gt;  &lt;pre class="code"&gt;&lt;span style="color: blue"&gt;using &lt;/span&gt;System.Diagnostics;
&lt;span style="color: blue"&gt;using &lt;/span&gt;System.Windows;
&lt;span style="color: blue"&gt;using &lt;/span&gt;System.Windows.Controls;

&lt;span style="color: blue"&gt;namespace &lt;/span&gt;DerekLakin.Libraries.Controls
{
    &lt;span style="color: blue"&gt;public class &lt;/span&gt;&lt;span style="color: #2b91af"&gt;TileView &lt;/span&gt;: &lt;span style="color: #2b91af"&gt;ViewBase
    &lt;/span&gt;{
        &lt;span style="color: blue"&gt;#region &lt;/span&gt;Dependency Properties
        ...
        &lt;span style="color: blue"&gt;public static readonly &lt;/span&gt;&lt;span style="color: #2b91af"&gt;DependencyProperty &lt;/span&gt;ItemTemplateProperty =
            &lt;span style="color: #2b91af"&gt;DependencyProperty&lt;/span&gt;.Register(&lt;span style="color: #a31515"&gt;&amp;quot;ItemTemplate&amp;quot;&lt;/span&gt;, &lt;span style="color: blue"&gt;typeof&lt;/span&gt;(&lt;span style="color: #2b91af"&gt;DataTemplate&lt;/span&gt;), &lt;span style="color: blue"&gt;typeof&lt;/span&gt;(&lt;span style="color: #2b91af"&gt;TileView&lt;/span&gt;),
                &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;FrameworkPropertyMetadata&lt;/span&gt;(
                    &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;PropertyChangedCallback&lt;/span&gt;(&lt;span style="color: #2b91af"&gt;TileView&lt;/span&gt;.OnItemTemplateChanged)));

        &lt;span style="color: blue"&gt;public &lt;/span&gt;&lt;span style="color: #2b91af"&gt;DataTemplate &lt;/span&gt;ItemTemplate
        {
            &lt;span style="color: blue"&gt;get &lt;/span&gt;{ &lt;span style="color: blue"&gt;return &lt;/span&gt;(&lt;span style="color: #2b91af"&gt;DataTemplate&lt;/span&gt;)GetValue(ItemTemplateProperty); }
            &lt;span style="color: blue"&gt;set &lt;/span&gt;{ SetValue(ItemTemplateProperty, &lt;span style="color: blue"&gt;value&lt;/span&gt;); }
        }

        &lt;span style="color: blue"&gt;public static readonly &lt;/span&gt;&lt;span style="color: #2b91af"&gt;DependencyProperty &lt;/span&gt;ItemTemplateSelectorProperty =
            &lt;span style="color: #2b91af"&gt;DependencyProperty&lt;/span&gt;.Register(&lt;span style="color: #a31515"&gt;&amp;quot;ItemTemplateSelector&amp;quot;&lt;/span&gt;,
                &lt;span style="color: blue"&gt;typeof&lt;/span&gt;(&lt;span style="color: #2b91af"&gt;DataTemplateSelector&lt;/span&gt;), &lt;span style="color: blue"&gt;typeof&lt;/span&gt;(&lt;span style="color: #2b91af"&gt;TileView&lt;/span&gt;), 
                &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;FrameworkPropertyMetadata&lt;/span&gt;(
                        &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;PropertyChangedCallback&lt;/span&gt;(&lt;span style="color: #2b91af"&gt;TileView&lt;/span&gt;.OnItemTemplateSelectorChanged)));

        &lt;span style="color: blue"&gt;public &lt;/span&gt;&lt;span style="color: #2b91af"&gt;DataTemplateSelector &lt;/span&gt;ItemTemplateSelector
        {
            &lt;span style="color: blue"&gt;get &lt;/span&gt;{ &lt;span style="color: blue"&gt;return &lt;/span&gt;(&lt;span style="color: #2b91af"&gt;DataTemplateSelector&lt;/span&gt;)GetValue(ItemTemplateSelectorProperty); }
            &lt;span style="color: blue"&gt;set &lt;/span&gt;{ SetValue(ItemTemplateSelectorProperty, &lt;span style="color: blue"&gt;value&lt;/span&gt;); }
        }

        &lt;span style="color: blue"&gt;public static readonly &lt;/span&gt;&lt;span style="color: #2b91af"&gt;DependencyProperty &lt;/span&gt;ItemWidthProperty =
            &lt;span style="color: #2b91af"&gt;WrapPanel&lt;/span&gt;.ItemWidthProperty.AddOwner(&lt;span style="color: blue"&gt;typeof&lt;/span&gt;(&lt;span style="color: #2b91af"&gt;TileView&lt;/span&gt;));

        &lt;span style="color: blue"&gt;public double &lt;/span&gt;ItemWidth
        {
            &lt;span style="color: blue"&gt;get &lt;/span&gt;{ &lt;span style="color: blue"&gt;return &lt;/span&gt;(&lt;span style="color: blue"&gt;double&lt;/span&gt;)GetValue(ItemWidthProperty); }
            &lt;span style="color: blue"&gt;set &lt;/span&gt;{ SetValue(ItemWidthProperty, &lt;span style="color: blue"&gt;value&lt;/span&gt;); }
        }
        &lt;span style="color: blue"&gt;#endregion

        #region &lt;/span&gt;Overrides
        ...
        &lt;span style="color: blue"&gt;protected override void &lt;/span&gt;PrepareItem(&lt;span style="color: #2b91af"&gt;ListViewItem &lt;/span&gt;item)
        {
            &lt;span style="color: blue"&gt;base&lt;/span&gt;.PrepareItem(item);

            &lt;span style="color: blue"&gt;object &lt;/span&gt;selector = &lt;span style="color: blue"&gt;this&lt;/span&gt;.ReadLocalValue(&lt;span style="color: #2b91af"&gt;TileView&lt;/span&gt;.ItemTemplateSelectorProperty);
            &lt;span style="color: blue"&gt;object &lt;/span&gt;template = &lt;span style="color: blue"&gt;this&lt;/span&gt;.ReadLocalValue(&lt;span style="color: #2b91af"&gt;TileView&lt;/span&gt;.ItemTemplateProperty);
            &lt;span style="color: blue"&gt;if &lt;/span&gt;(((&lt;span style="color: blue"&gt;null &lt;/span&gt;!= selector) &amp;amp;&amp;amp;
                 (&lt;span style="color: #2b91af"&gt;DependencyProperty&lt;/span&gt;.UnsetValue != selector)) &amp;amp;&amp;amp;
                ((&lt;span style="color: blue"&gt;null &lt;/span&gt;!= template) &amp;amp;&amp;amp;
                 (&lt;span style="color: #2b91af"&gt;DependencyProperty&lt;/span&gt;.UnsetValue != template)))
            {
                &lt;span style="color: green"&gt;// Both ItemTemplate and ItemTemplateSelector have been set.
                &lt;/span&gt;item.ContentTemplate = &lt;span style="color: blue"&gt;this&lt;/span&gt;.ItemTemplate;
            }
            &lt;span style="color: blue"&gt;else if &lt;/span&gt;((&lt;span style="color: blue"&gt;null &lt;/span&gt;!= selector) &amp;amp;&amp;amp;
                (&lt;span style="color: #2b91af"&gt;DependencyProperty&lt;/span&gt;.UnsetValue != selector))
            {
                &lt;span style="color: green"&gt;// Just ItemTemplateSelector has been set.
                &lt;/span&gt;item.ContentTemplate = 
                    &lt;span style="color: blue"&gt;this&lt;/span&gt;.ItemTemplateSelector.SelectTemplate(item, &lt;span style="color: blue"&gt;this&lt;/span&gt;);
            }
            &lt;span style="color: blue"&gt;else
            &lt;/span&gt;{
                &lt;span style="color: green"&gt;// Default to ItemTemplate.
                &lt;/span&gt;item.ContentTemplate = &lt;span style="color: blue"&gt;this&lt;/span&gt;.ItemTemplate;
            }
        }
        &lt;span style="color: blue"&gt;#endregion

        #region &lt;/span&gt;Property Changed Handlers
        &lt;span style="color: blue"&gt;private static void &lt;/span&gt;OnItemTemplateChanged(&lt;span style="color: #2b91af"&gt;DependencyObject &lt;/span&gt;d, 
            &lt;span style="color: #2b91af"&gt;DependencyPropertyChangedEventArgs &lt;/span&gt;e)
        {
            &lt;span style="color: #2b91af"&gt;TileView &lt;/span&gt;view = (&lt;span style="color: #2b91af"&gt;TileView&lt;/span&gt;)d;
            &lt;span style="color: green"&gt;// Check that a value hasn't already been set for the 
            // ItemTemplateSelector property.
            &lt;/span&gt;&lt;span style="color: blue"&gt;object &lt;/span&gt;selector = d.ReadLocalValue(&lt;span style="color: #2b91af"&gt;TileView&lt;/span&gt;.ItemTemplateSelectorProperty);
            &lt;span style="color: blue"&gt;if &lt;/span&gt;((&lt;span style="color: blue"&gt;null &lt;/span&gt;!= selector) &amp;amp;&amp;amp;
                (&lt;span style="color: #2b91af"&gt;DependencyProperty&lt;/span&gt;.UnsetValue != selector))
            {
                &lt;span style="color: #2b91af"&gt;Trace&lt;/span&gt;.WriteLine(&lt;span style="color: #a31515"&gt;&amp;quot;Cannot specify ItemTemplate and ItemTemplateSelector for a TileView. Using ItemTemplate.&amp;quot;&lt;/span&gt;);
            }
        }

        &lt;span style="color: blue"&gt;private static void &lt;/span&gt;OnItemTemplateSelectorChanged(&lt;span style="color: #2b91af"&gt;DependencyObject &lt;/span&gt;d, 
            &lt;span style="color: #2b91af"&gt;DependencyPropertyChangedEventArgs &lt;/span&gt;e)
        {
            &lt;span style="color: #2b91af"&gt;TileView &lt;/span&gt;view = (&lt;span style="color: #2b91af"&gt;TileView&lt;/span&gt;)d;
            &lt;span style="color: green"&gt;// Check that a value hasn't already been set for the 
            // ItemTemplate property.
            &lt;/span&gt;&lt;span style="color: blue"&gt;object &lt;/span&gt;template = d.ReadLocalValue(&lt;span style="color: #2b91af"&gt;TileView&lt;/span&gt;.ItemTemplateProperty);
            &lt;span style="color: blue"&gt;if &lt;/span&gt;((&lt;span style="color: blue"&gt;null &lt;/span&gt;!= template) &amp;amp;&amp;amp;
                (&lt;span style="color: #2b91af"&gt;DependencyProperty&lt;/span&gt;.UnsetValue != template))
            {
                &lt;span style="color: #2b91af"&gt;Trace&lt;/span&gt;.WriteLine(&lt;span style="color: #a31515"&gt;&amp;quot;Cannot specify ItemTemplate and ItemTemplateSelector for a TileView. Using ItemTemplate.&amp;quot;&lt;/span&gt;);
            }
        }
        &lt;span style="color: blue"&gt;#endregion
    &lt;/span&gt;}
}&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;h5&gt;&amp;#160;&lt;/h5&gt;

&lt;h5&gt;2. Implement the DataTemplateSelector&lt;/h5&gt;

&lt;p&gt;To implement your &lt;a title="DataTemplateSelector Class" href="http://msdn2.microsoft.com/ms609837.aspx"&gt;DataTemplateSelector&lt;/a&gt;, you need to provide properties for the templates that the user can choose from. In my case there are two options: the &lt;code&gt;FileDataTemplate&lt;/code&gt; and the &lt;code&gt;FolderDataTemplate&lt;/code&gt;. You also need to override the &lt;a title="DataTemplateSelector..::.SelectTemplate Method " href="http://msdn2.microsoft.com/ms558169.aspx"&gt;SelectTemplate&lt;/a&gt; method to provide the logic that determines which template to return.&lt;/p&gt;

&lt;p&gt;The following code example shows my &lt;a title="DataTemplateSelector Class" href="http://msdn2.microsoft.com/ms609837.aspx"&gt;DataTemplateSelector&lt;/a&gt;:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;using &lt;/span&gt;System.Windows;
&lt;span style="color: blue"&gt;using &lt;/span&gt;System.Windows.Controls;
&lt;span style="color: blue"&gt;using &lt;/span&gt;DerekLakin.Libraries.Synchronization;

&lt;span style="color: blue"&gt;namespace &lt;/span&gt;DerekLakin.Applications.Titan.Controls
{
    &lt;span style="color: blue"&gt;public class &lt;/span&gt;&lt;span style="color: #2b91af"&gt;FilesAndFoldersDataTemplateSelector&lt;/span&gt;: &lt;span style="color: #2b91af"&gt;DataTemplateSelector
    &lt;/span&gt;{
        &lt;span style="color: blue"&gt;public &lt;/span&gt;&lt;span style="color: #2b91af"&gt;DataTemplate &lt;/span&gt;FileDataTemplate { &lt;span style="color: blue"&gt;get&lt;/span&gt;; &lt;span style="color: blue"&gt;set&lt;/span&gt;; }
        &lt;span style="color: blue"&gt;public &lt;/span&gt;&lt;span style="color: #2b91af"&gt;DataTemplate &lt;/span&gt;FolderDataTemplate { &lt;span style="color: blue"&gt;get&lt;/span&gt;; &lt;span style="color: blue"&gt;set&lt;/span&gt;; }

        &lt;span style="color: blue"&gt;public override &lt;/span&gt;&lt;span style="color: #2b91af"&gt;DataTemplate &lt;/span&gt;SelectTemplate(&lt;span style="color: blue"&gt;object &lt;/span&gt;item, 
            &lt;span style="color: #2b91af"&gt;DependencyObject &lt;/span&gt;container)
        {
            &lt;span style="color: #2b91af"&gt;ListViewItem &lt;/span&gt;targetItem = (&lt;span style="color: #2b91af"&gt;ListViewItem&lt;/span&gt;)item;
            &lt;span style="color: blue"&gt;if &lt;/span&gt;(targetItem.DataContext &lt;span style="color: blue"&gt;is &lt;/span&gt;&lt;span style="color: #2b91af"&gt;VirtualFile&lt;/span&gt;)
            {
                &lt;span style="color: blue"&gt;return &lt;/span&gt;FileDataTemplate;
            }
            &lt;span style="color: blue"&gt;else
            &lt;/span&gt;{
                &lt;span style="color: blue"&gt;return &lt;/span&gt;FolderDataTemplate;
            }
        }
    }
}&lt;/pre&gt;

&lt;h5&gt;3. Bringing it All Together&lt;/h5&gt;

&lt;p&gt;To bring it all together, you need to create data templates for the selector to choose from. Then you need to create an instance of the &lt;a title="DataTemplateSelector Class" href="http://msdn2.microsoft.com/ms609837.aspx"&gt;DataTemplateSelector&lt;/a&gt;. Finally, you need to specify the template selector on the custom view mode (I’m assuming you already have an instance of the custom view mode and the &lt;a title="ListView Class" href="http://msdn2.microsoft.com/ms611074.aspx"&gt;ListView&lt;/a&gt; that uses it).&lt;/p&gt;

&lt;p&gt;The following XAML code example shows the relevant parts.&lt;/p&gt;

&lt;pre class="code"&gt;    &lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataTemplate &lt;/span&gt;&lt;span style="color: red"&gt;x&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: red"&gt;Key&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;filesTemplate&amp;quot;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;    ...
&lt;/span&gt;    &lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataTemplate&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&lt;/span&gt;    &lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataTemplate &lt;/span&gt;&lt;span style="color: red"&gt;x&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: red"&gt;Key&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;foldersTemplate&amp;quot;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;    ...
&lt;/span&gt;    &lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataTemplate&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;pre class="code"&gt;&amp;#160;&lt;/pre&gt;

&lt;pre class="code"&gt;    &lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;c&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;FilesAndFoldersDataTemplateSelector &lt;/span&gt;&lt;span style="color: red"&gt;x&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: red"&gt;Key&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;filesAndFoldersTemplateSelector&amp;quot;
                                           &lt;/span&gt;&lt;span style="color: red"&gt;FileDataTemplate&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color: #a31515"&gt;StaticResource &lt;/span&gt;&lt;span style="color: red"&gt;filesTemplate&lt;/span&gt;&lt;span style="color: blue"&gt;}&amp;quot;
                                           &lt;/span&gt;&lt;span style="color: red"&gt;FolderDataTemplate&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color: #a31515"&gt;StaticResource &lt;/span&gt;&lt;span style="color: red"&gt;foldersTemplate&lt;/span&gt;&lt;span style="color: blue"&gt;}&amp;quot; /&amp;gt;

    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;controls&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;TileView &lt;/span&gt;&lt;span style="color: red"&gt;x&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: red"&gt;Key&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;tileView&amp;quot; 
                       &lt;/span&gt;&lt;span style="color: red"&gt;ItemTemplateSelector&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color: #a31515"&gt;StaticResource &lt;/span&gt;&lt;span style="color: red"&gt;filesAndFoldersTemplateSelector&lt;/span&gt;&lt;span style="color: blue"&gt;}&amp;quot;
                       &lt;/span&gt;&lt;span style="color: red"&gt;ItemWidth&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;128&amp;quot; /&amp;gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;I’m planning (eventually) to evolve my &lt;code&gt;TileView&lt;/code&gt; into something that enables the user to change the size of the tiles in the same way that Windows Explorer does, although it’s a way off for now. When I do, though, I’ll release it into the wild for everyone to enjoy and it will, of course, support template selection.&lt;/p&gt;&lt;div class="wlWriterHeaderFooter" style="margin:0px; padding:0px 0px 0px 0px;"&gt;This work is licensed under a &lt;a href="http://creativecommons.org/licenses/by/3.0/"&gt;Creative Commons Attribution By license.&lt;/a&gt;&lt;/div&gt;&lt;div class="wlWriterHeaderFooter" style="margin:0px; padding:0px 0px 0px 0px;float:left;"&gt;&lt;a href="http://www.dotnetkicks.com/kick/?url=http://cloudstore.blogspot.com/2008/06/creating-custom-view-mode-that-supports.html"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://cloudstore.blogspot.com/2008/06/creating-custom-view-mode-that-supports.html&amp;amp;bgcolor=0080C0&amp;amp;fgcolor=FFFFFF&amp;amp;border=000000&amp;amp;cbgcolor=D4E1ED&amp;amp;cfgcolor=000000" border="0/"&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class="wlWriterHeaderFooter" style="text-align:left; margin:0px; padding:4px 4px 4px 4px;"&gt;&lt;script type="text/javascript"&gt;var dzone_url = 'http://cloudstore.blogspot.com/2008/06/creating-custom-view-mode-that-supports.html';&lt;/script&gt;&lt;script type="text/javascript"&gt;var dzone_title = 'Creating a Custom View Mode that Supports a Template Selector';&lt;/script&gt;&lt;script type="text/javascript"&gt;var dzone_blurb = 'Creating a Custom View Mode that Supports a Template Selector';&lt;/script&gt;&lt;script type="text/javascript"&gt;var dzone_style = '2';&lt;/script&gt;&lt;script language="javascript" src="http://widgets.dzone.com/widgets/zoneit.js"&gt;&lt;/script&gt; &lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=h3kdxIK_iwU:QbxHiOtASbY:4cEx4HpKnUU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?i=h3kdxIK_iwU:QbxHiOtASbY:4cEx4HpKnUU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=h3kdxIK_iwU:QbxHiOtASbY:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=h3kdxIK_iwU:QbxHiOtASbY:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?i=h3kdxIK_iwU:QbxHiOtASbY:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=h3kdxIK_iwU:QbxHiOtASbY:oCFASsrFxfc"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?d=oCFASsrFxfc" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=h3kdxIK_iwU:QbxHiOtASbY:Jwdi1b3fU3Q"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?d=Jwdi1b3fU3Q" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=h3kdxIK_iwU:QbxHiOtASbY:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?i=h3kdxIK_iwU:QbxHiOtASbY:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/cloudstore/~4/h3kdxIK_iwU" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/cloudstore/~3/h3kdxIK_iwU/creating-custom-view-mode-that-supports.html</link><author>noreply@blogger.com (Derek Lakin)</author><thr:total>1</thr:total><feedburner:origLink>http://cloudstore.blogspot.com/2008/06/creating-custom-view-mode-that-supports.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-804082557306552579.post-6445337589217269922</guid><pubDate>Wed, 18 Jun 2008 13:00:00 +0000</pubDate><atom:updated>2008-06-18T14:00:09.148+01:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">games</category><category domain="http://www.blogger.com/atom/ns#">Windows</category><category domain="http://www.blogger.com/atom/ns#">EA</category><category domain="http://www.blogger.com/atom/ns#">Spore</category><title>Spore Creature Creator</title><description>&lt;p&gt;I’ve been eagerly anticipating the release of &lt;a href="http://www.spore.com"&gt;Spore&lt;/a&gt; for so long I can’t remember how long I’ve been waiting for it! However, as a juicy teaser in advance of the release of &lt;a href="http://www.spore.com"&gt;Spore&lt;/a&gt; (still some 80 days away) they’ve released the &lt;a href="http://eu.spore.com/whatisspore/creaturecreator.cfm"&gt;Spore Creature Creator&lt;/a&gt; to whet our appetites.&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;div class="wlWriterSmartContent" id="scid:5737277B-5D6D-4f48-ABFC-DD9C333F4C5D:5f740945-6b19-4c88-83ee-43c64de22d31" style="padding-right: 5px; display: inline; padding-left: 0px; float: none; padding-bottom: 5px; margin: 0px; padding-top: 5px"&gt;&lt;div&gt;&lt;object type="application/x-shockwave-flash" width="400" height="300" data="http://www.flickr.com/apps/video/stewart.swf?v=49235" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"&gt; &lt;param name="flashvars" value="intl_lang=en-us&amp;amp;photo_secret=3dfee9678a&amp;amp;photo_id=2589890666"&gt;&lt;/param&gt; &lt;param name="movie" value="http://www.flickr.com/apps/video/stewart.swf?v=49235"&gt;&lt;/param&gt; &lt;param name="bgcolor" value="#000000"&gt;&lt;/param&gt; &lt;param name="allowFullScreen" value="true"&gt;&lt;/param&gt;&lt;embed type="application/x-shockwave-flash" src="http://www.flickr.com/apps/video/stewart.swf?v=49235" bgcolor="#000000" allowfullscreen="true" flashvars="intl_lang=en-us&amp;amp;photo_secret=3dfee9678a&amp;amp;photo_id=2589890666" height="300" width="400"&gt;&lt;/embed&gt;&lt;/object&gt;&lt;/div&gt;&lt;div style="clear:both;font-size:.8em;"&gt;The Flying BeerGut - The Stomp&lt;/div&gt;&lt;/div&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;The &lt;a href="http://eu.spore.com/whatisspore/creaturecreator.cfm"&gt;Spore Creature Creator&lt;/a&gt; enables you to create all manner of creatures, which you can then share and eventually use in the final game. You can also use creatures added to the community in the final game.&lt;/p&gt;  &lt;p&gt;The &lt;a href="http://eu.spore.com/whatisspore/creaturecreator.cfm"&gt;Spore Creature Creator&lt;/a&gt; comes in two different flavours, the full version, which costs £4.99 here in the UK ($9.95 in the USA, €9.99 in Europe) and the free trial version, which only includes 25% of the body parts of the full version. If you purchase the full version, &lt;a href="http://www.ea.com"&gt;EA&lt;/a&gt; will provide you with a coupon to the same value for you to redeem against the full game when it is released. From what I can gather, this will only be valid if you purchase it from the &lt;a href="http://www.ea.com"&gt;EA&lt;/a&gt; web site.&lt;/p&gt;  &lt;p&gt;In the space of literally a few minutes I managed to put together 3 very different creatures:&lt;/p&gt;  &lt;p&gt;&lt;a title="Snoutasaurus" href="http://www.flickr.com/photos/51035614344@N01/2589052873/"&gt;&lt;img alt="Snoutasaurus" src="http://static.flickr.com/3259/2589052873_8a922081d5_m.jpg" align="left" border="0" /&gt;&lt;/a&gt; &lt;a title="The Flying BeerGut" href="http://www.flickr.com/photos/51035614344@N01/2589888886/"&gt;&lt;img alt="The Flying BeerGut" src="http://static.flickr.com/3138/2589888886_fb323d1623_m.jpg" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;a title="Sluganaught" href="http://www.flickr.com/photos/51035614344@N01/2589888776/"&gt;&lt;img alt="Sluganaught" src="http://static.flickr.com/3086/2589888776_be77536085_m.jpg" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Oh yeah, one more thing: kudos to &lt;a href="http://www.ea.com"&gt;EA&lt;/a&gt; for providing sensible pricing for the full version. The price is roughly the same across the board, which &lt;strong&gt;really&lt;/strong&gt; makes a change here in the UK where we’re used to having to pay almost double for most things compared to the US!&lt;/p&gt;&lt;div class="wlWriterHeaderFooter" style="margin:0px; padding:0px 0px 0px 0px;"&gt;This work is licensed under a &lt;a href="http://creativecommons.org/licenses/by/3.0/"&gt;Creative Commons Attribution By license.&lt;/a&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=s5l1R3g2riw:uU2jqM5oiM4:4cEx4HpKnUU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?i=s5l1R3g2riw:uU2jqM5oiM4:4cEx4HpKnUU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=s5l1R3g2riw:uU2jqM5oiM4:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=s5l1R3g2riw:uU2jqM5oiM4:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?i=s5l1R3g2riw:uU2jqM5oiM4:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=s5l1R3g2riw:uU2jqM5oiM4:oCFASsrFxfc"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?d=oCFASsrFxfc" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=s5l1R3g2riw:uU2jqM5oiM4:Jwdi1b3fU3Q"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?d=Jwdi1b3fU3Q" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=s5l1R3g2riw:uU2jqM5oiM4:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?i=s5l1R3g2riw:uU2jqM5oiM4:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/cloudstore/~4/s5l1R3g2riw" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/cloudstore/~3/s5l1R3g2riw/spore-creature-creator.html</link><author>noreply@blogger.com (Derek Lakin)</author><thr:total>0</thr:total><feedburner:origLink>http://cloudstore.blogspot.com/2008/06/spore-creature-creator.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-804082557306552579.post-1392465685965860615</guid><pubDate>Fri, 06 Jun 2008 11:01:00 +0000</pubDate><atom:updated>2009-03-31T10:52:49.204+01:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">WPF</category><category domain="http://www.blogger.com/atom/ns#">custom</category><category domain="http://www.blogger.com/atom/ns#">.net</category><category domain="http://www.blogger.com/atom/ns#">XAML</category><category domain="http://www.blogger.com/atom/ns#">CodeProject</category><category domain="http://www.blogger.com/atom/ns#">styles</category><category domain="http://www.blogger.com/atom/ns#">Window</category><title>Moving a WPF Window with a WindowStyle of None</title><description>&lt;p&gt;&lt;img title="CustomWindow" style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="160" alt="CustomWindow" src="http://lh3.ggpht.com/derek.lakin/SEkY-CxtkNI/AAAAAAAAACw/WJQprOGLJyU/CustomWindow%5B4%5D.png?imgmax=800" width="290" align="left" border="0" /&gt; In my previous post: &lt;a href="http://cloudstore.blogspot.com/2008/05/creating-custom-window-style.html"&gt;Creating a Custom Window Style&lt;/a&gt;, I showed how to create a custom &lt;a href="http://msdn2.microsoft.com/ms603146.aspx"&gt;Style&lt;/a&gt; in WPF using &lt;a href="http://msdn2.microsoft.com/bb292738.aspx"&gt;WindowStyle.None&lt;/a&gt; and &lt;a href="http://msdn2.microsoft.com/bb348690.aspx"&gt;ResizeMode.NoResize&lt;/a&gt;. What bugged me about this approach was that you can’t move the custom window, because you have no Window chrome to drag around the screen.&lt;/p&gt;  &lt;p&gt;I read one &lt;a href="http://www.aeoth.net/blog/2007/05/16/moving-wpf-windows-without-a-titlebar/"&gt;article&lt;/a&gt; that took a really “hard core” approach and used interop to use the SendMessage, ReleaseCapture, and MouseMove methods, but this is a very Win32-oriented approach and in actual fact, WPF provides a much easier approach.&lt;/p&gt;  &lt;p&gt;To enable a user to move your window from any area on that window (not necessarily just the title if you want to do something really different), you simply handle the &lt;a title="UIElement..::.MouseLeftButtonDown Event" href="http://msdn2.microsoft.com/ms596680.aspx"&gt;MouseLeftButtonDown&lt;/a&gt; event for a &lt;a title="UIElement Class" href="http://msdn2.microsoft.com/ms590078.aspx"&gt;UIElement&lt;/a&gt; on your window and call the &lt;a title="Window..::.DragMove Method " href="http://msdn2.microsoft.com/ms599698.aspx"&gt;DragMove&lt;/a&gt; method, as shown in the following code example.&lt;/p&gt;  &lt;pre class="code"&gt;&lt;span style="color: blue"&gt;private void &lt;/span&gt;title_MouseLeftButtonDown(&lt;span style="color: blue"&gt;object &lt;/span&gt;sender, &lt;span style="color: #2b91af"&gt;MouseButtonEventArgs &lt;/span&gt;e)
{
    DragMove();
}&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;h3&gt;&lt;/h3&gt;

&lt;h3&gt;&amp;#160;&lt;/h3&gt;

&lt;h3&gt;Hooking it Up to the Style&lt;/h3&gt;

&lt;p&gt;Having defined the look-and-feel in a reusable &lt;a href="http://msdn2.microsoft.com/ms603146.aspx"&gt;Style&lt;/a&gt;, we need a way of hooking up the &lt;a title="UIElement..::.MouseLeftButtonDown Event" href="http://msdn2.microsoft.com/ms596680.aspx"&gt;MouseLeftButtonDown&lt;/a&gt; event and handling it in our &lt;a title="Window Class" href="http://msdn2.microsoft.com/ms590112.aspx"&gt;Window&lt;/a&gt; class. Unfortunately, this is a little bit tricky. If the &lt;a href="http://msdn2.microsoft.com/ms603146.aspx"&gt;Style&lt;/a&gt; is defined in the XAML that defines your Window then you can simply add the event handler for the relevant &lt;a title="UIElement Class" href="http://msdn2.microsoft.com/ms590078.aspx"&gt;UIElement&lt;/a&gt; as you would for any other element. However, putting your &lt;a href="http://msdn2.microsoft.com/ms603146.aspx"&gt;Style&lt;/a&gt; in with your actual Window doesn’t give you a very reusable &lt;a href="http://msdn2.microsoft.com/ms603146.aspx"&gt;Style&lt;/a&gt;. Instead, give a fixed name to the element in your &lt;a href="http://msdn2.microsoft.com/ms603146.aspx"&gt;Style&lt;/a&gt;, such as &lt;strong&gt;PART_Title&lt;/strong&gt;, and then get a reference to that element and hook the event in your &lt;a title="Window Class" href="http://msdn2.microsoft.com/ms590112.aspx"&gt;Window&lt;/a&gt; class. Are you still with me?&lt;/p&gt;

&lt;p&gt;The following XAML code example shows the named part in the &lt;a title="Window Class" href="http://msdn2.microsoft.com/ms590112.aspx"&gt;Window&lt;/a&gt; &lt;a href="http://msdn2.microsoft.com/ms603146.aspx"&gt;Style&lt;/a&gt;.&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Style &lt;/span&gt;&lt;span style="color: red"&gt;x&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: red"&gt;Key&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;MessageBox&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;TargetType&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color: #a31515"&gt;x&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;Type &lt;/span&gt;&lt;span style="color: red"&gt;Window&lt;/span&gt;&lt;span style="color: blue"&gt;}&amp;quot;&amp;gt;
    ...&lt;/span&gt;&lt;span style="color: blue"&gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Setter &lt;/span&gt;&lt;span style="color: red"&gt;Property&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;Template&amp;quot;&amp;gt;
        &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Setter.Value&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
            &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;ControlTemplate &lt;/span&gt;&lt;span style="color: red"&gt;TargetType&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color: #a31515"&gt;x&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;Type &lt;/span&gt;&lt;span style="color: red"&gt;Window&lt;/span&gt;&lt;span style="color: blue"&gt;}&amp;quot;&amp;gt;
                &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Border &lt;/span&gt;&lt;span style="color: red"&gt;Background&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color: #a31515"&gt;DynamicResource &lt;/span&gt;&lt;span style="color: red"&gt;MessageBoxBackgroundBrush&lt;/span&gt;&lt;span style="color: blue"&gt;}&amp;quot;&lt;/span&gt;
&lt;span style="color: blue"&gt;                        &lt;/span&gt;&lt;span style="color: red"&gt;BorderBrush&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color: #a31515"&gt;DynamicResource &lt;/span&gt;&lt;span style="color: red"&gt;MessageBoxBorderBrush&lt;/span&gt;&lt;span style="color: blue"&gt;}&amp;quot;&lt;/span&gt;
&lt;span style="color: blue"&gt;                        &lt;span style="color: red"&gt;BorderThickness&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;1&amp;quot;&lt;/span&gt;&amp;gt;
                    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Grid&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
                        &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Grid.RowDefinitions&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
                            &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;RowDefinition &lt;/span&gt;&lt;span style="color: red"&gt;Height&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;30&amp;quot; /&amp;gt;
                            &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;RowDefinition &lt;/span&gt;&lt;span style="color: blue"&gt;/&amp;gt;
                        &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Grid.RowDefinitions&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;
                        &lt;span style="background: yellow; color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: yellow; color: #a31515"&gt;Grid &lt;/span&gt;&lt;span style="background: yellow; color: red"&gt;x&lt;/span&gt;&lt;span style="background: yellow; color: blue"&gt;:&lt;/span&gt;&lt;span style="background: yellow; color: red"&gt;Name&lt;/span&gt;&lt;span style="background: yellow; color: blue"&gt;=&amp;quot;PART_Title&amp;quot;&amp;gt;&lt;/span&gt;
                            &lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Grid.Background&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
                                &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;LinearGradientBrush &lt;/span&gt;&lt;span style="color: red"&gt;EndPoint&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;0.5,1&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;StartPoint&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;0.5,0&amp;quot;&amp;gt;
                                    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;GradientStop &lt;/span&gt;&lt;span style="color: red"&gt;Color&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;#FF214F18&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;Offset&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;0&amp;quot;/&amp;gt;
                                    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;GradientStop &lt;/span&gt;&lt;span style="color: red"&gt;Color&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;#FF20361C&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;Offset&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;1&amp;quot;/&amp;gt;
                                &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;LinearGradientBrush&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
                            &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Grid.Background&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
                            &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Grid.ColumnDefinitions&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
                                &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;ColumnDefinition &lt;/span&gt;&lt;span style="color: blue"&gt;/&amp;gt;
                                &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;ColumnDefinition &lt;/span&gt;&lt;span style="color: red"&gt;Width&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;30&amp;quot; /&amp;gt;
                            &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Grid.ColumnDefinitions&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
                            &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Label &lt;/span&gt;&lt;span style="color: red"&gt;Style&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color: #a31515"&gt;DynamicResource &lt;/span&gt;&lt;span style="color: red"&gt;MessageBoxTitle&lt;/span&gt;&lt;span style="color: blue"&gt;}&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;Content&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color: #a31515"&gt;TemplateBinding &lt;/span&gt;&lt;span style="color: red"&gt;Title&lt;/span&gt;&lt;span style="color: blue"&gt;}&amp;quot; /&amp;gt;
                            &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Button &lt;/span&gt;&lt;span style="color: red"&gt;x&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: red"&gt;Name&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;PART_Close&amp;quot;
                                    &lt;/span&gt;&lt;span style="color: red"&gt;Content&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color: #a31515"&gt;DynamicResource &lt;/span&gt;&lt;span style="color: red"&gt;CloseButtonPath&lt;/span&gt;&lt;span style="color: blue"&gt;}&amp;quot;
                                    &lt;/span&gt;&lt;span style="color: red"&gt;Grid.Column&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;1&amp;quot;
                                    &lt;/span&gt;&lt;span style="color: red"&gt;Style&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color: #a31515"&gt;DynamicResource &lt;/span&gt;&lt;span style="color: red"&gt;CloseButton&lt;/span&gt;&lt;span style="color: blue"&gt;}&amp;quot;
                                    &lt;/span&gt;&lt;span style="color: red"&gt;Padding&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;4&amp;quot; /&amp;gt;
                        &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Grid&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
                        &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;AdornerDecorator &lt;/span&gt;&lt;span style="color: red"&gt;Grid.Row&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;1&amp;quot;&amp;gt;
                            &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;ContentPresenter &lt;/span&gt;&lt;span style="color: red"&gt;Content&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color: #a31515"&gt;TemplateBinding &lt;/span&gt;&lt;span style="color: red"&gt;Content&lt;/span&gt;&lt;span style="color: blue"&gt;}&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;Margin&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color: #a31515"&gt;TemplateBinding &lt;/span&gt;&lt;span style="color: red"&gt;Margin&lt;/span&gt;&lt;span style="color: blue"&gt;}&amp;quot; /&amp;gt;
                        &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;AdornerDecorator&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
                    &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Grid&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
                &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Border&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
            &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;ControlTemplate&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
        &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Setter.Value&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Setter&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Style&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;All I’ve done from the previous version of the &lt;a href="http://msdn2.microsoft.com/ms603146.aspx"&gt;Style&lt;/a&gt; is to add an &lt;code&gt;x:Name&lt;/code&gt; attribute with a value of &lt;strong&gt;PART_Title&lt;/strong&gt; to the &lt;a title="Grid Class" href="http://msdn2.microsoft.com/ms610550.aspx"&gt;Grid&lt;/a&gt; that contains the title of the &lt;a title="Window Class" href="http://msdn2.microsoft.com/ms590112.aspx"&gt;Window&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The following code example shows how to get a reference to that element and hook the mouse event in the &lt;code&gt;CustomMessageBox&lt;/code&gt; class.&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;namespace &lt;/span&gt;CustomWindow
{
    &lt;span style="color: gray"&gt;/// &amp;lt;summary&amp;gt;
    /// &lt;/span&gt;&lt;span style="color: green"&gt;Interaction logic for CustomMessageBox.xaml
    &lt;/span&gt;&lt;span style="color: gray"&gt;/// &amp;lt;/summary&amp;gt;
    &lt;/span&gt;&lt;span style="color: blue"&gt;public partial class &lt;/span&gt;&lt;span style="color: #2b91af"&gt;CustomMessageBox &lt;/span&gt;: &lt;span style="color: #2b91af"&gt;Window
    &lt;/span&gt;{
        &lt;span style="color: blue"&gt;private &lt;/span&gt;&lt;span style="color: #2b91af"&gt;MessageBoxResult &lt;/span&gt;_result = &lt;span style="color: #2b91af"&gt;MessageBoxResult&lt;/span&gt;.None;
        &lt;span style="color: blue"&gt;private &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Button &lt;/span&gt;_close;
        &lt;span style="background: yellow; color: blue"&gt;private &lt;/span&gt;&lt;span style="background: yellow; color: #2b91af"&gt;FrameworkElement &lt;/span&gt;&lt;span style="background: yellow"&gt;_title;&lt;/span&gt;

        ...

        &lt;span style="color: blue"&gt;private void &lt;/span&gt;this_Loaded(&lt;span style="color: blue"&gt;object &lt;/span&gt;sender, &lt;span style="color: #2b91af"&gt;RoutedEventArgs &lt;/span&gt;e)
        {
            &lt;span style="color: blue"&gt;this&lt;/span&gt;._close = (&lt;span style="color: #2b91af"&gt;Button&lt;/span&gt;)&lt;span style="color: blue"&gt;this&lt;/span&gt;.Template.FindName(&lt;span style="color: #a31515"&gt;&amp;quot;PART_Close&amp;quot;&lt;/span&gt;, &lt;span style="color: blue"&gt;this&lt;/span&gt;);
            &lt;span style="color: blue"&gt;if &lt;/span&gt;(&lt;span style="color: blue"&gt;null &lt;/span&gt;!= &lt;span style="color: blue"&gt;this&lt;/span&gt;._close)
            {
                &lt;span style="color: blue"&gt;if &lt;/span&gt;(&lt;span style="color: blue"&gt;false &lt;/span&gt;== &lt;span style="color: blue"&gt;this&lt;/span&gt;._cancel.IsVisible)
                {
                    &lt;span style="color: blue"&gt;this&lt;/span&gt;._close.IsCancel = &lt;span style="color: blue"&gt;false&lt;/span&gt;;
                }
            }

            &lt;span style="background: yellow; color: blue"&gt;this&lt;/span&gt;&lt;span style="background: yellow"&gt;._title = (&lt;/span&gt;&lt;span style="background: yellow; color: #2b91af"&gt;FrameworkElement&lt;/span&gt;&lt;span style="background: yellow"&gt;)&lt;/span&gt;&lt;span style="background: yellow; color: blue"&gt;this&lt;/span&gt;&lt;span style="background: yellow"&gt;.Template.FindName(&lt;/span&gt;&lt;span style="background: yellow; color: #a31515"&gt;&amp;quot;PART_Title&amp;quot;&lt;/span&gt;&lt;span style="background: yellow"&gt;, &lt;/span&gt;&lt;span style="background: yellow; color: blue"&gt;this&lt;/span&gt;&lt;span style="background: yellow"&gt;);&lt;/span&gt;
            &lt;span style="background: yellow; color: blue"&gt;if &lt;/span&gt;&lt;span style="background: yellow"&gt;(&lt;/span&gt;&lt;span style="background: yellow; color: blue"&gt;null &lt;/span&gt;&lt;span style="background: yellow"&gt;!= &lt;/span&gt;&lt;span style="background: yellow; color: blue"&gt;this&lt;/span&gt;&lt;span style="background: yellow"&gt;._title)&lt;/span&gt;
            &lt;span style="background: yellow"&gt;{&lt;/span&gt;
                &lt;span style="background: yellow; color: blue"&gt;this&lt;/span&gt;&lt;span style="background: yellow"&gt;._title.MouseLeftButtonDown += &lt;/span&gt;&lt;span style="background: yellow; color: blue"&gt;new &lt;/span&gt;&lt;span style="background: yellow; color: #2b91af"&gt;MouseButtonEventHandler&lt;/span&gt;&lt;span style="background: yellow"&gt;(title_MouseLeftButtonDown);&lt;/span&gt;
            &lt;span style="background: yellow"&gt;}&lt;/span&gt;
        }

        &lt;span style="color: blue"&gt;private void &lt;/span&gt;title_MouseLeftButtonDown(&lt;span style="color: blue"&gt;object &lt;/span&gt;sender, &lt;span style="color: #2b91af"&gt;MouseButtonEventArgs &lt;/span&gt;e)
        {
            DragMove();
        }

        ...
    }
}&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;h3&gt;Summary&lt;/h3&gt;

&lt;p&gt;So, if you want to enable window movement for custom styled windows, then you need to call the &lt;a title="Window..::.DragMove Method " href="http://msdn2.microsoft.com/ms599698.aspx"&gt;DragMove&lt;/a&gt; method from an event handler for the &lt;a title="UIElement..::.MouseLeftButtonDown Event" href="http://msdn2.microsoft.com/ms596680.aspx"&gt;MouseLeftButtonDown&lt;/a&gt; event. In this example, the &lt;code&gt;CustomMessageBox&lt;/code&gt; class provides that event handling. If you are using a &lt;a href="http://msdn2.microsoft.com/ms603146.aspx"&gt;Style&lt;/a&gt; that applies to multiple windows, then you will need to hook the mouse event in each class, or implement a base class that provides this functionality for you and inherit from that class.&lt;/p&gt;

&lt;p&gt;As before, I’ve provided the (now updated) source code for the custom message box class.&lt;/p&gt;

&lt;p&gt;&lt;iframe style="border-right: #dde5e9 1px solid; padding-right: 0px; border-top: #dde5e9 1px solid; padding-left: 0px; padding-bottom: 0px; margin: 3px; border-left: #dde5e9 1px solid; width: 240px; padding-top: 0px; border-bottom: #dde5e9 1px solid; height: 66px; background-color: #ffffff" marginwidth="0" marginheight="0" src="http://cid-2ebcba238c071a49.skydrive.live.com/embedrowdetail.aspx/WPF/CustomMovableWindow.zip" frameborder="0" scrolling="no"&gt;&lt;/iframe&gt;&lt;/p&gt;&lt;div class="wlWriterHeaderFooter" style="margin:0px; padding:0px 0px 0px 0px;"&gt;This work is licensed under a &lt;a href="http://creativecommons.org/licenses/by/3.0/"&gt;Creative Commons Attribution By license.&lt;/a&gt;&lt;/div&gt;&lt;div class="wlWriterHeaderFooter" style="margin:0px; padding:0px 0px 0px 0px;float:left;"&gt;&lt;a href="http://www.dotnetkicks.com/kick/?url=http://cloudstore.blogspot.com/2008/06/moving-wpf-window-with-windowstyle-of.html"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://cloudstore.blogspot.com/2008/06/moving-wpf-window-with-windowstyle-of.html&amp;amp;bgcolor=0080C0&amp;amp;fgcolor=FFFFFF&amp;amp;border=000000&amp;amp;cbgcolor=D4E1ED&amp;amp;cfgcolor=000000" border="0/"&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class="wlWriterHeaderFooter" style="text-align:left; margin:0px; padding:4px 4px 4px 4px;"&gt;&lt;script type="text/javascript"&gt;var dzone_url = 'http://cloudstore.blogspot.com/2008/06/moving-wpf-window-with-windowstyle-of.html';&lt;/script&gt;&lt;script type="text/javascript"&gt;var dzone_title = 'Moving a WPF Window with a WindowStyle of None';&lt;/script&gt;&lt;script type="text/javascript"&gt;var dzone_blurb = 'Moving a WPF Window with a WindowStyle of None';&lt;/script&gt;&lt;script type="text/javascript"&gt;var dzone_style = '2';&lt;/script&gt;&lt;script language="javascript" src="http://widgets.dzone.com/widgets/zoneit.js"&gt;&lt;/script&gt; &lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=am7W7n4lvjk:0RPeyn0ZMgE:4cEx4HpKnUU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?i=am7W7n4lvjk:0RPeyn0ZMgE:4cEx4HpKnUU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=am7W7n4lvjk:0RPeyn0ZMgE:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=am7W7n4lvjk:0RPeyn0ZMgE:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?i=am7W7n4lvjk:0RPeyn0ZMgE:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=am7W7n4lvjk:0RPeyn0ZMgE:oCFASsrFxfc"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?d=oCFASsrFxfc" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=am7W7n4lvjk:0RPeyn0ZMgE:Jwdi1b3fU3Q"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?d=Jwdi1b3fU3Q" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=am7W7n4lvjk:0RPeyn0ZMgE:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?i=am7W7n4lvjk:0RPeyn0ZMgE:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/cloudstore/~4/am7W7n4lvjk" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/cloudstore/~3/am7W7n4lvjk/moving-wpf-window-with-windowstyle-of.html</link><author>noreply@blogger.com (Derek Lakin)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://lh3.ggpht.com/derek.lakin/SEkY-CxtkNI/AAAAAAAAACw/WJQprOGLJyU/s72-c/CustomWindow%5B4%5D.png?imgmax=800" height="72" width="72" /><thr:total>12</thr:total><feedburner:origLink>http://cloudstore.blogspot.com/2008/06/moving-wpf-window-with-windowstyle-of.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-804082557306552579.post-5350202608445002312</guid><pubDate>Tue, 03 Jun 2008 09:29:00 +0000</pubDate><atom:updated>2009-03-31T10:52:37.380+01:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">WPF</category><category domain="http://www.blogger.com/atom/ns#">XAML</category><category domain="http://www.blogger.com/atom/ns#">CodeProject</category><category domain="http://www.blogger.com/atom/ns#">databinding</category><title>Setting the Initial Focus in WPF</title><description>&lt;p&gt;In WPF dialog boxes, I quite often see some code which looks like the following code. example.&lt;/p&gt;  &lt;pre class="code"&gt;&lt;span style="color: blue"&gt;private void &lt;/span&gt;OnLoaded(&lt;span style="color: blue"&gt;object &lt;/span&gt;sender, &lt;span style="color: #2b91af"&gt;EventArgs &lt;/span&gt;e)
{
    &lt;span style="color: blue"&gt;this&lt;/span&gt;._textSearch.Focus();
}&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;This is usually accompanied by some XAML that likes like the following XAML example.&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Window &lt;/span&gt;&lt;span&gt;...&lt;/span&gt;&lt;span style="color: blue"&gt;
        &lt;/span&gt;&lt;span style="color: red"&gt;Loaded&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;OnLoaded&amp;quot;&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;Occasionally, I also see the event being setup up in the constructor. For some reason this really gets on my nerves. I much prefer to see event handlers defined in the XAML. I’m not quite sure what my objection is; I think I just prefer to see all the UI things in one place.&lt;/p&gt;

&lt;p&gt;What this actually achieves (as you can probably work out), is that the control (in this case a &lt;a title="TextBox Class" href="http://msdn2.microsoft.com/ms617604.aspx"&gt;TextBox&lt;/a&gt;) named &lt;strong&gt;_textSearch&lt;/strong&gt; has focus when the dialog box is loaded. In actual fact, WPF provides a much easier way of setting the initial focus by using the &lt;a title="FocusManager Class" href="http://msdn2.microsoft.com/ms616863.aspx"&gt;FocusManager&lt;/a&gt;. The &lt;a title="FocusManager Class" href="http://msdn2.microsoft.com/ms616863.aspx"&gt;FocusManager&lt;/a&gt; provides a set of static methods, properties, and events that you use to determine and set the focus scope&lt;sup&gt;[1]&lt;/sup&gt; and to set the focused element within the focus scope.&lt;/p&gt;

&lt;p&gt;So, using the &lt;a title="FocusManager Class" href="http://msdn2.microsoft.com/ms616863.aspx"&gt;FocusManager&lt;/a&gt;, you don’t need to handle the &lt;a title="FrameworkElement..::.Loaded Event" href="http://msdn2.microsoft.com/ms596558.aspx"&gt;Loaded&lt;/a&gt; event and manually calling the &lt;a title="UIElement..::.Focus Method " href="http://msdn2.microsoft.com/ms598909.aspx"&gt;Focus&lt;/a&gt; method as shown in the previous code examples, you can simply set the &lt;a title="FocusManager..::.FocusedElement Attached Property" href="http://msdn2.microsoft.com/ms595030.aspx"&gt;FocusedElement&lt;/a&gt; on the &lt;a title="FocusManager Class" href="http://msdn2.microsoft.com/ms616863.aspx"&gt;FocusManager&lt;/a&gt; as shown in the following code example.&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Window &lt;/span&gt;&lt;span&gt;...&lt;/span&gt;&lt;span style="color: blue"&gt;
        &lt;/span&gt;&lt;span style="color: red"&gt;FocusManager.FocusedElement&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color: #a31515"&gt;Binding &lt;/span&gt;&lt;span style="color: red"&gt;ElementName&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;_&lt;span style="color: blue"&gt;textSearch}&amp;quot;&amp;gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;Simple, neat, all in one place, and no code-behind :)&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;&lt;sup&gt;[1] &lt;/sup&gt;For more information about focus scopes, see &lt;a href="http://msdn.microsoft.com/en-gb/system.windows.input.focusmanager.aspx"&gt;FocusManager Class&lt;/a&gt; on the MSDN web site.&lt;/p&gt;&lt;div class="wlWriterHeaderFooter" style="margin:0px; padding:0px 0px 0px 0px;"&gt;This work is licensed under a &lt;a href="http://creativecommons.org/licenses/by/3.0/"&gt;Creative Commons Attribution By license.&lt;/a&gt;&lt;/div&gt;&lt;div class="wlWriterHeaderFooter" style="float:left; margin:0px; padding:0px 0px 0px 0px;"&gt;&lt;a href="http://www.dotnetkicks.com/kick/?url=http://cloudstore.blogspot.com/2008/06/setting-initial-focus-in-wpf.html"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://cloudstore.blogspot.com/2008/06/setting-initial-focus-in-wpf.html&amp;amp;bgcolor=0080C0&amp;amp;fgcolor=FFFFFF&amp;amp;border=000000&amp;amp;cbgcolor=D4E1ED&amp;amp;cfgcolor=000000" border="0/"&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class="wlWriterHeaderFooter" style="text-align:left; margin:0px; padding:4px 4px 4px 4px;"&gt;&lt;script type="text/javascript"&gt;var dzone_url = 'http://cloudstore.blogspot.com/2008/06/setting-initial-focus-in-wpf.html';&lt;/script&gt;&lt;script type="text/javascript"&gt;var dzone_title = 'Setting the Initial Focus in WPF';&lt;/script&gt;&lt;script type="text/javascript"&gt;var dzone_blurb = 'Setting the Initial Focus in WPF';&lt;/script&gt;&lt;script type="text/javascript"&gt;var dzone_style = '2';&lt;/script&gt;&lt;script language="javascript" src="http://widgets.dzone.com/widgets/zoneit.js"&gt;&lt;/script&gt; &lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=y_EKp36ZHPk:GR4L2x15VUI:4cEx4HpKnUU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?i=y_EKp36ZHPk:GR4L2x15VUI:4cEx4HpKnUU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=y_EKp36ZHPk:GR4L2x15VUI:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=y_EKp36ZHPk:GR4L2x15VUI:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?i=y_EKp36ZHPk:GR4L2x15VUI:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=y_EKp36ZHPk:GR4L2x15VUI:oCFASsrFxfc"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?d=oCFASsrFxfc" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=y_EKp36ZHPk:GR4L2x15VUI:Jwdi1b3fU3Q"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?d=Jwdi1b3fU3Q" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=y_EKp36ZHPk:GR4L2x15VUI:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?i=y_EKp36ZHPk:GR4L2x15VUI:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/cloudstore/~4/y_EKp36ZHPk" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/cloudstore/~3/y_EKp36ZHPk/setting-initial-focus-in-wpf.html</link><author>noreply@blogger.com (Derek Lakin)</author><thr:total>4</thr:total><feedburner:origLink>http://cloudstore.blogspot.com/2008/06/setting-initial-focus-in-wpf.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-804082557306552579.post-3252137475128546166</guid><pubDate>Tue, 20 May 2008 08:32:00 +0000</pubDate><atom:updated>2008-06-06T10:00:20.996+01:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">multi-threading</category><category domain="http://www.blogger.com/atom/ns#">custom</category><category domain="http://www.blogger.com/atom/ns#">Titan</category><category domain="http://www.blogger.com/atom/ns#">.net</category><category domain="http://www.blogger.com/atom/ns#">threads</category><title>Enhancing the BackgroundWorker Class</title><description>&lt;h3&gt;Background&lt;/h3&gt;  &lt;p&gt;Amongst the inner complexities of Titan, there are a number of cases where I'm executing some actions asynchronously by using the &lt;a title="BackgroundWorker Class" href="http://msdn2.microsoft.com/4852et58.aspx"&gt;BackgroundWorker&lt;/a&gt; class. These are primarily in the controller class which handles calls from the user interface to the back-end service providers for actions such as getting the account tree, creating new folders, etc.&lt;/p&gt;  &lt;p&gt;The flow through the application is (simply) illustrated in the following diagram:&lt;/p&gt;  &lt;p&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="380" alt="BackgroundWorker" src="http://lh3.ggpht.com/derek.lakin/SDKMp0UZF5I/AAAAAAAAACo/tDk2SkyPORY/BackgroundWorker%5B2%5D.png?imgmax=800" width="500" border="0" /&gt;&lt;/p&gt;  &lt;p&gt;Figure 1. Background task flow.&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;The user interface makes a request on the Controller. &lt;/li&gt;    &lt;li&gt;The Controller creates a &lt;a title="BackgroundWorker Class" href="http://msdn2.microsoft.com/4852et58.aspx"&gt;BackgroundWorker&lt;/a&gt; instance and calls &lt;a title="BackgroundWorker..::.RunWorkerAsync Method " href="http://msdn2.microsoft.com/f6k7y5wc.aspx"&gt;RunWorkerAsync&lt;/a&gt;, passing in the required parameter. &lt;/li&gt;    &lt;li&gt;The &lt;a title="BackgroundWorker Class" href="http://msdn2.microsoft.com/4852et58.aspx"&gt;BackgroundWorker&lt;/a&gt; makes the necessary calls on the Service Provider and then raises the &lt;a title="BackgroundWorker..::.RunWorkerCompleted Event" href="http://msdn2.microsoft.com/hz2ts075.aspx"&gt;RunWorkerCompleted&lt;/a&gt; event when it's done. &lt;/li&gt;    &lt;li&gt;The Controller sends any response to the user interface. &lt;/li&gt; &lt;/ol&gt;  &lt;h3&gt;&lt;/h3&gt;  &lt;h3&gt;So, What's the Problem?&lt;/h3&gt;  &lt;p&gt;Take uploading a new file for example. When the files has been uploaded, the user interface needs to know which file has just been uploaded so that the user interface can be updated to reflect that the file is now synchronized. Titan enables users to upload or download more than one file at a time, so there could be multiple transfer operations happening at the same time. Which means that the controller needs to know which operation has just finished.&lt;/p&gt; The &lt;a title="BackgroundWorker Class" href="http://msdn2.microsoft.com/4852et58.aspx"&gt;BackgroundWorker&lt;/a&gt; class enables you to pass a parameter to the   &lt;p&gt;&lt;a title="BackgroundWorker..::.RunWorkerAsync Method " href="http://msdn2.microsoft.com/f6k7y5wc.aspx"&gt;RunWorkerAsync&lt;/a&gt; method, which you can retrieve from the &lt;a title="DoWorkEventArgs..::.Argument Property " href="http://msdn2.microsoft.com/33x3bweh.aspx"&gt;Argument&lt;/a&gt; property of the &lt;a title="DoWorkEventArgs Class" href="http://msdn2.microsoft.com/13a7z7z8.aspx"&gt;DoWorkEventArgs&lt;/a&gt;. Once you've finished, you can specify a result in the &lt;a title="DoWorkEventArgs..::.Result Property " href="http://msdn2.microsoft.com/ezx6e3ty.aspx"&gt;Result&lt;/a&gt; property of the same &lt;a title="DoWorkEventArgs Class" href="http://msdn2.microsoft.com/13a7z7z8.aspx"&gt;DoWorkEventArgs&lt;/a&gt;. This result is then available in the &lt;a title="RunWorkerCompletedEventArgs..::.Result Property " href="http://msdn2.microsoft.com/2913sbt7.aspx"&gt;Result&lt;/a&gt; property of the &lt;a title="RunWorkerCompletedEventArgs Class" href="http://msdn2.microsoft.com/dbd7wse7.aspx"&gt;RunWorkerCompletedEventArgs&lt;/a&gt; in the &lt;a title="BackgroundWorker..::.RunWorkerCompleted Event" href="http://msdn2.microsoft.com/hz2ts075.aspx"&gt;RunWorkerCompleted&lt;/a&gt; event handler. However, there's no access to the original argument that you supplied, which in my case makes it difficult to tie up which upload (for example) has completed.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;h3&gt;OK, So What's the Solution?&lt;/h3&gt;  &lt;p&gt;One potential solution would be to create a struct that contains the result that I wanted to return initially and also the original argument, but personally I don't like these kind of solutions. It's like having an event args inside an event args! &lt;/p&gt;  &lt;p&gt;The solution I employed was to create an &lt;code&gt;EnhancedBackgroundWorker&lt;/code&gt; class that simply exposes the original argument. All it does is to provide a new &lt;a title="BackgroundWorker..::.RunWorkerAsync Method " href="http://msdn2.microsoft.com/f6k7y5wc.aspx"&gt;RunWorkerAsync&lt;/a&gt; method, which stores the supplied argument (which is exposed as the Argument property), and then calls the base implementation of &lt;a title="BackgroundWorker..::.RunWorkerAsync Method " href="http://msdn2.microsoft.com/f6k7y5wc.aspx"&gt;RunWorkerAsync&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;The following code shows the &lt;code&gt;EnhancedBackgroundWorker&lt;/code&gt; class.&lt;/p&gt;  &lt;pre class="code"&gt;&lt;span style="color: blue"&gt;using &lt;/span&gt;System.ComponentModel;

&lt;span style="color: blue"&gt;namespace &lt;/span&gt;DerekLakin.Libraries.Utilities.Thread
{
    &lt;span style="color: gray"&gt;/// &amp;lt;summary&amp;gt;
    /// &lt;/span&gt;&lt;span style="color: green"&gt;Enhanced &lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;see cref=&amp;quot;BackgroundWorker&amp;quot;/&amp;gt; &lt;/span&gt;&lt;span style="color: green"&gt;class that stores the
    &lt;/span&gt;&lt;span style="color: gray"&gt;/// &lt;/span&gt;&lt;span style="color: green"&gt;argument supplied to the &lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;code&amp;gt;&lt;/span&gt;&lt;span style="color: green"&gt;RunWorkerAsync&lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;/code&amp;gt;
    /// &lt;/span&gt;&lt;span style="color: green"&gt;method so that it is available in the relevant event handlers.
    &lt;/span&gt;&lt;span style="color: gray"&gt;/// &amp;lt;/summary&amp;gt;
    &lt;/span&gt;&lt;span style="color: blue"&gt;public class &lt;/span&gt;&lt;span style="color: #2b91af"&gt;EnhancedBackgroundWorker &lt;/span&gt;: &lt;span style="color: #2b91af"&gt;BackgroundWorker
    &lt;/span&gt;{
        &lt;span style="color: blue"&gt;public object &lt;/span&gt;Argument { &lt;span style="color: blue"&gt;get&lt;/span&gt;; &lt;span style="color: blue"&gt;set&lt;/span&gt;; }

        &lt;span style="color: blue"&gt;public new void &lt;/span&gt;RunWorkerAsync(&lt;span style="color: blue"&gt;object &lt;/span&gt;argument)
        {
            &lt;span style="color: blue"&gt;this&lt;/span&gt;.Argument = argument;

            &lt;span style="color: blue"&gt;base&lt;/span&gt;.RunWorkerAsync(argument);
        }
    }
}&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;Now, in the &lt;a title="BackgroundWorker..::.RunWorkerCompleted Event" href="http://msdn2.microsoft.com/hz2ts075.aspx"&gt;RunWorkerCompleted&lt;/a&gt; event handler, I can access the originally supplied argument from the &lt;code&gt;EnhancedBackgroundWorker&lt;/code&gt; (which is the &lt;code&gt;sender&lt;/code&gt; parameter). Simple but effective. I like those kinds of solutions :) &lt;/p&gt;

&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;div class="wlWriterHeaderFooter" style="margin:0px; padding:0px 0px 0px 0px;"&gt;This work is licensed under a &lt;a href="http://creativecommons.org/licenses/by/3.0/"&gt;Creative Commons Attribution By license.&lt;/a&gt;&lt;/div&gt;&lt;div class="wlWriterHeaderFooter" style="float:left;margin:0px; padding:0px 0px 0px 0px;"&gt;&lt;a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fcloudstore.blogspot.com%2f2008%2f05%2fenhancing-backgroundworker-class.html"&gt;&lt;img alt="kick it on DotNetKicks.com" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fcloudstore.blogspot.com%2f2008%2f05%2fenhancing-backgroundworker-class.html&amp;amp;bgcolor=47505F&amp;amp;cbgcolor=FFFFFF" border="0" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class="wlWriterHeaderFooter" style="text-align:left; margin:0px; padding:4px 4px 4px 4px;"&gt;&lt;script type="text/javascript"&gt;var dzone_url = 'http://cloudstore.blogspot.com/2008/05/enhancing-backgroundworker-class.html';&lt;/script&gt;&lt;script type="text/javascript"&gt;var dzone_title = 'Enhancing the BackgroundWorker Class';&lt;/script&gt;&lt;script type="text/javascript"&gt;var dzone_blurb = 'Enhancing the BackgroundWorker Class';&lt;/script&gt;&lt;script type="text/javascript"&gt;var dzone_style = '2';&lt;/script&gt;&lt;script language="javascript" src="http://widgets.dzone.com/widgets/zoneit.js"&gt;&lt;/script&gt; &lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=FCAW2ddMTQk:cSOf3ZMf1Xs:4cEx4HpKnUU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?i=FCAW2ddMTQk:cSOf3ZMf1Xs:4cEx4HpKnUU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=FCAW2ddMTQk:cSOf3ZMf1Xs:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=FCAW2ddMTQk:cSOf3ZMf1Xs:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?i=FCAW2ddMTQk:cSOf3ZMf1Xs:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=FCAW2ddMTQk:cSOf3ZMf1Xs:oCFASsrFxfc"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?d=oCFASsrFxfc" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=FCAW2ddMTQk:cSOf3ZMf1Xs:Jwdi1b3fU3Q"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?d=Jwdi1b3fU3Q" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=FCAW2ddMTQk:cSOf3ZMf1Xs:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?i=FCAW2ddMTQk:cSOf3ZMf1Xs:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/cloudstore/~4/FCAW2ddMTQk" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/cloudstore/~3/FCAW2ddMTQk/enhancing-backgroundworker-class.html</link><author>noreply@blogger.com (Derek Lakin)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://lh3.ggpht.com/derek.lakin/SDKMp0UZF5I/AAAAAAAAACo/tDk2SkyPORY/s72-c/BackgroundWorker%5B2%5D.png?imgmax=800" height="72" width="72" /><thr:total>1</thr:total><feedburner:origLink>http://cloudstore.blogspot.com/2008/05/enhancing-backgroundworker-class.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-804082557306552579.post-4653721503295210147</guid><pubDate>Fri, 09 May 2008 17:24:00 +0000</pubDate><atom:updated>2009-03-31T10:52:24.298+01:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">dependency properties</category><category domain="http://www.blogger.com/atom/ns#">WPF</category><category domain="http://www.blogger.com/atom/ns#">custom</category><category domain="http://www.blogger.com/atom/ns#">XAML</category><category domain="http://www.blogger.com/atom/ns#">CodeProject</category><category domain="http://www.blogger.com/atom/ns#">screen shot</category><category domain="http://www.blogger.com/atom/ns#">styles</category><category domain="http://www.blogger.com/atom/ns#">Window</category><title>Creating a Custom Window Style</title><description>&lt;p&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="145" alt="CustomWindow" src="http://lh5.ggpht.com/derek.lakin/SCSIxDjIZOI/AAAAAAAAACA/sX2J_SyuPN0/CustomWindow7.png?imgmax=800" width="260" align="left" border="0" /&gt; I'm currently neck deep in refactoring an application for my company and one of the issues that I've just finished tidying up was that of providing a custom &lt;a title="Window Class" href="http://msdn2.microsoft.com/ms590112.aspx"&gt;Window&lt;/a&gt; &lt;a title="Style Class" href="http://msdn2.microsoft.com/ms603146.aspx"&gt;Style&lt;/a&gt;. The original application developer (in his infinite wisdom) had the same markup in every single file to produce the same look-and-feel and then used a complicated WindowHelper class to load the user control into an actual Window.&lt;/p&gt;  &lt;p&gt;If you didn't know already, we can simplify this whole process greatly by applying a &lt;a title="Style Class" href="http://msdn2.microsoft.com/ms603146.aspx"&gt;Style&lt;/a&gt; to the &lt;a title="Window Class" href="http://msdn2.microsoft.com/ms590112.aspx"&gt;Window&lt;/a&gt; and implementing whatever appearance you want in the &lt;a title="ControlTemplate Class" href="http://msdn2.microsoft.com/ms609827.aspx"&gt;ControlTemplate&lt;/a&gt;. In the rest of this article, I'll show you how to implement a custom &lt;a title="Style Class" href="http://msdn2.microsoft.com/ms603146.aspx"&gt;Style&lt;/a&gt; by implementing a custom message box.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;h2&gt;Elements of a Custom Window Style&lt;/h2&gt;  &lt;p&gt;&lt;/p&gt;  &lt;h3&gt;&amp;#160;&lt;/h3&gt;  &lt;h3&gt;1. Remove the Borders&lt;/h3&gt;  &lt;p&gt;The first thing we need to do is to remove the standard window chrome, borders, etc. At first glance you might think that setting the window's &lt;a title="WindowStyle Enumeration" href="http://msdn2.microsoft.com/ms590119.aspx"&gt;WindowStyle&lt;/a&gt; to &lt;a title="None Field" href="http://msdn2.microsoft.com/bb292738.aspx"&gt;WindowStyle.None&lt;/a&gt; would do the trick, but as you can see from the following images, this still leaves us with a border. In order to remove all borders completely, you need to set the window's &lt;a title="ResizeMode Enumeration" href="http://msdn2.microsoft.com/ms589725.aspx"&gt;ResizeMode&lt;/a&gt; to &lt;a title="NoResize Field" href="http://msdn2.microsoft.com/bb348690.aspx"&gt;ResizeMode.NoResize&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="158" alt="RegularWindow" src="http://lh3.ggpht.com/derek.lakin/SCSIxjjIZPI/AAAAAAAAACI/i4Dto3-zLnI/RegularWindow2.png?imgmax=800" width="322" border="0" /&gt; &lt;/p&gt;  &lt;p&gt;Figure 1. Regular Window.&lt;/p&gt;  &lt;p&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="164" alt="WindowStyle_None" src="http://lh5.ggpht.com/derek.lakin/SCSIyDjIZQI/AAAAAAAAACQ/CXw170cGXEc/WindowStyle_None2.png?imgmax=800" width="326" border="0" /&gt; &lt;/p&gt;  &lt;p&gt;Figure 2. &lt;a title="WindowStyle Enumeration" href="http://msdn2.microsoft.com/ms590119.aspx"&gt;WindowStyle&lt;/a&gt; set to &lt;a title="None Field" href="http://msdn2.microsoft.com/bb292738.aspx"&gt;None&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="163" alt="WindowStyle_None_ResizeMode_NoResize" src="http://lh3.ggpht.com/derek.lakin/SCSIyjjIZRI/AAAAAAAAACY/WX0PuopazSA/WindowStyle_None_ResizeMode_NoResize.png?imgmax=800" width="322" border="0" /&gt; &lt;/p&gt;  &lt;p&gt;Figure 3. &lt;a title="WindowStyle Enumeration" href="http://msdn2.microsoft.com/ms590119.aspx"&gt;WindowStyle&lt;/a&gt; set to &lt;a title="None Field" href="http://msdn2.microsoft.com/bb292738.aspx"&gt;None&lt;/a&gt; and &lt;a title="ResizeMode Enumeration" href="http://msdn2.microsoft.com/ms589725.aspx"&gt;ResizeMode&lt;/a&gt; set to &lt;a title="NoResize Field" href="http://msdn2.microsoft.com/bb348690.aspx"&gt;NoResize&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;The following example XAML code shows how to define these properties in the XAML for your Window:&lt;/p&gt;  
&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Window
&lt;/span&gt;&lt;span&gt;    ...&lt;/span&gt;
&lt;span style="color: blue"&gt;    &lt;/span&gt;&lt;span style="color: red"&gt;ResizeMode&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;NoResize&amp;quot;
&lt;/span&gt;&lt;span style="color: blue"&gt;    &lt;/span&gt;&lt;span style="color: red"&gt;WindowStyle&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;None&amp;quot;&amp;gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;h2&gt;&amp;#160;&lt;/h2&gt;

&lt;p&gt;Another use for this approach is to implement a custom splash screen.&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;h3&gt;2. Define a New Style&lt;/h3&gt;

&lt;p&gt;It's all very well putting the &lt;a title="WindowStyle Enumeration" href="http://msdn2.microsoft.com/ms590119.aspx"&gt;WindowStyle&lt;/a&gt; and &lt;a title="ResizeMode Enumeration" href="http://msdn2.microsoft.com/ms589725.aspx"&gt;ResizeMode&lt;/a&gt; in each Window, but if we want to apply our new look-and-feel to multiple windows then we need to put it into a &lt;a title="Style Class" href="http://msdn2.microsoft.com/ms603146.aspx"&gt;Style&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The following example XAML code shows how to define the &lt;a title="WindowStyle Enumeration" href="http://msdn2.microsoft.com/ms590119.aspx"&gt;WindowStyle&lt;/a&gt; and &lt;a title="ResizeMode Enumeration" href="http://msdn2.microsoft.com/ms589725.aspx"&gt;ResizeMode&lt;/a&gt; values in a custom Window style.&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Style &lt;/span&gt;&lt;span style="color: red"&gt;x&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: red"&gt;Key&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;MessageBox&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;TargetType&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color: #a31515"&gt;x&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;Type &lt;/span&gt;&lt;span style="color: red"&gt;Window&lt;/span&gt;&lt;span style="color: blue"&gt;}&amp;quot;&amp;gt;
&lt;/span&gt;&lt;span style="color: blue"&gt;    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Setter &lt;/span&gt;&lt;span style="color: red"&gt;Property&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;ResizeMode&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;Value&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;NoResize&amp;quot; /&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Setter &lt;/span&gt;&lt;span style="color: red"&gt;Property&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;WindowStyle&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;Value&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;None&amp;quot; /&amp;gt;
&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Style&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;The following example XAML code shows how to apply this style to our custom window.&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Window
    &lt;/span&gt;&lt;span style="color: red"&gt;xmlns&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&amp;quot;
&lt;/span&gt;&lt;span style="color: blue"&gt;    &lt;/span&gt;&lt;span style="color: red"&gt;xmlns&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: red"&gt;x&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;http://schemas.microsoft.com/winfx/2006/xaml&amp;quot;
    &lt;/span&gt;&lt;span style="color: red"&gt;x&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: red"&gt;Class&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;CustomWindow.CustomMessageBox&amp;quot;
&lt;/span&gt;    &lt;span style="color: red"&gt;Style&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color: #a31515"&gt;DynamicResource &lt;/span&gt;&lt;span style="color: red"&gt;MessageBox&lt;/span&gt;&lt;span style="color: blue"&gt;}&amp;quot;
    &lt;/span&gt;&lt;span&gt;...&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;h3&gt;3. Custom Look-and-Feel&lt;/h3&gt;

&lt;p&gt;The next thing we need to do is to make our custom window look the way we want it to. To do this we provide a &lt;a title="ControlTemplate Class" href="http://msdn2.microsoft.com/ms609827.aspx"&gt;ControlTemplate&lt;/a&gt; in our &lt;a title="Window Class" href="http://msdn2.microsoft.com/ms590112.aspx"&gt;Window&lt;/a&gt; &lt;a title="Style Class" href="http://msdn2.microsoft.com/ms603146.aspx"&gt;Style&lt;/a&gt; as you can see in the following picture:&lt;/p&gt;

&lt;p&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="269" alt="CustomWindow" src="http://lh3.ggpht.com/derek.lakin/SCSIzjjIZSI/AAAAAAAAACg/_0TAfma3xwU/CustomWindow%5B3%5D.png?imgmax=800" width="500" border="0" /&gt; &lt;/p&gt;

&lt;p&gt;You use regular WPF layout controls and elements to provide the look-and-feel that you require, but it's worth mentioning three things.&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;You need to include a &lt;a title="ContentPresenter Class" href="http://msdn2.microsoft.com/ms609804.aspx"&gt;ContentPresenter&lt;/a&gt; element in your &lt;a title="ControlTemplate Class" href="http://msdn2.microsoft.com/ms609827.aspx"&gt;ControlTemplate&lt;/a&gt; so that the XAML that you supply in the Window definition gets displayed. You should bind the &lt;a title="ContentPresenter..::.Content Property " href="http://msdn2.microsoft.com/ms592481.aspx"&gt;Content&lt;/a&gt; property of the &lt;a title="ContentPresenter Class" href="http://msdn2.microsoft.com/ms609804.aspx"&gt;ContentPresenter&lt;/a&gt; to &lt;code&gt;{TemplateBinding Content}&lt;/code&gt; as shown in the following example XAML code. &lt;/li&gt;

  &lt;li&gt;You should wrap your &lt;a title="ContentPresenter Class" href="http://msdn2.microsoft.com/ms609804.aspx"&gt;ContentPresenter&lt;/a&gt; element in an &lt;a title="AdornerDecorator Class" href="http://msdn2.microsoft.com/ms600182.aspx"&gt;AdornerDecorator&lt;/a&gt; element. This isn't strictly necessary unless you want to support drag-and-drop, but it won't hurt to include it just in case. &lt;/li&gt;

  &lt;li&gt;If you want to display the window title somehow (which is still likely even though you're using a custom look-and-feel), you can use a template binding to access the regular &lt;a title="Window..::.Title Property " href="http://msdn2.microsoft.com/ms588788.aspx"&gt;Window.Title&lt;/a&gt; property. &lt;/li&gt;
&lt;/ol&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Style &lt;/span&gt;&lt;span style="color: red"&gt;x&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: red"&gt;Key&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;MessageBox&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;TargetType&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color: #a31515"&gt;x&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;Type &lt;/span&gt;&lt;span style="color: red"&gt;Window&lt;/span&gt;&lt;span style="color: blue"&gt;}&amp;quot;&amp;gt;
&lt;/span&gt;&lt;span style="color: blue"&gt;    ...&lt;/span&gt;&lt;span style="color: blue"&gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Setter &lt;/span&gt;&lt;span style="color: red"&gt;Property&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;Template&amp;quot;&amp;gt;
        &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Setter.Value&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
            &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;ControlTemplate &lt;/span&gt;&lt;span style="color: red"&gt;TargetType&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color: #a31515"&gt;x&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;Type &lt;/span&gt;&lt;span style="color: red"&gt;Window&lt;/span&gt;&lt;span style="color: blue"&gt;}&amp;quot;&amp;gt;
&lt;/span&gt;&lt;span&gt;                ...&lt;/span&gt;
                &lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Label &lt;/span&gt;&lt;span style="color: red"&gt;Content&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color: #a31515"&gt;TemplateBinding &lt;/span&gt;&lt;span style="color: red"&gt;Title&lt;/span&gt;&lt;span style="color: blue"&gt;}&amp;quot; /&amp;gt;
&lt;span&gt;                ...&lt;/span&gt;&lt;/span&gt;
                &lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;AdornerDecorator&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&lt;/span&gt;                        &lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;ContentPresenter
                            &lt;/span&gt;&lt;span style="color: red"&gt;Content&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color: #a31515"&gt;TemplateBinding &lt;/span&gt;&lt;span style="color: red"&gt;Content&lt;/span&gt;&lt;span style="color: blue"&gt;}&amp;quot; 
&lt;/span&gt;&lt;span style="color: blue"&gt;                            &lt;/span&gt;&lt;span style="color: red"&gt;Margin&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color: #a31515"&gt;TemplateBinding &lt;/span&gt;&lt;span style="color: red"&gt;Margin&lt;/span&gt;&lt;span style="color: blue"&gt;}&amp;quot; /&amp;gt;
&lt;/span&gt;&lt;span style="color: blue"&gt;                &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;AdornerDecorator&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&lt;/span&gt;&lt;span style="color: blue"&gt;            &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;ControlTemplate&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
        &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Setter.Value&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Setter&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Style&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;h2&gt;Creating a Custom Message Box&lt;/h2&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;Now that we've got all of the elements of a custom Window Style, moving to a custom message box is just a matter of implementation. The attached sample code includes an almost complete implementation of a Message Box including setting the message box buttons, image, caption, text, and default result. I won't bore you with the details, just download it and take a look, but there are a couple of points worth noting.&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;h3&gt;Setting the WindowStartupLocation&lt;/h3&gt;

&lt;p&gt;The &lt;a title="Window..::.WindowStartupLocation Property " href="http://msdn2.microsoft.com/ms588791.aspx"&gt;WindowStartupLocation&lt;/a&gt; property isn't a dependency property, so we can't set it in the Style and apply it to all of our custom windows. The custom message box class simply sets it in the window XAML, but you should be aware of this for your own custom windows.&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;h3&gt;Binding to Enumerations&lt;/h3&gt;

&lt;p&gt;I've blogged about &lt;a href="http://cloudstore.blogspot.com/2008/04/binding-to-enumerations.html"&gt;binding to enumerations&lt;/a&gt; before, but I came across an interesting problem when producing the sample application.&lt;/p&gt;

&lt;p&gt;I wanted to bind a &lt;a title="ComboBox Class" href="http://msdn2.microsoft.com/ms609785.aspx"&gt;ComboBox&lt;/a&gt; to the &lt;a title="MessageBoxImage Enumeration" href="http://msdn2.microsoft.com/ms602953.aspx"&gt;MessageBoxImage&lt;/a&gt; enumeration, but this enumeration has several names that resolve to the same value (&lt;a title="Asterisk Field" href="http://msdn2.microsoft.com/bb299836.aspx"&gt;Asterisk&lt;/a&gt; and &lt;a title="Information Field" href="http://msdn2.microsoft.com/bb396534.aspx"&gt;Information&lt;/a&gt;, &lt;a title="Error Field" href="http://msdn2.microsoft.com/bb356871.aspx"&gt;Error&lt;/a&gt;, &lt;a title="Hand Field" href="http://msdn2.microsoft.com/bb156238.aspx"&gt;Hand&lt;/a&gt; and &lt;a title="Stop Field" href="http://msdn2.microsoft.com/bb358655.aspx"&gt;Stop&lt;/a&gt;, and &lt;a title="Exclamation Field" href="http://msdn2.microsoft.com/bb302863.aspx"&gt;Exclamation&lt;/a&gt; and &lt;a title="Warning Field" href="http://msdn2.microsoft.com/bb339087.aspx"&gt;Warning&lt;/a&gt;), so a call to &lt;a title="Enum..::.GetValues Method " href="http://msdn2.microsoft.com/d8118w4z.aspx"&gt;Enum.GetValues&lt;/a&gt; results in a list of the enumerated values being recalled. When the binding engine binds the resulting list of values in the &lt;a title="ComboBox Class" href="http://msdn2.microsoft.com/ms609785.aspx"&gt;ComboBox&lt;/a&gt;, it uses the ToString method to display the name of the enumeration. However, because several of the names resolve to the same name, I was getting the first name repeated multiple times.&lt;/p&gt;

&lt;p&gt;This makes sense, because there is no way for the binding engine to resolve the same number to different string names.&lt;/p&gt;

&lt;p&gt;The solution was to use the &lt;a title="Enum..::.GetNames Method " href="http://msdn2.microsoft.com/928552tz.aspx"&gt;GetNames&lt;/a&gt; method instead, which results in a list of strings being returned to the &lt;a title="ComboBox Class" href="http://msdn2.microsoft.com/ms609785.aspx"&gt;ComboBox&lt;/a&gt;. As a result, you need to set the SelectedValue using the appropriate string value instead of an actual enumeration in the SelectedItem to set the initial selection, and you'll need to use the &lt;a title="Enum..::.Parse Method " href="http://msdn2.microsoft.com/sehsc5fz.aspx"&gt;System.Enum.Parse&lt;/a&gt; method if you want to get an enumeration from the SelectedItem.&lt;/p&gt;

&lt;p&gt;I hope you find some or all of this useful. Feel free to use the attached code to whatever end you like, commercial or otherwise.&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;&lt;iframe style="border-right: #dde5e9 1px solid; padding-right: 0px; border-top: #dde5e9 1px solid; padding-left: 0px; padding-bottom: 0px; margin: 3px; border-left: #dde5e9 1px solid; width: 240px; padding-top: 0px; border-bottom: #dde5e9 1px solid; height: 66px; background-color: #ffffff" marginwidth="0" marginheight="0" src="http://cid-2ebcba238c071a49.skydrive.live.com/embedrowdetail.aspx/WPF/CustomWindow.zip" frameborder="0" scrolling="no"&gt;&lt;/iframe&gt;&lt;/p&gt;

&lt;div class="wlWriterHeaderFooter" style="margin:0px; padding:0px 0px 0px 0px;"&gt;This work is licensed under a &lt;a href="http://creativecommons.org/licenses/by/3.0/"&gt;Creative Commons Attribution By license.&lt;/a&gt;&lt;/div&gt;&lt;div class="wlWriterHeaderFooter" style="float:left; margin:0px; padding:0px 0px 0px 0px;"&gt;&lt;a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fcloudstore.blogspot.com%2f2008%2f05%2fcreating-custom-window-style.html"&gt;&lt;img alt="kick it on DotNetKicks.com" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fcloudstore.blogspot.com%2f2008%2f05%2fcreating-custom-window-style.html&amp;amp;bgcolor=47505F&amp;amp;cbgcolor=FFFFFF" border="0" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class="wlWriterHeaderFooter" style="text-align:left; margin:0px; padding:4px 4px 4px 4px;"&gt;&lt;script type="text/javascript"&gt;var dzone_url = 'http://cloudstore.blogspot.com/2008/05/creating-custom-window-style.html';&lt;/script&gt;&lt;script type="text/javascript"&gt;var dzone_title = 'Creating a Custom Window Style';&lt;/script&gt;&lt;script type="text/javascript"&gt;var dzone_blurb = 'Creating a Custom Window Style';&lt;/script&gt;&lt;script type="text/javascript"&gt;var dzone_style = '2';&lt;/script&gt;&lt;script language="javascript" src="http://widgets.dzone.com/widgets/zoneit.js"&gt;&lt;/script&gt; &lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=7P0TT6JspzA:PBEEH3udoHI:4cEx4HpKnUU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?i=7P0TT6JspzA:PBEEH3udoHI:4cEx4HpKnUU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=7P0TT6JspzA:PBEEH3udoHI:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=7P0TT6JspzA:PBEEH3udoHI:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?i=7P0TT6JspzA:PBEEH3udoHI:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=7P0TT6JspzA:PBEEH3udoHI:oCFASsrFxfc"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?d=oCFASsrFxfc" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=7P0TT6JspzA:PBEEH3udoHI:Jwdi1b3fU3Q"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?d=Jwdi1b3fU3Q" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/cloudstore?a=7P0TT6JspzA:PBEEH3udoHI:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/cloudstore?i=7P0TT6JspzA:PBEEH3udoHI:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/cloudstore/~4/7P0TT6JspzA" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/cloudstore/~3/7P0TT6JspzA/creating-custom-window-style.html</link><author>noreply@blogger.com (Derek Lakin)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://lh5.ggpht.com/derek.lakin/SCSIxDjIZOI/AAAAAAAAACA/sX2J_SyuPN0/s72-c/CustomWindow7.png?imgmax=800" height="72" width="72" /><thr:total>8</thr:total><feedburner:origLink>http://cloudstore.blogspot.com/2008/05/creating-custom-window-style.html</feedburner:origLink></item></channel></rss>
