<?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:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Richard Dutton</title>
	
	<link>http://www.dutton.me.uk</link>
	<description>Software Engineering, Photography, Travel, Stuff...</description>
	<lastBuildDate>Thu, 03 May 2012 00:03:25 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/RichardDutton" /><feedburner:info uri="richarddutton" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>Rolling back to previous ClickOnce versions</title>
		<link>http://feedproxy.google.com/~r/RichardDutton/~3/rS8dgtMwJGc/</link>
		<comments>http://www.dutton.me.uk/2011/09/07/rolling-back-to-previous-clickonce-versions/#comments</comments>
		<pubDate>Wed, 07 Sep 2011 16:12:23 +0000</pubDate>
		<dc:creator>richard</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[back]]></category>
		<category><![CDATA[click once]]></category>
		<category><![CDATA[clickonce]]></category>
		<category><![CDATA[deployment]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[roll]]></category>
		<category><![CDATA[roll back]]></category>
		<category><![CDATA[rollback]]></category>

		<guid isPermaLink="false">http://www.dutton.me.uk/?p=401</guid>
		<description><![CDATA[I&#8217;ve been deploying software using Microsoft&#8217;s ClickOnce mechanism a lot lately and despite enjoying  its simplicity, especially in comparison to some of the more complicated MSI Setup Projects I&#8217;ve inherited, I&#8217;ve found myself slightly nervous about its abililty to turn a simple software code update into a potentially massively distributed network of fail with its [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been deploying software using Microsoft&#8217;s ClickOnce mechanism a lot lately and despite enjoying  its simplicity, especially in comparison to some of the more complicated MSI Setup Projects I&#8217;ve inherited, I&#8217;ve found myself slightly nervous about its abililty to turn a simple software code update into a potentially massively distributed network of fail with its Auto Updating feature.</p>
<p>Because of this, you occasionally have a rather urgent need to roll back everyone to the last working version, and this turns out to be rather easy.<span id="more-401"></span></p>
<p>In the publish&#8217;s output folder you will see a file called &#8220;&lt;application name&gt;.application&#8221;. This is the ClickOnce Application Deployment Manifest and contains a load of details about the application and in particular the version to install and where to find it.</p>
<p>You will also see an &#8220;Application Files&#8221; folder which will contain a folder for each version of your application deployed so far. To revert all of your users to a previous version, simply copy the &#8220;&lt;application name&gt;.application&#8221; file from the relevant version subdirectory over the one in the root, then either point your users at your ClickOnce location or if you had the application set to check for and apply updates automatically just tell them to restart. The application will detect that there is a &#8220;newer&#8221; version (even if that version is in fact older) and allow the user to install it.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/RichardDutton?a=rS8dgtMwJGc:pGxErGMDK0U:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/RichardDutton?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/RichardDutton?a=rS8dgtMwJGc:pGxErGMDK0U:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/RichardDutton?i=rS8dgtMwJGc:pGxErGMDK0U:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/RichardDutton?a=rS8dgtMwJGc:pGxErGMDK0U:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/RichardDutton?i=rS8dgtMwJGc:pGxErGMDK0U:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/RichardDutton?a=rS8dgtMwJGc:pGxErGMDK0U:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/RichardDutton?d=qj6IDK7rITs" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/RichardDutton/~4/rS8dgtMwJGc" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.dutton.me.uk/2011/09/07/rolling-back-to-previous-clickonce-versions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.dutton.me.uk/2011/09/07/rolling-back-to-previous-clickonce-versions/</feedburner:origLink></item>
		<item>
		<title>RichTextBox ScrollToCaret() bug</title>
		<link>http://feedproxy.google.com/~r/RichardDutton/~3/m2OhtinPjMg/</link>
		<comments>http://www.dutton.me.uk/2011/08/31/richtextbox-scrolltocaret-bug/#comments</comments>
		<pubDate>Wed, 31 Aug 2011 09:23:02 +0000</pubDate>
		<dc:creator>richard</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Windows Forms]]></category>
		<category><![CDATA[bug]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[richtextbox]]></category>
		<category><![CDATA[scroll]]></category>
		<category><![CDATA[scrolltocaret]]></category>
		<category><![CDATA[win forms]]></category>
		<category><![CDATA[windows forms]]></category>
		<category><![CDATA[winforms]]></category>

		<guid isPermaLink="false">http://www.dutton.me.uk/?p=395</guid>
		<description><![CDATA[I recently needed to add selective colour to text in a Windows Forms TextBox. TextBox doesn&#8217;t support this, but its close sibling RichTextBox does and as they both derive from TextBoxBase, the conversion in code was painless. The original TextBox control would automatically set the caret (cursor) position to the end of the text and [...]]]></description>
			<content:encoded><![CDATA[<p>I recently needed to add selective colour to text in a Windows Forms TextBox. TextBox doesn&#8217;t support this, but its close sibling RichTextBox does and as they both derive from TextBoxBase, the conversion in code was painless.</p>
<p>The original TextBox control would automatically set the caret (cursor) position to the end of the text and use ScrollToCaret() to ensure the last line was always visible after dynamically adding content. This doesn&#8217;t quite work the same when called on a RichTextBox as it appears to scroll until just the very top of the caret is visible, resulting in at best a few pixels of the last line&#8217;s text visible.</p>
<p>Quite a bit of googling of the problem reveals lots of discussion but not much in the way of a suggested solution.</p>
<p>Fortunately, user32.dll provides calls we can use to set the scroll position and we can access these unmanaged functions through P/Invoke as follows:</p>
<pre class="c-sharp">
[StructLayout(LayoutKind.Sequential)]
public class POINT
{
    public int x;
    public int y;

    public POINT()
    {
    }

    public POINT(int x, int y)
    {
        this.x = x;
        this.y = y;
    }
}

const int SB_VERT = 1;
const int EM_SETSCROLLPOS = 0x0400 + 222;

[DllImport("user32", CharSet = CharSet.Auto)]
static extern bool GetScrollRange(IntPtr hWnd, int nBar, out int lpMinPos, out int lpMaxPos);

[DllImport("user32", CharSet = CharSet.Auto)]
static extern IntPtr SendMessage(IntPtr hWnd, int msg, int wParam, POINT lParam)
</pre>
<p>Then, when you want to set the scroll position (&#8220;control&#8221; is your RichTextBox instance):</p>
<pre class="c-sharp">
int min, max;
GetScrollRange(control.Handle, SB_VERT, out min, out max);
SendMessage(control.Handle, EM_SETSCROLLPOS, 0, new POINT(0, max - control.Height));
</pre>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/RichardDutton?a=m2OhtinPjMg:-CvtREM8E74:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/RichardDutton?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/RichardDutton?a=m2OhtinPjMg:-CvtREM8E74:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/RichardDutton?i=m2OhtinPjMg:-CvtREM8E74:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/RichardDutton?a=m2OhtinPjMg:-CvtREM8E74:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/RichardDutton?i=m2OhtinPjMg:-CvtREM8E74:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/RichardDutton?a=m2OhtinPjMg:-CvtREM8E74:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/RichardDutton?d=qj6IDK7rITs" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/RichardDutton/~4/m2OhtinPjMg" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.dutton.me.uk/2011/08/31/richtextbox-scrolltocaret-bug/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.dutton.me.uk/2011/08/31/richtextbox-scrolltocaret-bug/</feedburner:origLink></item>
		<item>
		<title>Microsoft 70-511 Exam Passed</title>
		<link>http://feedproxy.google.com/~r/RichardDutton/~3/ZOQWg_XhsjQ/</link>
		<comments>http://www.dutton.me.uk/2011/08/15/microsoft-70-511-exam-passed/#comments</comments>
		<pubDate>Mon, 15 Aug 2011 15:06:15 +0000</pubDate>
		<dc:creator>richard</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[.net framework 4]]></category>
		<category><![CDATA[70-511]]></category>
		<category><![CDATA[certified]]></category>
		<category><![CDATA[exam]]></category>
		<category><![CDATA[mcts]]></category>
		<category><![CDATA[microsoft]]></category>
		<category><![CDATA[microsoft certified technology specialist]]></category>
		<category><![CDATA[windows applications]]></category>

		<guid isPermaLink="false">http://www.dutton.me.uk/?p=391</guid>
		<description><![CDATA[Last week I passed the Microsoft 70-511: Windows Application Development with Microsoft .NET Framework 4 exam, making me a Microsoft Certified Technology Specialist! This is the first of four exams I&#8217;m aiming to complete in order to become a Microsoft Certified Professional Developer.]]></description>
			<content:encoded><![CDATA[<p>Last week I passed the Microsoft 70-511: Windows Application Development with Microsoft .NET Framework 4 exam, making me a Microsoft Certified Technology Specialist!</p>
<p><a href="http://www.dutton.me.uk/wp-content/uploads/2011/08/MCTSrgb_1369.png"><img class="aligncenter size-full wp-image-392" title="MCTS 70-511" src="http://www.dutton.me.uk/wp-content/uploads/2011/08/MCTSrgb_1369.png" alt="" width="366" height="80" /></a></p>
<p>This is the first of four exams I&#8217;m aiming to complete in order to become a Microsoft Certified Professional Developer.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/RichardDutton?a=ZOQWg_XhsjQ:Pf9XXb_vezQ:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/RichardDutton?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/RichardDutton?a=ZOQWg_XhsjQ:Pf9XXb_vezQ:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/RichardDutton?i=ZOQWg_XhsjQ:Pf9XXb_vezQ:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/RichardDutton?a=ZOQWg_XhsjQ:Pf9XXb_vezQ:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/RichardDutton?i=ZOQWg_XhsjQ:Pf9XXb_vezQ:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/RichardDutton?a=ZOQWg_XhsjQ:Pf9XXb_vezQ:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/RichardDutton?d=qj6IDK7rITs" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/RichardDutton/~4/ZOQWg_XhsjQ" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.dutton.me.uk/2011/08/15/microsoft-70-511-exam-passed/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://www.dutton.me.uk/2011/08/15/microsoft-70-511-exam-passed/</feedburner:origLink></item>
		<item>
		<title>How to handle Command Line Arguments in WPF Applications</title>
		<link>http://feedproxy.google.com/~r/RichardDutton/~3/0ixroTVs5_U/</link>
		<comments>http://www.dutton.me.uk/2011/02/21/how-to-handle-command-line-arguments-in-wpf-applications/#comments</comments>
		<pubDate>Mon, 21 Feb 2011 16:12:03 +0000</pubDate>
		<dc:creator>richard</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[Application]]></category>
		<category><![CDATA[arguments]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[command line]]></category>
		<category><![CDATA[command line arguments]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[Startup]]></category>
		<category><![CDATA[StartupEventArgs]]></category>

		<guid isPermaLink="false">http://www.dutton.me.uk/?p=378</guid>
		<description><![CDATA[I&#8217;ve not considered it before as up to now I haven&#8217;t required it, but obviously in a WPF Application you don&#8217;t have a nice static void Main(string[] args) { ... } with a useful string array of arguments like you do in a regular C# console app, so how do you access them? In a [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve not considered it before as up to now I haven&#8217;t required it, but obviously in a WPF Application you don&#8217;t have a nice</p>
<pre name="code" class="c-sharp">static void Main(string[] args)
{
...
}</pre>
<p>with a useful string array of arguments like you do in a regular C# console app, so how do you access them?</p>
<p>In a default WPF application, the entry point to the program is <span id="more-378"></span>the <strong>Application</strong> object. This object has an event <strong>Startup</strong> which is fired, unsurprisingly on startup of your app and contains <strong>StartupEventArgs</strong>. You can query this object to get to your arguments as follows:</p>
<pre name="code" class="c-sharp">
public partial class App : Application
 {
   ///
   /// A static string array containing our start-up command line arguments
   ///
   public static string[] Args;

   protected override void OnStartup(StartupEventArgs e)
   {
       Args = e.Args;
       base.OnStartup(e);
   }
}</pre>
<p>Store them in a static member and then you can access them elsewhere in your application as <strong>Apps.Args</strong>.</p>
<p>So far, so good. But what happens if you actually need some arguments to run, and so want to check and fail gracefully if they don&#8217;t exist? I found that if I checked in my <strong>OnStartup</strong> handler, I still couldn&#8217;t halt the start-up of my application on error.</p>
<p>Instead, I added a <strong>Loaded</strong> event handler to my MainWindow. This is fired once the Application and MainWindow have been loaded so I know I my static Args member will have been set by the time it is fired. I can do all the validation I want on my argument array and decide whether to continue execution or stop and provide an error to the user.</p>
<pre name="code" class="c-sharp">
public MainWindow()
{
     InitializeComponent();

     // Make sure the command line arguments have been processed
     this.Loaded += new RoutedEventHandler(MainWindow_Loaded);
}

void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
    if (App.Args.Length == 1)
    {
        // everything is good, do stuff
    }
    else
    {
        // ERROR!!!
        MessageBox.Show("Not enough arguments!");
        App.Current.Shutdown();
     }
}</pre>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/RichardDutton?a=0ixroTVs5_U:-8KrB2flixM:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/RichardDutton?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/RichardDutton?a=0ixroTVs5_U:-8KrB2flixM:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/RichardDutton?i=0ixroTVs5_U:-8KrB2flixM:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/RichardDutton?a=0ixroTVs5_U:-8KrB2flixM:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/RichardDutton?i=0ixroTVs5_U:-8KrB2flixM:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/RichardDutton?a=0ixroTVs5_U:-8KrB2flixM:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/RichardDutton?d=qj6IDK7rITs" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/RichardDutton/~4/0ixroTVs5_U" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.dutton.me.uk/2011/02/21/how-to-handle-command-line-arguments-in-wpf-applications/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://www.dutton.me.uk/2011/02/21/how-to-handle-command-line-arguments-in-wpf-applications/</feedburner:origLink></item>
		<item>
		<title>How to fix the iTunes 10 compilation album grouping bug</title>
		<link>http://feedproxy.google.com/~r/RichardDutton/~3/5mpgj1vXBzM/</link>
		<comments>http://www.dutton.me.uk/2011/02/14/how-to-fix-the-itunes-10-compilation-album-grouping-bug/#comments</comments>
		<pubDate>Mon, 14 Feb 2011 14:59:32 +0000</pubDate>
		<dc:creator>richard</dc:creator>
				<category><![CDATA[Apple]]></category>
		<category><![CDATA[iTunes]]></category>
		<category><![CDATA[10.1.2]]></category>
		<category><![CDATA[annoyance]]></category>
		<category><![CDATA[annoying]]></category>
		<category><![CDATA[compilation]]></category>
		<category><![CDATA[compilation album]]></category>
		<category><![CDATA[error]]></category>
		<category><![CDATA[fault]]></category>
		<category><![CDATA[fix]]></category>
		<category><![CDATA[grouping]]></category>
		<category><![CDATA[seperate listing bug]]></category>
		<category><![CDATA[sort album artist]]></category>

		<guid isPermaLink="false">http://www.dutton.me.uk/?p=370</guid>
		<description><![CDATA[I&#8217;ve been encoding a lot of my CDs in iTunes (10.1.2) lately. It generally does a great job of encoding to Apple Lossless and grabbing the appropriate track data and cover art from the internet I&#8217;ve have come across an annoying problem. Occasionally, despite ALL of the tags being the same, and numerous combinations of [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been encoding a lot of my CDs in iTunes (10.1.2) lately. It generally does a great job of encoding to Apple Lossless and grabbing the appropriate track data and cover art from the internet I&#8217;ve have come across an annoying problem. Occasionally, despite ALL of the tags being the same, and numerous combinations of &#8220;Compilation, Sort Album, etc&#8230;&#8221; being set, iTunes still insists on listing a compilation album as individual tracks like this:</p>
<p><a href="http://www.dutton.me.uk/wp-content/uploads/2011/02/Screen-shot-2011-02-14-at-14.25.49.png"><img class="aligncenter size-medium wp-image-371" title="The problem with iTunes grouping" src="http://www.dutton.me.uk/wp-content/uploads/2011/02/Screen-shot-2011-02-14-at-14.25.49-300x177.png" alt="" width="300" height="177" /></a></p>
<p>A google search of the problem shows that I&#8217;m not alone. There seems to be as many solutions as there are people posting so in case it&#8217;s of any use, here&#8217;s what has worked for me every time.<span id="more-370"></span></p>
<ol>
<li>Select all of the tracks you wish to group, right-click, and from the context menu select &#8220;Get Info&#8221;.</li>
<li>On the &#8220;Info&#8221; tab, enter a single space in the &#8220;Album Artist&#8221; field.<a href="http://www.dutton.me.uk/wp-content/uploads/2011/02/Screen-shot-2011-02-14-at-14.40.01.png"><img class="aligncenter size-medium wp-image-373" title="Album Artist field" src="http://www.dutton.me.uk/wp-content/uploads/2011/02/Screen-shot-2011-02-14-at-14.40.01-300x253.png" alt="" width="300" height="253" /></a></li>
<li>On the &#8220;Options&#8221; tab, set &#8220;Part of a compilation&#8221; to &#8220;Yes&#8221;.<a href="http://www.dutton.me.uk/wp-content/uploads/2011/02/Screen-shot-2011-02-14-at-14.39.25.png"><img class="aligncenter size-medium wp-image-374" title="Part of a Compilation" src="http://www.dutton.me.uk/wp-content/uploads/2011/02/Screen-shot-2011-02-14-at-14.39.25-300x253.png" alt="" width="300" height="253" /></a></li>
<li>Click &#8220;OK&#8221; to make those changes.</li>
<li>The album should now be grouped properly, and you&#8217;ll see something like this:<a href="http://www.dutton.me.uk/wp-content/uploads/2011/02/Screen-shot-2011-02-14-at-14.42.23.png"><img class="aligncenter size-medium wp-image-372" title="iTunes grouping but without &quot;Various Artists&quot;" src="http://www.dutton.me.uk/wp-content/uploads/2011/02/Screen-shot-2011-02-14-at-14.42.23-300x167.png" alt="" width="300" height="167" /></a></li>
<li>The only problem is now iTunes thinks that the album&#8217;s artist is &#8221; &#8221; and so isn&#8217;t listing it as &#8220;Various Artists&#8221;, so with the tracks selected, right-click and from the context menu select &#8220;Get Info&#8221; again.</li>
<li>This time on the &#8220;Info&#8221; tab, remove the single space from the &#8220;Album Artist&#8221; field.</li>
<li>Click &#8220;OK&#8221; to make that change and the album should now be grouped properly and listed as Various Artists.</li>
</ol>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/RichardDutton?a=5mpgj1vXBzM:rZ9NFahVbdA:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/RichardDutton?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/RichardDutton?a=5mpgj1vXBzM:rZ9NFahVbdA:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/RichardDutton?i=5mpgj1vXBzM:rZ9NFahVbdA:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/RichardDutton?a=5mpgj1vXBzM:rZ9NFahVbdA:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/RichardDutton?i=5mpgj1vXBzM:rZ9NFahVbdA:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/RichardDutton?a=5mpgj1vXBzM:rZ9NFahVbdA:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/RichardDutton?d=qj6IDK7rITs" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/RichardDutton/~4/5mpgj1vXBzM" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.dutton.me.uk/2011/02/14/how-to-fix-the-itunes-10-compilation-album-grouping-bug/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		<feedburner:origLink>http://www.dutton.me.uk/2011/02/14/how-to-fix-the-itunes-10-compilation-album-grouping-bug/</feedburner:origLink></item>
		<item>
		<title>DoshTracker Update #5 – 16 months later…</title>
		<link>http://feedproxy.google.com/~r/RichardDutton/~3/3n-LbakfTtE/</link>
		<comments>http://www.dutton.me.uk/2011/02/02/doshtracker-update-5-%e2%80%93-16-months-later/#comments</comments>
		<pubDate>Wed, 02 Feb 2011 14:46:31 +0000</pubDate>
		<dc:creator>richard</dc:creator>
				<category><![CDATA[Doshtracker]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://www.dutton.me.uk/?p=364</guid>
		<description><![CDATA[It has been a while, but not completely quiet on the DoshTracker front. Although last year my Project 365 took up most of my free time, I have been slowly working on another UI design using a new Javascript framework (jQuery) and this time it&#8217;s really coming together. We have: Full Google Maps interaction, plotting [...]]]></description>
			<content:encoded><![CDATA[<p>It <strong>has</strong> been a while, but not completely quiet on the DoshTracker front. Although last year my <a href="http://project365.dutton.me.uk" target="_blank">Project 365 </a>took up most of my free time, I have been slowly working on another UI design using a new Javascript framework (jQuery) and this time it&#8217;s really coming together.</p>
<p>We have:</p>
<ul>
<li>Full Google Maps interaction, plotting all our note hits on a map.</li>
<li>International support, now you can plot your notes anywhere the Google Maps API can geocode.</li>
<li>The complete old database! All of your original DoshTracker notes and user accounts have been preserved. These will be imported during the beta.</li>
</ul>
<p>Check out the new logo and design on <a href="http://www.doshtracker.co.uk" target="_blank">www.doshtracker.co.uk</a> and please sign up for our mailing list so we can keep in touch.</p>
<p>Invites to the closed beta test will be going out soon to the mailing list and former users of the old site.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/RichardDutton?a=3n-LbakfTtE:ufMncjVWxS8:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/RichardDutton?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/RichardDutton?a=3n-LbakfTtE:ufMncjVWxS8:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/RichardDutton?i=3n-LbakfTtE:ufMncjVWxS8:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/RichardDutton?a=3n-LbakfTtE:ufMncjVWxS8:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/RichardDutton?i=3n-LbakfTtE:ufMncjVWxS8:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/RichardDutton?a=3n-LbakfTtE:ufMncjVWxS8:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/RichardDutton?d=qj6IDK7rITs" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/RichardDutton/~4/3n-LbakfTtE" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.dutton.me.uk/2011/02/02/doshtracker-update-5-%e2%80%93-16-months-later/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.dutton.me.uk/2011/02/02/doshtracker-update-5-%e2%80%93-16-months-later/</feedburner:origLink></item>
		<item>
		<title>How to find the Hash key on a UK Mac Keyboard</title>
		<link>http://feedproxy.google.com/~r/RichardDutton/~3/zBbZjMBuZjA/</link>
		<comments>http://www.dutton.me.uk/2010/10/20/how-to-find-the-hash-key-on-a-uk-mac-keyboard/#comments</comments>
		<pubDate>Wed, 20 Oct 2010 10:02:49 +0000</pubDate>
		<dc:creator>richard</dc:creator>
				<category><![CDATA[Apple]]></category>
		<category><![CDATA[OS X]]></category>
		<category><![CDATA[#]]></category>
		<category><![CDATA[hash]]></category>
		<category><![CDATA[key]]></category>
		<category><![CDATA[keyboard]]></category>

		<guid isPermaLink="false">http://www.dutton.me.uk/?p=357</guid>
		<description><![CDATA[I&#8217;m a Microsoft .Net programmer by day and yet a Mac user by night, but occasionally I still need to type the &#8216;#&#8217; key on my UK Mac keyboard and always forget the shortcut as it&#8217;s not immediately apparent. I usually end up copying and pasting it from somewhere else. It&#8217;s ALT-3, #########, there!]]></description>
			<content:encoded><![CDATA[<div id="_mcePaste">I&#8217;m a Microsoft .Net programmer by day and yet a Mac user by night, but occasionally I still need to type the &#8216;#&#8217; key on my UK Mac keyboard and always forget the shortcut as it&#8217;s not immediately apparent. I usually end up copying and pasting it from somewhere else.</div>
<div></div>
<div id="_mcePaste">It&#8217;s ALT-3, #########, there!</div>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/RichardDutton?a=zBbZjMBuZjA:-ItDDLwlSJo:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/RichardDutton?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/RichardDutton?a=zBbZjMBuZjA:-ItDDLwlSJo:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/RichardDutton?i=zBbZjMBuZjA:-ItDDLwlSJo:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/RichardDutton?a=zBbZjMBuZjA:-ItDDLwlSJo:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/RichardDutton?i=zBbZjMBuZjA:-ItDDLwlSJo:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/RichardDutton?a=zBbZjMBuZjA:-ItDDLwlSJo:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/RichardDutton?d=qj6IDK7rITs" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/RichardDutton/~4/zBbZjMBuZjA" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.dutton.me.uk/2010/10/20/how-to-find-the-hash-key-on-a-uk-mac-keyboard/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.dutton.me.uk/2010/10/20/how-to-find-the-hash-key-on-a-uk-mac-keyboard/</feedburner:origLink></item>
		<item>
		<title>OK – Cancel behaviour with data binding in WPF</title>
		<link>http://feedproxy.google.com/~r/RichardDutton/~3/IA-wBf-WVBI/</link>
		<comments>http://www.dutton.me.uk/2010/10/11/ok-cancel-behaviour-with-data-binding-in-wpf/#comments</comments>
		<pubDate>Mon, 11 Oct 2010 14:05:33 +0000</pubDate>
		<dc:creator>richard</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[GetBindingExpression]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://www.dutton.me.uk/?p=346</guid>
		<description><![CDATA[As much as I am a fan of the Mac OSX and iPhone approach of modifying a setting and having it apply immediately without any further user interaction, my current work involves designing GUIs for Industrial Control and Automation systems where the old &#60;OK&#62; &#60;Cancel&#62; buttons are still required (often by law) which brought up [...]]]></description>
			<content:encoded><![CDATA[<p>As much as I am a fan of the Mac OSX and iPhone approach of modifying a setting and having it apply immediately without any further user interaction, my current work involves designing GUIs for Industrial Control and Automation systems where the old &lt;OK&gt; &lt;Cancel&gt; buttons are still required (often by law) which brought up the question of how to do this in WPF with data binding where, depending on the control, updates are triggered either in real-time or on loss of focus.</p>
<p>The answer is in one of the attributes of Binding called &#8220;<strong>UpdateSourceTrigger</strong>&#8221; which has the following options:</p>
<ul>
<li><strong>LostFocus</strong> &#8211; Update bound property when the control loses focus (TextBox default).</li>
<li><strong>PropertyChanged</strong> &#8211; Update bound property in real-time.</li>
<li><strong>Explicit </strong>- Update bound property when UpdateSource() is called</li>
</ul>
<p>It is this last setting which allows us to delay updating our bound property until we tell it to.</p>
<p>Let&#8217;s say we have a UserControl containing a TextBox, &#8216;MyTextBox&#8217; which is bound to some Dependency Property and two buttons, &#8216;OK&#8217; and &#8216;Cancel&#8217;. Depending on how you hook your buttons up (with RoutedCommands or click handlers (eugh!)) the &#8216;OK&#8217; button&#8217;s code looks like this:</p>
<pre name="code" class="c-sharp">
BindingExpression be = MyTextBox.GetBindingExpression(TextBox.TextProperty);
if (be!=null) be.UpdateSource();</pre>
<p>The &#8216;Cancel&#8217; button&#8217;s code does the reverse:</p>
<pre name="code" class="c-sharp">
BindingExpression be = MyTextBox.GetBindingExpression(TextBox.TextProperty);
if (be!=null) be.UpdateTarget();</pre>
<p>Et voila! Your dependency property will now only update when you want it to.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/RichardDutton?a=IA-wBf-WVBI:Sg0fqnlUJuI:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/RichardDutton?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/RichardDutton?a=IA-wBf-WVBI:Sg0fqnlUJuI:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/RichardDutton?i=IA-wBf-WVBI:Sg0fqnlUJuI:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/RichardDutton?a=IA-wBf-WVBI:Sg0fqnlUJuI:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/RichardDutton?i=IA-wBf-WVBI:Sg0fqnlUJuI:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/RichardDutton?a=IA-wBf-WVBI:Sg0fqnlUJuI:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/RichardDutton?d=qj6IDK7rITs" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/RichardDutton/~4/IA-wBf-WVBI" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.dutton.me.uk/2010/10/11/ok-cancel-behaviour-with-data-binding-in-wpf/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://www.dutton.me.uk/2010/10/11/ok-cancel-behaviour-with-data-binding-in-wpf/</feedburner:origLink></item>
		<item>
		<title>Handling events from within a ControlTemplate in WPF</title>
		<link>http://feedproxy.google.com/~r/RichardDutton/~3/Bzz81ZfWj90/</link>
		<comments>http://www.dutton.me.uk/2010/02/13/handling-events-from-within-a-controltemplate-in-wpf/#comments</comments>
		<pubDate>Sat, 13 Feb 2010 07:00:42 +0000</pubDate>
		<dc:creator>richard</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[button]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[event]]></category>
		<category><![CDATA[events]]></category>
		<category><![CDATA[events inside a ControlTemplate]]></category>
		<category><![CDATA[events within a ControlTemplate]]></category>
		<category><![CDATA[GetTemplateChild]]></category>
		<category><![CDATA[OnApplyTemplate]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[RoutedEvent]]></category>
		<category><![CDATA[RoutedEventhandler]]></category>

		<guid isPermaLink="false">http://www.dutton.me.uk/?p=323</guid>
		<description><![CDATA[Here&#8217;s an interesting one that had me stumped for a few hours. Following on from my previous post, where I explained how to create a ControlTemplate to style a TextBox in WPF, I&#8217;ve got an object, TextEntryBox, which dervies from a TextBox (it provides some custom event handlers when text is entered, but to all [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s an interesting one that had me stumped for a few hours.</p>
<p>Following on from my <a href="http://www.dutton.me.uk/2010/02/13/how-to-create-a-controltemplate-for-a-wpf-textbox/" target="_blank">previous post</a>, where I explained how to create a ControlTemplate to style a TextBox in WPF, I&#8217;ve got an object, TextEntryBox, which dervies from a TextBox (it provides some custom event handlers when text is entered, but to all intents and purposes, it&#8217;s a regular TextBox).</p>
<p>I wanted to style my TextEntryBox, this time including a button within my ControlTemplate (this will eventually toggle an on-screen keyboard pop-up, but that&#8217;s another blog post!). I came up with this:<br />
<span id="more-323"></span></p>
<pre name="code" class="xml">
<Style TargetType="{x:Type my:EntryTextBox}">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type my:EntryTextBox}">
                <DockPanel>
                    <Border BorderThickness="1"
                    	HorizontalAlignment="Stretch"
                    	BorderBrush="DarkGray"
                    	Background="White"
                    	Width="100">
                        <DockPanel>
                            <Button x:Name="PART_KeyboardPopupButton"
                            	DockPanel.Dock="Right"
                            	Width="15"
                            	Height="10"/>
                            <ScrollViewer Margin="0"
                            	Background="Transparent"
                            	HorizontalAlignment="Stretch"
                            	x:Name="PART_ContentHost"/>
                        </DockPanel>
                    </Border>
                </DockPanel>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>
</pre>
<p>All&#8217;s well and good, until I want to try and handle the Click event for that button within my TextEntryBox class. Even Matthew MacDonald&#8217;s &#8220;Pro WPF in C# 2008&#8243; which has proved a lifesaver for all things WPF since I&#8217;ve been working with this technology only had the following words of wisdom;</p>
<blockquote><p>&#8220;You can&#8217;t attach event handlers in the control template. Instead, you&#8217;ll need to give your elements recognizable names and attach event handlers to them programmatically in the control constructor&#8221;</p></blockquote>
<p>But whatever I tried I couldn&#8217;t access the event in my constructor, until I remembered the seperation between the visual and logical trees in WPF.</p>
<p>The template is applied at runtime, and so elements contained within it it are part of the visual tree. My class, and therefore my class&#8217; constructor is executed within the logical tree, so I needed to attach my event handler after the template had been applied. You can do this by overriding OnApplyTemplate in your class, obtain the template that&#8217;s being applied, and then you have access to the named button&#8217;s events, like this:</p>
<pre name="code" class="c-sharp">
public override void OnApplyTemplate()
{
    DependencyObject d = GetTemplateChild("PART_KeyboardPopupButton");
    if (d != null)
    {
        (d as Button).Click += new RoutedEventHandler(KeyboardPopupButton_Click);
    }

    base.OnApplyTemplate();
}
</pre>
<p>Note the null check, as someone could have applied a completely different template to the object.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/RichardDutton?a=Bzz81ZfWj90:ngEs5zeMyLY:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/RichardDutton?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/RichardDutton?a=Bzz81ZfWj90:ngEs5zeMyLY:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/RichardDutton?i=Bzz81ZfWj90:ngEs5zeMyLY:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/RichardDutton?a=Bzz81ZfWj90:ngEs5zeMyLY:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/RichardDutton?i=Bzz81ZfWj90:ngEs5zeMyLY:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/RichardDutton?a=Bzz81ZfWj90:ngEs5zeMyLY:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/RichardDutton?d=qj6IDK7rITs" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/RichardDutton/~4/Bzz81ZfWj90" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.dutton.me.uk/2010/02/13/handling-events-from-within-a-controltemplate-in-wpf/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		<feedburner:origLink>http://www.dutton.me.uk/2010/02/13/handling-events-from-within-a-controltemplate-in-wpf/</feedburner:origLink></item>
		<item>
		<title>How to create a ControlTemplate for a WPF TextBox</title>
		<link>http://feedproxy.google.com/~r/RichardDutton/~3/fxDIlF80oho/</link>
		<comments>http://www.dutton.me.uk/2010/02/13/how-to-create-a-controltemplate-for-a-wpf-textbox/#comments</comments>
		<pubDate>Sat, 13 Feb 2010 06:00:10 +0000</pubDate>
		<dc:creator>richard</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[ContentHost]]></category>
		<category><![CDATA[ControlTemplate]]></category>
		<category><![CDATA[PART_ContentHost]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[ScrollViewer]]></category>
		<category><![CDATA[style]]></category>
		<category><![CDATA[TextBox]]></category>
		<category><![CDATA[x:Name]]></category>
		<category><![CDATA[x:Name="Part_ContentHost"]]></category>

		<guid isPermaLink="false">http://www.dutton.me.uk/?p=325</guid>
		<description><![CDATA[This is a short post, but has one specific piece of information I want to keep. Q: If you want to create a ControlTemplate to provide a custom style for a TextBox, how do you specify where the text goes when it&#8217;s used in WPF? A: The answer was hidden in the depths of the [...]]]></description>
			<content:encoded><![CDATA[<p>This is a short post, but has one specific piece of information I want to keep.</p>
<p>Q: If you want to create a ControlTemplate to provide a custom style for a TextBox, how do you specify where the text goes when it&#8217;s used in WPF?</p>
<p>A: The answer was hidden in the depths of the MSDN Documentation. You have to include a &lt;ScrollViewer&gt; within your ControlTemplate with an x:Name value of &#8220;PART_ContentHost&#8221;.</p>
<p>Here&#8217;s a noddy example:</p>
<pre name="code" class="xml">
<Style TargetType="{x:Type TextBox}">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type TextBox}">
                <DockPanel>
                    <Border BorderThickness="1"
                               BorderBrush="DarkGray"
                               Background="White"
                               Width="100">
                        <DockPanel>
                            <ScrollViewer Background="Transparent"
                                               HorizontalAlignment="Stretch"
                                               x:Name="PART_ContentHost"/>
                        </DockPanel>
                    </Border>
                </DockPanel>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>
</pre>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/RichardDutton?a=fxDIlF80oho:z0lkeSAu5mk:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/RichardDutton?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/RichardDutton?a=fxDIlF80oho:z0lkeSAu5mk:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/RichardDutton?i=fxDIlF80oho:z0lkeSAu5mk:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/RichardDutton?a=fxDIlF80oho:z0lkeSAu5mk:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/RichardDutton?i=fxDIlF80oho:z0lkeSAu5mk:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/RichardDutton?a=fxDIlF80oho:z0lkeSAu5mk:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/RichardDutton?d=qj6IDK7rITs" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/RichardDutton/~4/fxDIlF80oho" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.dutton.me.uk/2010/02/13/how-to-create-a-controltemplate-for-a-wpf-textbox/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://www.dutton.me.uk/2010/02/13/how-to-create-a-controltemplate-for-a-wpf-textbox/</feedburner:origLink></item>
	</channel>
</rss>

