<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	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/"
	>

<channel>
	<title>Code Green Software</title>
	<atom:link href="http://mel-green.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://mel-green.com</link>
	<description></description>
	<lastBuildDate>Fri, 18 May 2012 14:44:14 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
<image>
  <link>http://mel-green.com</link>
  <url>http://mel-green.com//Images/favicon.png</url>
  <title>Code Green Software</title>
</image>
		<item>
		<title>Call of Duty: Modern Warfare 3 Multiple Profiles</title>
		<link>http://mel-green.com/2011/11/call-of-duty-modern-warfare-3-multiple-profiles/</link>
		<comments>http://mel-green.com/2011/11/call-of-duty-modern-warfare-3-multiple-profiles/#comments</comments>
		<pubDate>Thu, 17 Nov 2011 03:44:10 +0000</pubDate>
		<dc:creator>Mel</dc:creator>
				<category><![CDATA[Software]]></category>

		<guid isPermaLink="false">http://mel-green.com/?p=517</guid>
		<description><![CDATA[I created this launcher to provide multiple profiles for the single player game of Call of Duty: Modern Warfare 3. This is similar to the loader I wrote for Modern Warfare 2 which you can find here. As there are multiple ways to acquire this game and install it, this may not work for everyone. [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://mel-green.com/wp-content/uploads/2011/11/mw3_launcher.png" alt="Modern Warfare 3 Multiple Profiles Launcher" title="Modern Warfare 3 Multiple Profiles Launcher" width="491" height="310" class="aligncenter size-full wp-image-493" /></p>
<p>I created this launcher to provide multiple profiles for the single player game of <em>Call of Duty: Modern Warfare 3</em>. This is similar to the loader I wrote for Modern Warfare 2 which you can find <a href="http://mel-green.com/2009/11/modern-warfare-2-multiple-profiles-loader/" target="_blank">here</a>. As there are multiple ways to acquire this game and install it, this may not work for everyone.</p>
<p><strong>Instructions:</strong></p>
<ol>
<li>Download the zip file <a href="http://mel-green.com/Uploads/MW3_Multiple_Profiles_Loader.zip">here</a></li>
<li>Extract the contents to the install directory for <em>Modern Warfare 3</em></li>
<li>Create a shortcut on your desktop for <em>MW3 Loader.exe</em> and use it instead of launching the game directly.</li>
<li>When you click &#8220;Launch&#8221; and you&#8217;re asked to select a program or shortcut to run, navigate to the shortcut you would normally use to launch the single player game and select it. This will ensure that the game is run through Steam.</li>
<li>If for some reason you need to re-select a program or shortcut to run, you can do this by resetting the Loader. To do this you need to delete the <em>settings.xml</em> file located in:<br /> <strong>(XP)</strong> <em>C:\Documents and Settings\All Users\Application Data\MW3_Loader\</em> <br /> <strong>(Vista)</strong> <em>C:\Program Data\MW3_Loader\</em> <br /> <strong>(Win7)</strong> <em>C:\ProgramData\MW3_Loader\</em></li>
<li>If you don&#8217;t already have the Microsoft .Net Framework 3.5 installed on your system, you will need to download it <a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=333325FD-AE52-4E35-B531-508D977D32A6&amp;displaylang=en">here</a></li>
</ol>
<p>Here&#8217;s a picture of what the game directory should look like after you&#8217;ve extracted the file:<br />
<img src="http://mel-green.com/wp-content/uploads/2011/11/mw3_dir.png" alt="Modern Warfare 3 Install Directory" title="Modern Warfare 3 Install Directory" width="493" height="641" class="aligncenter size-full wp-image-490" /></p>
<p>Note: This only works for the PC version of the game and as far as I know only changes your Single Player profile, which includes all game settings and saved games.</p>
<p>If you have any questions or comments please feel free to post them below. Feedback and praise is always welcome!</p>
]]></content:encoded>
			<wfw:commentRss>http://mel-green.com/2011/11/call-of-duty-modern-warfare-3-multiple-profiles/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>WPF: Focus DatePicker on Text in TextBox</title>
		<link>http://mel-green.com/2011/02/wpf-focus-datepicker-on-text-in-textbox/</link>
		<comments>http://mel-green.com/2011/02/wpf-focus-datepicker-on-text-in-textbox/#comments</comments>
		<pubDate>Sun, 20 Feb 2011 23:52:08 +0000</pubDate>
		<dc:creator>Mel</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[DatePicker]]></category>
		<category><![CDATA[Focus]]></category>

		<guid isPermaLink="false">http://mel-green.com/?p=498</guid>
		<description><![CDATA[I&#8217;ve been using the DatePicker control (which can be found in WPF 4.0 as well as the WPF Toolkit) and have come across a situation where I would like to set keyboard focus on a DatePicker programmatically so that the user can immediately begin typing a date into the control. Well like many other people [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been using the <strong>DatePicker</strong> control (which can be found in WPF 4.0 as well as the WPF Toolkit) and have come across a situation where I would like to set keyboard focus on a <strong>DatePicker</strong> programmatically so that the user can immediately begin typing a date into the control. Well like many other people out there I attempted to do this by calling the controls <em>Focus()</em> method and when that didn&#8217;t have the desired results I tried <strong>Keyboard</strong><em>.Focus()</em> and passed it the <strong>DatePicker</strong>. This also didn&#8217;t accomplish what I was looking for.</p>
<p>In the above cases the <strong>DatePicker</strong> would indeed gain focus, however you could not immediately begin typing in a date. If you pressed a navigational key on the keyboard such as <em>Tab</em> or any of the directional arrows it would then put the keyboard focus into the <strong>TextBox</strong> portion of the control and highlight any existing text. </p>
<p><div id="attachment_499" class="wp-caption aligncenter" style="width: 125px"><img src="http://mel-green.com/wp-content/uploads/2011/02/datepicker.png" alt="DatePicker without focus on text" title="Focus, but not on text..." width="115" height="25" class="size-full wp-image-499" /><p class="wp-caption-text">Focus, but not on text...</p></div><br />
<br />
<div id="attachment_504" class="wp-caption aligncenter" style="width: 124px"><img src="http://mel-green.com/wp-content/uploads/2011/02/datepicker_selected.png" alt="DatePicker with focus on text" title="Focus on text!" width="114" height="26" class="size-full wp-image-504" /><p class="wp-caption-text">Focus on text!</p></div><br />
</p>
<p>Since this is exactly the end result I was after I set about automating this in code and arrived at the following solution. Basically all I&#8217;m doing is simulating the <em>Up Arrow</em> being pressed on the <strong>DatePicker</strong> control, this causes the control to move focus to the internal <strong>TextBox</strong>. It&#8217;s very hacky but it&#8217;s the best thing I could come up with without inheriting from DatePicker which I&#8217;d like to avoid. I wrapped the code up in a nice extension method for ease of use, and that&#8217;s what you see below.<br />
</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Windows.Controls</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Windows.Input</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">namespace</span> CGS
<span style="color: #008000;">&#123;</span>
    <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">class</span> DatePickerExtensions
    <span style="color: #008000;">&#123;</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">void</span> FocusOnText<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span> DatePicker datePicker<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            Keyboard<span style="color: #008000;">.</span><span style="color: #0000FF;">Focus</span><span style="color: #008000;">&#40;</span>datePicker<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            var eventArgs <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> KeyEventArgs<span style="color: #008000;">&#40;</span>Keyboard<span style="color: #008000;">.</span><span style="color: #0000FF;">PrimaryDevice</span>,
                                             Keyboard<span style="color: #008000;">.</span><span style="color: #0000FF;">PrimaryDevice</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ActiveSource</span>,
                                             <span style="color: #FF0000;">0</span>,
                                             Key<span style="color: #008000;">.</span><span style="color: #0000FF;">Up</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            eventArgs<span style="color: #008000;">.</span><span style="color: #0000FF;">RoutedEvent</span> <span style="color: #008000;">=</span> DatePicker<span style="color: #008000;">.</span><span style="color: #0000FF;">KeyDownEvent</span><span style="color: #008000;">;</span>
&nbsp;
            datePicker<span style="color: #008000;">.</span><span style="color: #0000FF;">RaiseEvent</span><span style="color: #008000;">&#40;</span>eventArgs<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>If anyone knows of a cleaner, more legitimate way to accomplish this please let me know! As always questions and comments are welcome and appreciated.</p>
]]></content:encoded>
			<wfw:commentRss>http://mel-green.com/2011/02/wpf-focus-datepicker-on-text-in-textbox/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Call of Duty: Black Ops Multiple Profiles</title>
		<link>http://mel-green.com/2010/11/call-of-duty-black-ops-multiple-profiles/</link>
		<comments>http://mel-green.com/2010/11/call-of-duty-black-ops-multiple-profiles/#comments</comments>
		<pubDate>Sat, 13 Nov 2010 03:55:35 +0000</pubDate>
		<dc:creator>Mel</dc:creator>
				<category><![CDATA[Computers]]></category>
		<category><![CDATA[Games]]></category>
		<category><![CDATA[Black Ops]]></category>
		<category><![CDATA[Call of Duty]]></category>
		<category><![CDATA[Loader]]></category>
		<category><![CDATA[Multiple Profiles]]></category>

		<guid isPermaLink="false">http://mel-green.com/?p=487</guid>
		<description><![CDATA[I created this launcher to provide multiple profiles for the single player game of Call of Duty: Black Ops. This is similar to the loader I wrote for Modern Warfare 2 which you can find here. As there are multiple ways to acquire this game and install it, this may not work for everyone. Instructions: [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://mel-green.com/wp-content/uploads/2010/11/bo_launcher.png" alt="Black Ops Multiple Profiles Launcher" title="Black Ops Multiple Profiles Launcher" width="491" height="310" class="aligncenter size-full wp-image-493" /></p>
<p>I created this launcher to provide multiple profiles for the single player game of <em>Call of Duty: Black Ops</em>. This is similar to the loader I wrote for Modern Warfare 2 which you can find <a href="http://mel-green.com/2009/11/modern-warfare-2-multiple-profiles-loader/" target="_blank">here</a>. As there are multiple ways to acquire this game and install it, this may not work for everyone.</p>
<p><strong>Instructions:</strong></p>
<ol>
<li>Download the zip file <a href="http://mel-green.com/Uploads/BlackOps_Multiple_Profiles_Loader.zip">here</a></li>
<li>Extract the contents to the install directory for <em>Black Ops</em></li>
<li>Create a shortcut on your desktop for <em>Black Ops Loader.exe</em> and use it instead of launching the game directly.</li>
<li>When you click &#8220;Launch&#8221; and you&#8217;re asked to select a program or shortcut to run, navigate to the shortcut you would normally use to launch the single player game and select it. This will ensure that the game is run through Steam.</li>
<li>If for some reason you need to re-select a program or shortcut to run, you can do this by resetting the Loader. To do this you need to delete the <em>profiles.xml</em> file located in:<br /> <strong>(XP)</strong> <em>C:\Documents and Settings\All Users\Application Data\BO_Loader\</em> <br /> <strong>(Vista)</strong> <em>C:\Program Data\BO_Loader\</em> <br /> <strong>(Win7)</strong> <em>C:\ProgramData\BO_Loader\</em></li>
<li>If you don&#8217;t already have the Microsoft .Net Framework 3.5 installed on your system, you will need to download it <a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=333325FD-AE52-4E35-B531-508D977D32A6&amp;displaylang=en">here</a></li>
</ol>
<p>Here&#8217;s a picture of what the game directory should look like after you&#8217;ve extracted the file:<br />
<img src="http://mel-green.com/wp-content/uploads/2010/11/bo_dir.png" alt="Black Ops Install Directory" title="Black Ops Install Directory" width="493" height="641" class="aligncenter size-full wp-image-490" /></p>
<p>Note: This only works for the PC version of the game and as far as I know only changes your Single Player profile, which includes all game settings and saved games.</p>
<p>If you have any questions or comments please feel free to post them below. Feedback and praise is always welcome!</p>
]]></content:encoded>
			<wfw:commentRss>http://mel-green.com/2010/11/call-of-duty-black-ops-multiple-profiles/feed/</wfw:commentRss>
		<slash:comments>30</slash:comments>
		</item>
		<item>
		<title>C#: Refresh Windows Desktop and Explorer</title>
		<link>http://mel-green.com/2010/09/c-refresh-windows-desktop-and-explorer/</link>
		<comments>http://mel-green.com/2010/09/c-refresh-windows-desktop-and-explorer/#comments</comments>
		<pubDate>Thu, 02 Sep 2010 22:54:13 +0000</pubDate>
		<dc:creator>Mel</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Explorer]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[Windows 7]]></category>

		<guid isPermaLink="false">http://mel-green.com/?p=483</guid>
		<description><![CDATA[This post is mostly for my own reference since the following code is actually found elsewhere online and is not my original work. However the code to both refresh the desktop and any open explorer windows is generally found in parts, so here I&#8217;ve combined it for convenience sake. &#91;System.Runtime.InteropServices.DllImport&#40;&#34;Shell32.dll&#34;&#41;&#93; private static extern int SHChangeNotify&#40;int [...]]]></description>
			<content:encoded><![CDATA[<p>This post is mostly for my own reference since the following code is actually found elsewhere online and is not my original work. However the code to both refresh the desktop and any open explorer windows is generally found in parts, so here I&#8217;ve combined it for convenience sake.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008000;">&#91;</span><span style="color: #000000;">System.<span style="color: #0000FF;">Runtime</span><span style="color: #008000;">.</span><span style="color: #0000FF;">InteropServices</span></span><span style="color: #008000;">.</span><span style="color: #0000FF;">DllImport</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Shell32.dll&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span>
<span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #0600FF; font-weight: bold;">extern</span> <span style="color: #6666cc; font-weight: bold;">int</span> SHChangeNotify<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span> eventId, <span style="color: #6666cc; font-weight: bold;">int</span> flags, IntPtr item1, IntPtr item2<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">void</span> RefreshWindowsExplorer<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    <span style="color: #008080; font-style: italic;">// Refresh the desktop</span>
    SHChangeNotify<span style="color: #008000;">&#40;</span>0x8000000, 0x1000, IntPtr<span style="color: #008000;">.</span><span style="color: #0000FF;">Zero</span>, IntPtr<span style="color: #008000;">.</span><span style="color: #0000FF;">Zero</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #008080; font-style: italic;">// Refresh any open explorer windows</span>
    <span style="color: #008080; font-style: italic;">// based on http://stackoverflow.com/questions/2488727/refresh-windows-explorer-in-win7</span>
    Guid CLSID_ShellApplication <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Guid<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;13709620-C279-11CE-A49E-444553540000&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    Type shellApplicationType <span style="color: #008000;">=</span> Type<span style="color: #008000;">.</span><span style="color: #0000FF;">GetTypeFromCLSID</span><span style="color: #008000;">&#40;</span>CLSID_ShellApplication, <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #6666cc; font-weight: bold;">object</span> shellApplication <span style="color: #008000;">=</span> Activator<span style="color: #008000;">.</span><span style="color: #0000FF;">CreateInstance</span><span style="color: #008000;">&#40;</span>shellApplicationType<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #6666cc; font-weight: bold;">object</span> windows <span style="color: #008000;">=</span> shellApplicationType<span style="color: #008000;">.</span><span style="color: #0000FF;">InvokeMember</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Windows&quot;</span>, <span style="color: #000000;">System.<span style="color: #0000FF;">Reflection</span></span><span style="color: #008000;">.</span><span style="color: #0000FF;">BindingFlags</span><span style="color: #008000;">.</span><span style="color: #0000FF;">InvokeMethod</span>, <span style="color: #0600FF; font-weight: bold;">null</span>, shellApplication, <span style="color: #008000;">new</span> <span style="color: #6666cc; font-weight: bold;">object</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> <span style="color: #008000;">&#123;</span> <span style="color: #008000;">&#125;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    Type windowsType <span style="color: #008000;">=</span> windows<span style="color: #008000;">.</span><span style="color: #0000FF;">GetType</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #6666cc; font-weight: bold;">object</span> count <span style="color: #008000;">=</span> windowsType<span style="color: #008000;">.</span><span style="color: #0000FF;">InvokeMember</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Count&quot;</span>, <span style="color: #000000;">System.<span style="color: #0000FF;">Reflection</span></span><span style="color: #008000;">.</span><span style="color: #0000FF;">BindingFlags</span><span style="color: #008000;">.</span><span style="color: #0000FF;">GetProperty</span>, <span style="color: #0600FF; font-weight: bold;">null</span>, windows, <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #0600FF; font-weight: bold;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span> i <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span> i <span style="color: #008000;">&lt;</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#41;</span>count<span style="color: #008000;">;</span> i<span style="color: #008000;">++</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        <span style="color: #6666cc; font-weight: bold;">object</span> item <span style="color: #008000;">=</span> windowsType<span style="color: #008000;">.</span><span style="color: #0000FF;">InvokeMember</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Item&quot;</span>, <span style="color: #000000;">System.<span style="color: #0000FF;">Reflection</span></span><span style="color: #008000;">.</span><span style="color: #0000FF;">BindingFlags</span><span style="color: #008000;">.</span><span style="color: #0000FF;">InvokeMethod</span>, <span style="color: #0600FF; font-weight: bold;">null</span>, windows, <span style="color: #008000;">new</span> <span style="color: #6666cc; font-weight: bold;">object</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> <span style="color: #008000;">&#123;</span> i <span style="color: #008000;">&#125;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        Type itemType <span style="color: #008000;">=</span> item<span style="color: #008000;">.</span><span style="color: #0000FF;">GetType</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">// Only refresh Windows Explorer, without checking for the name this could refresh open IE windows</span>
        <span style="color: #6666cc; font-weight: bold;">string</span> itemName <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&#41;</span>itemType<span style="color: #008000;">.</span><span style="color: #0000FF;">InvokeMember</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Name&quot;</span>, <span style="color: #000000;">System.<span style="color: #0000FF;">Reflection</span></span><span style="color: #008000;">.</span><span style="color: #0000FF;">BindingFlags</span><span style="color: #008000;">.</span><span style="color: #0000FF;">GetProperty</span>, <span style="color: #0600FF; font-weight: bold;">null</span>, item, <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>itemName <span style="color: #008000;">==</span> <span style="color: #666666;">&quot;Windows Explorer&quot;</span><span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            itemType<span style="color: #008000;">.</span><span style="color: #0000FF;">InvokeMember</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Refresh&quot;</span>, <span style="color: #000000;">System.<span style="color: #0000FF;">Reflection</span></span><span style="color: #008000;">.</span><span style="color: #0000FF;">BindingFlags</span><span style="color: #008000;">.</span><span style="color: #0000FF;">InvokeMethod</span>, <span style="color: #0600FF; font-weight: bold;">null</span>, item, <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://mel-green.com/2010/09/c-refresh-windows-desktop-and-explorer/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>OfficeToXps: Convert Word, Excel, and PowerPoint to XPS</title>
		<link>http://mel-green.com/2010/05/officetoxps-convert-word-excel-and-powerpoint-to-xps/</link>
		<comments>http://mel-green.com/2010/05/officetoxps-convert-word-excel-and-powerpoint-to-xps/#comments</comments>
		<pubDate>Tue, 11 May 2010 22:59:58 +0000</pubDate>
		<dc:creator>Mel</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Microsoft Office]]></category>
		<category><![CDATA[XPS]]></category>

		<guid isPermaLink="false">http://mel-green.com/?p=470</guid>
		<description><![CDATA[I recently had the need to convert Word, Excel, and PowerPoint files to Microsoft&#8217;s XPS format for easy displaying in WPF. There&#8217;s a plethora of articles, threads, and questions out there that illustrate how to do this, but I haven&#8217;t seen anyone compile a single class/library that will convert from all three applications with good [...]]]></description>
			<content:encoded><![CDATA[<p>I recently had the need to convert Word, Excel, and PowerPoint files to Microsoft&#8217;s XPS format for easy displaying in WPF. There&#8217;s a plethora of articles, threads, and questions out there that illustrate how to do this, but I haven&#8217;t seen anyone compile a single class/library that will convert from all three applications with good error handling and no price tag.</p>
<p>So I figured since I had to write it anyway I&#8217;d post it here for the aid of anyone else looking to do the same thing. As always comments/questions/praise are appreciated.</p>
<p><a href="http://mel-green.com/Uploads/OfficeToXps.cs">Download Code File</a></p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Collections.Generic</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.IO</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">Excel </span><span style="color: #008000;">=</span> Microsoft<span style="color: #008000;">.</span><span style="color: #0000FF;">Office</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Interop</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Excel</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">PowerPoint </span><span style="color: #008000;">=</span> Microsoft<span style="color: #008000;">.</span><span style="color: #0000FF;">Office</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Interop</span><span style="color: #008000;">.</span><span style="color: #0000FF;">PowerPoint</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">Word </span><span style="color: #008000;">=</span> Microsoft<span style="color: #008000;">.</span><span style="color: #0000FF;">Office</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Interop</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Word</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">namespace</span> CGS
<span style="color: #008000;">&#123;</span>
    <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> OfficeToXps
    <span style="color: #008000;">&#123;</span>
        <span style="color: #008080;">#region Properties &amp; Constants</span>
        <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> List<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&gt;</span> wordExtensions <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> List<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&gt;</span>
        <span style="color: #008000;">&#123;</span>
            <span style="color: #666666;">&quot;.doc&quot;</span>,
            <span style="color: #666666;">&quot;.docx&quot;</span>
        <span style="color: #008000;">&#125;</span><span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> List<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&gt;</span> excelExtensions <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> List<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&gt;</span>
        <span style="color: #008000;">&#123;</span>
            <span style="color: #666666;">&quot;.xls&quot;</span>,
            <span style="color: #666666;">&quot;.xlsx&quot;</span>
        <span style="color: #008000;">&#125;</span><span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> List<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&gt;</span> powerpointExtensions <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> List<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&gt;</span>
        <span style="color: #008000;">&#123;</span>
            <span style="color: #666666;">&quot;.ppt&quot;</span>,
            <span style="color: #666666;">&quot;.pptx&quot;</span>
        <span style="color: #008000;">&#125;</span><span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #008080;">#endregion</span>
&nbsp;
        <span style="color: #008080;">#region Public Methods</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> OfficeToXpsConversionResult ConvertToXps<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span> sourceFilePath, <span style="color: #0600FF; font-weight: bold;">ref</span> <span style="color: #6666cc; font-weight: bold;">string</span> resultFilePath<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            var result <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> OfficeToXpsConversionResult<span style="color: #008000;">&#40;</span>ConversionResult<span style="color: #008000;">.</span><span style="color: #0000FF;">UnexpectedError</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">// Check to see if it's a valid file</span>
            <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">!</span>IsValidFilePath<span style="color: #008000;">&#40;</span>sourceFilePath<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
                result<span style="color: #008000;">.</span><span style="color: #0000FF;">Result</span> <span style="color: #008000;">=</span> ConversionResult<span style="color: #008000;">.</span><span style="color: #0000FF;">InvalidFilePath</span><span style="color: #008000;">;</span>
                result<span style="color: #008000;">.</span><span style="color: #0000FF;">ResultText</span> <span style="color: #008000;">=</span> sourceFilePath<span style="color: #008000;">;</span>
                <span style="color: #0600FF; font-weight: bold;">return</span> result<span style="color: #008000;">;</span>
            <span style="color: #008000;">&#125;</span>
&nbsp;
&nbsp;
&nbsp;
            var ext <span style="color: #008000;">=</span> Path<span style="color: #008000;">.</span><span style="color: #0000FF;">GetExtension</span><span style="color: #008000;">&#40;</span>sourceFilePath<span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ToLower</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">// Check to see if it's in our list of convertable extensions</span>
            <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">!</span>IsConvertableFilePath<span style="color: #008000;">&#40;</span>sourceFilePath<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
                result<span style="color: #008000;">.</span><span style="color: #0000FF;">Result</span> <span style="color: #008000;">=</span> ConversionResult<span style="color: #008000;">.</span><span style="color: #0000FF;">InvalidFileExtension</span><span style="color: #008000;">;</span>
                result<span style="color: #008000;">.</span><span style="color: #0000FF;">ResultText</span> <span style="color: #008000;">=</span> ext<span style="color: #008000;">;</span>
                <span style="color: #0600FF; font-weight: bold;">return</span> result<span style="color: #008000;">;</span>
            <span style="color: #008000;">&#125;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">// Convert if Word</span>
            <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>wordExtensions<span style="color: #008000;">.</span><span style="color: #0000FF;">Contains</span><span style="color: #008000;">&#40;</span>ext<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
                <span style="color: #0600FF; font-weight: bold;">return</span> ConvertFromWord<span style="color: #008000;">&#40;</span>sourceFilePath, <span style="color: #0600FF; font-weight: bold;">ref</span> resultFilePath<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #008000;">&#125;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">// Convert if Excel</span>
            <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>excelExtensions<span style="color: #008000;">.</span><span style="color: #0000FF;">Contains</span><span style="color: #008000;">&#40;</span>ext<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
                <span style="color: #0600FF; font-weight: bold;">return</span> ConvertFromExcel<span style="color: #008000;">&#40;</span>sourceFilePath, <span style="color: #0600FF; font-weight: bold;">ref</span> resultFilePath<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #008000;">&#125;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">// Convert if PowerPoint</span>
            <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>powerpointExtensions<span style="color: #008000;">.</span><span style="color: #0000FF;">Contains</span><span style="color: #008000;">&#40;</span>ext<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
                <span style="color: #0600FF; font-weight: bold;">return</span> ConvertFromPowerPoint<span style="color: #008000;">&#40;</span>sourceFilePath, <span style="color: #0600FF; font-weight: bold;">ref</span> resultFilePath<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #008000;">&#125;</span>
&nbsp;
            <span style="color: #0600FF; font-weight: bold;">return</span> result<span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
        <span style="color: #008080;">#endregion</span>
&nbsp;
        <span style="color: #008080;">#region Private Methods</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">bool</span> IsValidFilePath<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span> sourceFilePath<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">.</span><span style="color: #0000FF;">IsNullOrEmpty</span><span style="color: #008000;">&#40;</span>sourceFilePath<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
                <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #0600FF; font-weight: bold;">try</span>
            <span style="color: #008000;">&#123;</span>
                <span style="color: #0600FF; font-weight: bold;">return</span> File<span style="color: #008000;">.</span><span style="color: #0000FF;">Exists</span><span style="color: #008000;">&#40;</span>sourceFilePath<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #008000;">&#125;</span>
            <span style="color: #0600FF; font-weight: bold;">catch</span> <span style="color: #008000;">&#40;</span>Exception<span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
            <span style="color: #008000;">&#125;</span>
&nbsp;
            <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">bool</span> IsConvertableFilePath<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span> sourceFilePath<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            var ext <span style="color: #008000;">=</span> Path<span style="color: #008000;">.</span><span style="color: #0000FF;">GetExtension</span><span style="color: #008000;">&#40;</span>sourceFilePath<span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ToLower</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #0600FF; font-weight: bold;">return</span> IsConvertableExtension<span style="color: #008000;">&#40;</span>ext<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">bool</span> IsConvertableExtension<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span> extension<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            <span style="color: #0600FF; font-weight: bold;">return</span> wordExtensions<span style="color: #008000;">.</span><span style="color: #0000FF;">Contains</span><span style="color: #008000;">&#40;</span>extension<span style="color: #008000;">&#41;</span> <span style="color: #008000;">||</span>
                   excelExtensions<span style="color: #008000;">.</span><span style="color: #0000FF;">Contains</span><span style="color: #008000;">&#40;</span>extension<span style="color: #008000;">&#41;</span> <span style="color: #008000;">||</span>
                   powerpointExtensions<span style="color: #008000;">.</span><span style="color: #0000FF;">Contains</span><span style="color: #008000;">&#40;</span>extension<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">string</span> GetTempXpsFilePath<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            <span style="color: #0600FF; font-weight: bold;">return</span> Path<span style="color: #008000;">.</span><span style="color: #0000FF;">ChangeExtension</span><span style="color: #008000;">&#40;</span>Path<span style="color: #008000;">.</span><span style="color: #0000FF;">GetTempFileName</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>, <span style="color: #666666;">&quot;.xps&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> OfficeToXpsConversionResult ConvertFromWord<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span> sourceFilePath, <span style="color: #0600FF; font-weight: bold;">ref</span> <span style="color: #6666cc; font-weight: bold;">string</span> resultFilePath<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            <span style="color: #6666cc; font-weight: bold;">object</span> pSourceDocPath <span style="color: #008000;">=</span> sourceFilePath<span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #6666cc; font-weight: bold;">string</span> pExportFilePath <span style="color: #008000;">=</span> <span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">.</span><span style="color: #0000FF;">IsNullOrWhiteSpace</span><span style="color: #008000;">&#40;</span>resultFilePath<span style="color: #008000;">&#41;</span> <span style="color: #008000;">?</span> GetTempXpsFilePath<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">:</span> resultFilePath<span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #0600FF; font-weight: bold;">try</span>
            <span style="color: #008000;">&#123;</span>
                var pExportFormat <span style="color: #008000;">=</span> Word<span style="color: #008000;">.</span><span style="color: #0000FF;">WdExportFormat</span><span style="color: #008000;">.</span><span style="color: #0000FF;">wdExportFormatXPS</span><span style="color: #008000;">;</span>
                <span style="color: #6666cc; font-weight: bold;">bool</span> pOpenAfterExport <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">;</span>
                var pExportOptimizeFor <span style="color: #008000;">=</span> Word<span style="color: #008000;">.</span><span style="color: #0000FF;">WdExportOptimizeFor</span><span style="color: #008000;">.</span><span style="color: #0000FF;">wdExportOptimizeForOnScreen</span><span style="color: #008000;">;</span>
                var pExportRange <span style="color: #008000;">=</span> Word<span style="color: #008000;">.</span><span style="color: #0000FF;">WdExportRange</span><span style="color: #008000;">.</span><span style="color: #0000FF;">wdExportAllDocument</span><span style="color: #008000;">;</span>
                <span style="color: #6666cc; font-weight: bold;">int</span> pStartPage <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span>
                <span style="color: #6666cc; font-weight: bold;">int</span> pEndPage <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span>
                var pExportItem <span style="color: #008000;">=</span> Word<span style="color: #008000;">.</span><span style="color: #0000FF;">WdExportItem</span><span style="color: #008000;">.</span><span style="color: #0000FF;">wdExportDocumentContent</span><span style="color: #008000;">;</span>
                var pIncludeDocProps <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span>
                var pKeepIRM <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span>
                var pCreateBookmarks <span style="color: #008000;">=</span> Word<span style="color: #008000;">.</span><span style="color: #0000FF;">WdExportCreateBookmarks</span><span style="color: #008000;">.</span><span style="color: #0000FF;">wdExportCreateWordBookmarks</span><span style="color: #008000;">;</span>
                var pDocStructureTags <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span>
                var pBitmapMissingFonts <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span>
                var pUseISO19005_1 <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">;</span>
&nbsp;
&nbsp;
                Word<span style="color: #008000;">.</span><span style="color: #0000FF;">Application</span> wordApplication <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">;</span>
                Word<span style="color: #008000;">.</span><span style="color: #0000FF;">Document</span> wordDocument <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">;</span>
&nbsp;
                <span style="color: #0600FF; font-weight: bold;">try</span>
                <span style="color: #008000;">&#123;</span>
                    wordApplication <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Word<span style="color: #008000;">.</span><span style="color: #0000FF;">Application</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #008000;">&#125;</span>
                <span style="color: #0600FF; font-weight: bold;">catch</span> <span style="color: #008000;">&#40;</span>Exception exc<span style="color: #008000;">&#41;</span>
                <span style="color: #008000;">&#123;</span>
                    <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #008000;">new</span> OfficeToXpsConversionResult<span style="color: #008000;">&#40;</span>ConversionResult<span style="color: #008000;">.</span><span style="color: #0000FF;">ErrorUnableToInitializeOfficeApp</span>, <span style="color: #666666;">&quot;Word&quot;</span>, exc<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #008000;">&#125;</span>
&nbsp;
                <span style="color: #0600FF; font-weight: bold;">try</span>
                <span style="color: #008000;">&#123;</span>
                    <span style="color: #0600FF; font-weight: bold;">try</span>
                    <span style="color: #008000;">&#123;</span>
                        wordDocument <span style="color: #008000;">=</span> wordApplication<span style="color: #008000;">.</span><span style="color: #0000FF;">Documents</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Open</span><span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">ref</span> pSourceDocPath<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                    <span style="color: #008000;">&#125;</span>
                    <span style="color: #0600FF; font-weight: bold;">catch</span> <span style="color: #008000;">&#40;</span>Exception exc<span style="color: #008000;">&#41;</span>
                    <span style="color: #008000;">&#123;</span>
                        <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #008000;">new</span> OfficeToXpsConversionResult<span style="color: #008000;">&#40;</span>ConversionResult<span style="color: #008000;">.</span><span style="color: #0000FF;">ErrorUnableToOpenOfficeFile</span>, exc<span style="color: #008000;">.</span><span style="color: #0000FF;">Message</span>, exc<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                    <span style="color: #008000;">&#125;</span>
&nbsp;
                    <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>wordDocument <span style="color: #008000;">!=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span>
                    <span style="color: #008000;">&#123;</span>
                        <span style="color: #0600FF; font-weight: bold;">try</span>
                        <span style="color: #008000;">&#123;</span>
                            wordDocument<span style="color: #008000;">.</span><span style="color: #0000FF;">ExportAsFixedFormat</span><span style="color: #008000;">&#40;</span>
                                                pExportFilePath,
                                                pExportFormat,
                                                pOpenAfterExport,
                                                pExportOptimizeFor,
                                                pExportRange,
                                                pStartPage,
                                                pEndPage,
                                                pExportItem,
                                                pIncludeDocProps,
                                                pKeepIRM,
                                                pCreateBookmarks,
                                                pDocStructureTags,
                                                pBitmapMissingFonts,
                                                pUseISO19005_1
                                            <span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                        <span style="color: #008000;">&#125;</span>
                        <span style="color: #0600FF; font-weight: bold;">catch</span> <span style="color: #008000;">&#40;</span>Exception exc<span style="color: #008000;">&#41;</span>
                        <span style="color: #008000;">&#123;</span>
                            <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #008000;">new</span> OfficeToXpsConversionResult<span style="color: #008000;">&#40;</span>ConversionResult<span style="color: #008000;">.</span><span style="color: #0000FF;">ErrorUnableToExportToXps</span>, <span style="color: #666666;">&quot;Word&quot;</span>, exc<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                        <span style="color: #008000;">&#125;</span>
                    <span style="color: #008000;">&#125;</span>
                    <span style="color: #0600FF; font-weight: bold;">else</span>
                    <span style="color: #008000;">&#123;</span>
                        <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #008000;">new</span> OfficeToXpsConversionResult<span style="color: #008000;">&#40;</span>ConversionResult<span style="color: #008000;">.</span><span style="color: #0000FF;">ErrorUnableToOpenOfficeFile</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                    <span style="color: #008000;">&#125;</span>
                <span style="color: #008000;">&#125;</span>
                <span style="color: #0600FF; font-weight: bold;">finally</span>
                <span style="color: #008000;">&#123;</span>
                    <span style="color: #008080; font-style: italic;">// Close and release the Document object.</span>
                    <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>wordDocument <span style="color: #008000;">!=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span>
                    <span style="color: #008000;">&#123;</span>
                        wordDocument<span style="color: #008000;">.</span><span style="color: #0000FF;">Close</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                        wordDocument <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">;</span>
                    <span style="color: #008000;">&#125;</span>
&nbsp;
                    <span style="color: #008080; font-style: italic;">// Quit Word and release the ApplicationClass object.</span>
                    <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>wordApplication <span style="color: #008000;">!=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span>
                    <span style="color: #008000;">&#123;</span>
                        wordApplication<span style="color: #008000;">.</span><span style="color: #0000FF;">Quit</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                        wordApplication <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">;</span>
                    <span style="color: #008000;">&#125;</span>
&nbsp;
                    GC<span style="color: #008000;">.</span><span style="color: #0000FF;">Collect</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                    GC<span style="color: #008000;">.</span><span style="color: #0000FF;">WaitForPendingFinalizers</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                    GC<span style="color: #008000;">.</span><span style="color: #0000FF;">Collect</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                    GC<span style="color: #008000;">.</span><span style="color: #0000FF;">WaitForPendingFinalizers</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #008000;">&#125;</span>
            <span style="color: #008000;">&#125;</span>
            <span style="color: #0600FF; font-weight: bold;">catch</span> <span style="color: #008000;">&#40;</span>Exception exc<span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
                <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #008000;">new</span> OfficeToXpsConversionResult<span style="color: #008000;">&#40;</span>ConversionResult<span style="color: #008000;">.</span><span style="color: #0000FF;">ErrorUnableToAccessOfficeInterop</span>, <span style="color: #666666;">&quot;Word&quot;</span>, exc<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #008000;">&#125;</span>
&nbsp;
            resultFilePath <span style="color: #008000;">=</span> pExportFilePath<span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #008000;">new</span> OfficeToXpsConversionResult<span style="color: #008000;">&#40;</span>ConversionResult<span style="color: #008000;">.</span><span style="color: #0000FF;">OK</span>, pExportFilePath<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> OfficeToXpsConversionResult ConvertFromPowerPoint<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span> sourceFilePath, <span style="color: #0600FF; font-weight: bold;">ref</span> <span style="color: #6666cc; font-weight: bold;">string</span> resultFilePath<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            <span style="color: #6666cc; font-weight: bold;">string</span> pSourceDocPath <span style="color: #008000;">=</span> sourceFilePath<span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #6666cc; font-weight: bold;">string</span> pExportFilePath <span style="color: #008000;">=</span> <span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">.</span><span style="color: #0000FF;">IsNullOrWhiteSpace</span><span style="color: #008000;">&#40;</span>resultFilePath<span style="color: #008000;">&#41;</span> <span style="color: #008000;">?</span> GetTempXpsFilePath<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">:</span> resultFilePath<span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #0600FF; font-weight: bold;">try</span>
            <span style="color: #008000;">&#123;</span>
                PowerPoint<span style="color: #008000;">.</span><span style="color: #0000FF;">Application</span> pptApplication <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">;</span>
                PowerPoint<span style="color: #008000;">.</span><span style="color: #0000FF;">Presentation</span> pptPresentation <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">;</span>
&nbsp;
                <span style="color: #0600FF; font-weight: bold;">try</span>
                <span style="color: #008000;">&#123;</span>
                    pptApplication <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> PowerPoint<span style="color: #008000;">.</span><span style="color: #0000FF;">Application</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #008000;">&#125;</span>
                <span style="color: #0600FF; font-weight: bold;">catch</span> <span style="color: #008000;">&#40;</span>Exception exc<span style="color: #008000;">&#41;</span>
                <span style="color: #008000;">&#123;</span>
                    <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #008000;">new</span> OfficeToXpsConversionResult<span style="color: #008000;">&#40;</span>ConversionResult<span style="color: #008000;">.</span><span style="color: #0000FF;">ErrorUnableToInitializeOfficeApp</span>, <span style="color: #666666;">&quot;PowerPoint&quot;</span>, exc<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #008000;">&#125;</span>
&nbsp;
                <span style="color: #0600FF; font-weight: bold;">try</span>
                <span style="color: #008000;">&#123;</span>
                    <span style="color: #0600FF; font-weight: bold;">try</span>
                    <span style="color: #008000;">&#123;</span>
                        pptPresentation <span style="color: #008000;">=</span> pptApplication<span style="color: #008000;">.</span><span style="color: #0000FF;">Presentations</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Open</span><span style="color: #008000;">&#40;</span>pSourceDocPath,
                                                                            Microsoft<span style="color: #008000;">.</span><span style="color: #0000FF;">Office</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Core</span><span style="color: #008000;">.</span><span style="color: #0000FF;">MsoTriState</span><span style="color: #008000;">.</span><span style="color: #0000FF;">msoTrue</span>,
                                                                            Microsoft<span style="color: #008000;">.</span><span style="color: #0000FF;">Office</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Core</span><span style="color: #008000;">.</span><span style="color: #0000FF;">MsoTriState</span><span style="color: #008000;">.</span><span style="color: #0000FF;">msoTrue</span>,
                                                                            Microsoft<span style="color: #008000;">.</span><span style="color: #0000FF;">Office</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Core</span><span style="color: #008000;">.</span><span style="color: #0000FF;">MsoTriState</span><span style="color: #008000;">.</span><span style="color: #0000FF;">msoFalse</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                    <span style="color: #008000;">&#125;</span>
                    <span style="color: #0600FF; font-weight: bold;">catch</span> <span style="color: #008000;">&#40;</span>Exception exc<span style="color: #008000;">&#41;</span>
                    <span style="color: #008000;">&#123;</span>
                        <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #008000;">new</span> OfficeToXpsConversionResult<span style="color: #008000;">&#40;</span>ConversionResult<span style="color: #008000;">.</span><span style="color: #0000FF;">ErrorUnableToOpenOfficeFile</span>, exc<span style="color: #008000;">.</span><span style="color: #0000FF;">Message</span>, exc<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                    <span style="color: #008000;">&#125;</span>
&nbsp;
                    <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>pptPresentation <span style="color: #008000;">!=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span>
                    <span style="color: #008000;">&#123;</span>
                        <span style="color: #0600FF; font-weight: bold;">try</span>
                        <span style="color: #008000;">&#123;</span>
                            pptPresentation<span style="color: #008000;">.</span><span style="color: #0000FF;">ExportAsFixedFormat</span><span style="color: #008000;">&#40;</span>
                                                pExportFilePath,
                                                PowerPoint<span style="color: #008000;">.</span><span style="color: #0000FF;">PpFixedFormatType</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ppFixedFormatTypeXPS</span>,
                                                PowerPoint<span style="color: #008000;">.</span><span style="color: #0000FF;">PpFixedFormatIntent</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ppFixedFormatIntentScreen</span>,
                                                Microsoft<span style="color: #008000;">.</span><span style="color: #0000FF;">Office</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Core</span><span style="color: #008000;">.</span><span style="color: #0000FF;">MsoTriState</span><span style="color: #008000;">.</span><span style="color: #0000FF;">msoFalse</span>,
                                                PowerPoint<span style="color: #008000;">.</span><span style="color: #0000FF;">PpPrintHandoutOrder</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ppPrintHandoutVerticalFirst</span>,
                                                PowerPoint<span style="color: #008000;">.</span><span style="color: #0000FF;">PpPrintOutputType</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ppPrintOutputSlides</span>,
                                                Microsoft<span style="color: #008000;">.</span><span style="color: #0000FF;">Office</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Core</span><span style="color: #008000;">.</span><span style="color: #0000FF;">MsoTriState</span><span style="color: #008000;">.</span><span style="color: #0000FF;">msoFalse</span>,
                                                <span style="color: #0600FF; font-weight: bold;">null</span>,
                                                PowerPoint<span style="color: #008000;">.</span><span style="color: #0000FF;">PpPrintRangeType</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ppPrintAll</span>,
                                                <span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Empty</span>,
                                                <span style="color: #0600FF; font-weight: bold;">true</span>,
                                                <span style="color: #0600FF; font-weight: bold;">true</span>,
                                                <span style="color: #0600FF; font-weight: bold;">true</span>,
                                                <span style="color: #0600FF; font-weight: bold;">true</span>,
                                                <span style="color: #0600FF; font-weight: bold;">false</span>
                                            <span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                        <span style="color: #008000;">&#125;</span>
                        <span style="color: #0600FF; font-weight: bold;">catch</span> <span style="color: #008000;">&#40;</span>Exception exc<span style="color: #008000;">&#41;</span>
                        <span style="color: #008000;">&#123;</span>
                            <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #008000;">new</span> OfficeToXpsConversionResult<span style="color: #008000;">&#40;</span>ConversionResult<span style="color: #008000;">.</span><span style="color: #0000FF;">ErrorUnableToExportToXps</span>, <span style="color: #666666;">&quot;PowerPoint&quot;</span>, exc<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                        <span style="color: #008000;">&#125;</span>
                    <span style="color: #008000;">&#125;</span>
                    <span style="color: #0600FF; font-weight: bold;">else</span>
                    <span style="color: #008000;">&#123;</span>
                        <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #008000;">new</span> OfficeToXpsConversionResult<span style="color: #008000;">&#40;</span>ConversionResult<span style="color: #008000;">.</span><span style="color: #0000FF;">ErrorUnableToOpenOfficeFile</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                    <span style="color: #008000;">&#125;</span>
                <span style="color: #008000;">&#125;</span>
                <span style="color: #0600FF; font-weight: bold;">finally</span>
                <span style="color: #008000;">&#123;</span>
                    <span style="color: #008080; font-style: italic;">// Close and release the Document object.</span>
                    <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>pptPresentation <span style="color: #008000;">!=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span>
                    <span style="color: #008000;">&#123;</span>
                        pptPresentation<span style="color: #008000;">.</span><span style="color: #0000FF;">Close</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                        pptPresentation <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">;</span>
                    <span style="color: #008000;">&#125;</span>
&nbsp;
                    <span style="color: #008080; font-style: italic;">// Quit Word and release the ApplicationClass object.</span>
                    <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>pptApplication <span style="color: #008000;">!=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span>
                    <span style="color: #008000;">&#123;</span>
                        pptApplication<span style="color: #008000;">.</span><span style="color: #0000FF;">Quit</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                        pptApplication <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">;</span>
                    <span style="color: #008000;">&#125;</span>
&nbsp;
                    GC<span style="color: #008000;">.</span><span style="color: #0000FF;">Collect</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                    GC<span style="color: #008000;">.</span><span style="color: #0000FF;">WaitForPendingFinalizers</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                    GC<span style="color: #008000;">.</span><span style="color: #0000FF;">Collect</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                    GC<span style="color: #008000;">.</span><span style="color: #0000FF;">WaitForPendingFinalizers</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #008000;">&#125;</span>
            <span style="color: #008000;">&#125;</span>
            <span style="color: #0600FF; font-weight: bold;">catch</span> <span style="color: #008000;">&#40;</span>Exception exc<span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
                <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #008000;">new</span> OfficeToXpsConversionResult<span style="color: #008000;">&#40;</span>ConversionResult<span style="color: #008000;">.</span><span style="color: #0000FF;">ErrorUnableToAccessOfficeInterop</span>, <span style="color: #666666;">&quot;PowerPoint&quot;</span>, exc<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #008000;">&#125;</span>
&nbsp;
            resultFilePath <span style="color: #008000;">=</span> pExportFilePath<span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #008000;">new</span> OfficeToXpsConversionResult<span style="color: #008000;">&#40;</span>ConversionResult<span style="color: #008000;">.</span><span style="color: #0000FF;">OK</span>, pExportFilePath<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> OfficeToXpsConversionResult ConvertFromExcel<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span> sourceFilePath, <span style="color: #0600FF; font-weight: bold;">ref</span> <span style="color: #6666cc; font-weight: bold;">string</span> resultFilePath<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            <span style="color: #6666cc; font-weight: bold;">string</span> pSourceDocPath <span style="color: #008000;">=</span> sourceFilePath<span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #6666cc; font-weight: bold;">string</span> pExportFilePath <span style="color: #008000;">=</span> <span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">.</span><span style="color: #0000FF;">IsNullOrWhiteSpace</span><span style="color: #008000;">&#40;</span>resultFilePath<span style="color: #008000;">&#41;</span> <span style="color: #008000;">?</span> GetTempXpsFilePath<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">:</span> resultFilePath<span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #0600FF; font-weight: bold;">try</span>
            <span style="color: #008000;">&#123;</span>
                var pExportFormat <span style="color: #008000;">=</span> Excel<span style="color: #008000;">.</span><span style="color: #0000FF;">XlFixedFormatType</span><span style="color: #008000;">.</span><span style="color: #0000FF;">xlTypeXPS</span><span style="color: #008000;">;</span>
                var pExportQuality <span style="color: #008000;">=</span> Excel<span style="color: #008000;">.</span><span style="color: #0000FF;">XlFixedFormatQuality</span><span style="color: #008000;">.</span><span style="color: #0000FF;">xlQualityStandard</span><span style="color: #008000;">;</span>
                var pOpenAfterPublish <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">;</span>
                var pIncludeDocProps <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span>
                var pIgnorePrintAreas <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span>
&nbsp;
&nbsp;
                Excel<span style="color: #008000;">.</span><span style="color: #0000FF;">Application</span> excelApplication <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">;</span>
                Excel<span style="color: #008000;">.</span><span style="color: #0000FF;">Workbook</span> excelWorkbook <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">;</span>
&nbsp;
                <span style="color: #0600FF; font-weight: bold;">try</span>
                <span style="color: #008000;">&#123;</span>
                    excelApplication <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Excel<span style="color: #008000;">.</span><span style="color: #0000FF;">Application</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #008000;">&#125;</span>
                <span style="color: #0600FF; font-weight: bold;">catch</span> <span style="color: #008000;">&#40;</span>Exception exc<span style="color: #008000;">&#41;</span>
                <span style="color: #008000;">&#123;</span>
                    <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #008000;">new</span> OfficeToXpsConversionResult<span style="color: #008000;">&#40;</span>ConversionResult<span style="color: #008000;">.</span><span style="color: #0000FF;">ErrorUnableToInitializeOfficeApp</span>, <span style="color: #666666;">&quot;Excel&quot;</span>, exc<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #008000;">&#125;</span>
&nbsp;
                <span style="color: #0600FF; font-weight: bold;">try</span>
                <span style="color: #008000;">&#123;</span>
                    <span style="color: #0600FF; font-weight: bold;">try</span>
                    <span style="color: #008000;">&#123;</span>
                        excelWorkbook <span style="color: #008000;">=</span> excelApplication<span style="color: #008000;">.</span><span style="color: #0000FF;">Workbooks</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Open</span><span style="color: #008000;">&#40;</span>pSourceDocPath<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                    <span style="color: #008000;">&#125;</span>
                    <span style="color: #0600FF; font-weight: bold;">catch</span> <span style="color: #008000;">&#40;</span>Exception exc<span style="color: #008000;">&#41;</span>
                    <span style="color: #008000;">&#123;</span>
                        <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #008000;">new</span> OfficeToXpsConversionResult<span style="color: #008000;">&#40;</span>ConversionResult<span style="color: #008000;">.</span><span style="color: #0000FF;">ErrorUnableToOpenOfficeFile</span>, exc<span style="color: #008000;">.</span><span style="color: #0000FF;">Message</span>, exc<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                    <span style="color: #008000;">&#125;</span>
&nbsp;
                    <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>excelWorkbook <span style="color: #008000;">!=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span>
                    <span style="color: #008000;">&#123;</span>
                        <span style="color: #0600FF; font-weight: bold;">try</span>
                        <span style="color: #008000;">&#123;</span>
                            excelWorkbook<span style="color: #008000;">.</span><span style="color: #0000FF;">ExportAsFixedFormat</span><span style="color: #008000;">&#40;</span>
                                                pExportFormat,
                                                pExportFilePath,
                                                pExportQuality,
                                                pIncludeDocProps,
                                                pIgnorePrintAreas,
&nbsp;
                                                OpenAfterPublish <span style="color: #008000;">:</span> pOpenAfterPublish
                                            <span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                        <span style="color: #008000;">&#125;</span>
                        <span style="color: #0600FF; font-weight: bold;">catch</span> <span style="color: #008000;">&#40;</span>Exception exc<span style="color: #008000;">&#41;</span>
                        <span style="color: #008000;">&#123;</span>
                            <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #008000;">new</span> OfficeToXpsConversionResult<span style="color: #008000;">&#40;</span>ConversionResult<span style="color: #008000;">.</span><span style="color: #0000FF;">ErrorUnableToExportToXps</span>, <span style="color: #666666;">&quot;Excel&quot;</span>, exc<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                        <span style="color: #008000;">&#125;</span>
                    <span style="color: #008000;">&#125;</span>
                    <span style="color: #0600FF; font-weight: bold;">else</span>
                    <span style="color: #008000;">&#123;</span>
                        <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #008000;">new</span> OfficeToXpsConversionResult<span style="color: #008000;">&#40;</span>ConversionResult<span style="color: #008000;">.</span><span style="color: #0000FF;">ErrorUnableToOpenOfficeFile</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                    <span style="color: #008000;">&#125;</span>
                <span style="color: #008000;">&#125;</span>
                <span style="color: #0600FF; font-weight: bold;">finally</span>
                <span style="color: #008000;">&#123;</span>
                    <span style="color: #008080; font-style: italic;">// Close and release the Document object.</span>
                    <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>excelWorkbook <span style="color: #008000;">!=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span>
                    <span style="color: #008000;">&#123;</span>
                        excelWorkbook<span style="color: #008000;">.</span><span style="color: #0000FF;">Close</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                        excelWorkbook <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">;</span>
                    <span style="color: #008000;">&#125;</span>
&nbsp;
                    <span style="color: #008080; font-style: italic;">// Quit Word and release the ApplicationClass object.</span>
                    <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>excelApplication <span style="color: #008000;">!=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span>
                    <span style="color: #008000;">&#123;</span>
                        excelApplication<span style="color: #008000;">.</span><span style="color: #0000FF;">Quit</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                        excelApplication <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">;</span>
                    <span style="color: #008000;">&#125;</span>
&nbsp;
                    GC<span style="color: #008000;">.</span><span style="color: #0000FF;">Collect</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                    GC<span style="color: #008000;">.</span><span style="color: #0000FF;">WaitForPendingFinalizers</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                    GC<span style="color: #008000;">.</span><span style="color: #0000FF;">Collect</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                    GC<span style="color: #008000;">.</span><span style="color: #0000FF;">WaitForPendingFinalizers</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #008000;">&#125;</span>
            <span style="color: #008000;">&#125;</span>
            <span style="color: #0600FF; font-weight: bold;">catch</span> <span style="color: #008000;">&#40;</span>Exception exc<span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
                <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #008000;">new</span> OfficeToXpsConversionResult<span style="color: #008000;">&#40;</span>ConversionResult<span style="color: #008000;">.</span><span style="color: #0000FF;">ErrorUnableToAccessOfficeInterop</span>, <span style="color: #666666;">&quot;Excel&quot;</span>, exc<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #008000;">&#125;</span>
&nbsp;
            resultFilePath <span style="color: #008000;">=</span> pExportFilePath<span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #008000;">new</span> OfficeToXpsConversionResult<span style="color: #008000;">&#40;</span>ConversionResult<span style="color: #008000;">.</span><span style="color: #0000FF;">OK</span>, pExportFilePath<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
        <span style="color: #008080;">#endregion</span>
    <span style="color: #008000;">&#125;</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> OfficeToXpsConversionResult
    <span style="color: #008000;">&#123;</span>
        <span style="color: #008080;">#region Properties</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> ConversionResult Result <span style="color: #008000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">string</span> ResultText <span style="color: #008000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> Exception ResultError <span style="color: #008000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span> 
        <span style="color: #008080;">#endregion</span>
&nbsp;
        <span style="color: #008080;">#region Constructors</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> OfficeToXpsConversionResult<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            Result <span style="color: #008000;">=</span> ConversionResult<span style="color: #008000;">.</span><span style="color: #0000FF;">UnexpectedError</span><span style="color: #008000;">;</span>
            ResultText <span style="color: #008000;">=</span> <span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Empty</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> OfficeToXpsConversionResult<span style="color: #008000;">&#40;</span>ConversionResult result<span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">:</span> <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            Result <span style="color: #008000;">=</span> result<span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> OfficeToXpsConversionResult<span style="color: #008000;">&#40;</span>ConversionResult result, <span style="color: #6666cc; font-weight: bold;">string</span> resultText<span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">:</span> <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">&#40;</span>result<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            ResultText <span style="color: #008000;">=</span> resultText<span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> OfficeToXpsConversionResult<span style="color: #008000;">&#40;</span>ConversionResult result, <span style="color: #6666cc; font-weight: bold;">string</span> resultText, Exception exc<span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">:</span> <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">&#40;</span>result, resultText<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            ResultError <span style="color: #008000;">=</span> exc<span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span> 
        <span style="color: #008080;">#endregion</span>
    <span style="color: #008000;">&#125;</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">enum</span> ConversionResult
    <span style="color: #008000;">&#123;</span>
        OK <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span>,
        InvalidFilePath <span style="color: #008000;">=</span> <span style="color: #FF0000;">1</span>,
        InvalidFileExtension <span style="color: #008000;">=</span> <span style="color: #FF0000;">2</span>,
        UnexpectedError <span style="color: #008000;">=</span> <span style="color: #FF0000;">3</span>,
        ErrorUnableToInitializeOfficeApp <span style="color: #008000;">=</span> <span style="color: #FF0000;">4</span>,
        ErrorUnableToOpenOfficeFile <span style="color: #008000;">=</span> <span style="color: #FF0000;">5</span>,
        ErrorUnableToAccessOfficeInterop <span style="color: #008000;">=</span> <span style="color: #FF0000;">6</span>,
        ErrorUnableToExportToXps <span style="color: #008000;">=</span> <span style="color: #FF0000;">7</span>
    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>This solution uses the 2007 Office Interop libraries for Word, Excel, and PowerPoint. To compile it in Visual Studio you&#8217;ll need to reference these assemblies in your project. For example here&#8217;s what the Word assembly looks like:</p>
<p><img src="http://mel-green.com/wp-content/uploads/2010/05/word_interop_reference.png" alt="" title="word_interop_reference" width="590" height="408" class="aligncenter size-full wp-image-473" /></p>
<p>Also note that I&#8217;ve made use of some shortcuts provided by the new optional parameters in C# 4.0. If you&#8217;re using an earlier version of .Net you&#8217;ll have to make some changes to the interop calls, but it&#8217;s nothing serious.</p>
<p>Here&#8217;s a quick example of using the given code in an application:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #6666cc; font-weight: bold;">string</span> filePath <span style="color: #008000;">=</span> <span style="color: #666666;">@&quot;C:\Test\Test.doc&quot;</span><span style="color: #008000;">;</span>
<span style="color: #6666cc; font-weight: bold;">string</span> xpsFilePath <span style="color: #008000;">=</span> <span style="color: #666666;">@&quot;C:\Test\Test.xps&quot;</span><span style="color: #008000;">;</span>
&nbsp;
var convertResults <span style="color: #008000;">=</span> OfficeToXps<span style="color: #008000;">.</span><span style="color: #0000FF;">ConvertToXps</span><span style="color: #008000;">&#40;</span>filePath, <span style="color: #0600FF; font-weight: bold;">ref</span> xpsFilePath<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">switch</span> <span style="color: #008000;">&#40;</span>convertResults<span style="color: #008000;">.</span><span style="color: #0000FF;">Result</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    <span style="color: #0600FF; font-weight: bold;">case</span> ConversionResult<span style="color: #008000;">.</span><span style="color: #0000FF;">OK</span><span style="color: #008000;">:</span>
        XpsDocument xpsDoc <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> XpsDocument<span style="color: #008000;">&#40;</span>xpsFilePath, FileAccess<span style="color: #008000;">.</span><span style="color: #0000FF;">ReadWrite</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #0600FF; font-weight: bold;">break</span><span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">case</span> ConversionResult<span style="color: #008000;">.</span><span style="color: #0000FF;">InvalidFilePath</span><span style="color: #008000;">:</span>
        <span style="color: #008080; font-style: italic;">// Handle bad file path or file missing</span>
        <span style="color: #0600FF; font-weight: bold;">break</span><span style="color: #008000;">;</span>
    <span style="color: #0600FF; font-weight: bold;">case</span> ConversionResult<span style="color: #008000;">.</span><span style="color: #0000FF;">UnexpectedError</span><span style="color: #008000;">:</span>
        <span style="color: #008080; font-style: italic;">// This should only happen if the code is modified poorly</span>
        <span style="color: #0600FF; font-weight: bold;">break</span><span style="color: #008000;">;</span>
    <span style="color: #0600FF; font-weight: bold;">case</span> ConversionResult<span style="color: #008000;">.</span><span style="color: #0000FF;">ErrorUnableToInitializeOfficeApp</span><span style="color: #008000;">:</span>
        <span style="color: #008080; font-style: italic;">// Handle Office 2007 (Word | Excel | PowerPoint) not installed</span>
        <span style="color: #0600FF; font-weight: bold;">break</span><span style="color: #008000;">;</span>
    <span style="color: #0600FF; font-weight: bold;">case</span> ConversionResult<span style="color: #008000;">.</span><span style="color: #0000FF;">ErrorUnableToOpenOfficeFile</span><span style="color: #008000;">:</span>
        <span style="color: #008080; font-style: italic;">// Handle source file being locked or invalid permissions</span>
        <span style="color: #0600FF; font-weight: bold;">break</span><span style="color: #008000;">;</span>
    <span style="color: #0600FF; font-weight: bold;">case</span> ConversionResult<span style="color: #008000;">.</span><span style="color: #0000FF;">ErrorUnableToAccessOfficeInterop</span><span style="color: #008000;">:</span>
        <span style="color: #008080; font-style: italic;">// Handle Office 2007 (Word | Excel | PowerPoint) not installed</span>
        <span style="color: #0600FF; font-weight: bold;">break</span><span style="color: #008000;">;</span>
    <span style="color: #0600FF; font-weight: bold;">case</span> ConversionResult<span style="color: #008000;">.</span><span style="color: #0000FF;">ErrorUnableToExportToXps</span><span style="color: #008000;">:</span>
        <span style="color: #008080; font-style: italic;">// Handle Microsoft Save As PDF or XPS Add-In missing for 2007</span>
        <span style="color: #0600FF; font-weight: bold;">break</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://mel-green.com/2010/05/officetoxps-convert-word-excel-and-powerpoint-to-xps/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>WPF: Time Control 12 Hour Format</title>
		<link>http://mel-green.com/2010/03/wpf-time-control-12-hour-format/</link>
		<comments>http://mel-green.com/2010/03/wpf-time-control-12-hour-format/#comments</comments>
		<pubDate>Tue, 16 Mar 2010 02:14:50 +0000</pubDate>
		<dc:creator>Mel</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[XAML]]></category>
		<category><![CDATA[Control]]></category>

		<guid isPermaLink="false">http://mel-green.com/?p=459</guid>
		<description><![CDATA[I&#8217;ve spent a bit of time scouring the internet for a WPF Time Control that supports 12-hour format. There are several examples out there that are in 24-hour format, but I haven&#8217;t seen any for 12-hour format, so I wrote one. I began with some code located here and then modified it extensively to work [...]]]></description>
			<content:encoded><![CDATA[<p><div id="attachment_462" class="wp-caption aligncenter" style="width: 120px"><img src="http://mel-green.com/wp-content/uploads/2010/03/TimeControl12.png" alt="Time Control 12 Hour Format" title="Time Control 12 Hour Format" width="110" height="60" class="size-full wp-image-462" /><p class="wp-caption-text">Time Control 12 Hour Format</p></div> <br/></p>
<p>I&#8217;ve spent a bit of time scouring the internet for a WPF Time Control that supports 12-hour format. There are several examples out there that are in 24-hour format, but I haven&#8217;t seen any for 12-hour format, so I wrote one. I began with some code located <a href="http://jobijoy.blogspot.com/2007/10/time-picker-user-control.html">here</a> and then modified it extensively to work for my situation. I didn&#8217;t need to display seconds, however it would be pretty easy to add them.</p>
<p>This control supports a wide range of keyboard input. You can enter the value for <em>Hour</em>, <em>Minute</em>, and <em>Part of Day</em> by either using the up/down arrow keys or by typing in numbers and letters. If you have any questions/suggestions/praise/opinions please feel free to leave a comment!<br />
<br/><br />
XAML:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;UserControl</span> <span style="color: #000066;">x:Class</span>=<span style="color: #ff0000;">&quot;CGS.TimeControl&quot;</span></span>
<span style="color: #009900;">             <span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;</span></span>
<span style="color: #009900;">             <span style="color: #000066;">xmlns:x</span>=<span style="color: #ff0000;">&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;</span></span>
<span style="color: #009900;">             <span style="color: #000066;">xmlns:mc</span>=<span style="color: #ff0000;">&quot;http://schemas.openxmlformats.org/markup-compatibility/2006&quot;</span> </span>
<span style="color: #009900;">             <span style="color: #000066;">xmlns:d</span>=<span style="color: #ff0000;">&quot;http://schemas.microsoft.com/expression/blend/2008&quot;</span></span>
<span style="color: #009900;">             <span style="color: #000066;">xmlns:local</span>=<span style="color: #ff0000;">&quot;clr-namespace:CGS&quot;</span></span>
<span style="color: #009900;">             <span style="color: #000066;">Height</span>=<span style="color: #ff0000;">&quot;Auto&quot;</span> <span style="color: #000066;">Width</span>=<span style="color: #ff0000;">&quot;Auto&quot;</span> <span style="color: #000066;">x:Name</span>=<span style="color: #ff0000;">&quot;UserControl&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;UserControl.Resources<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;local:MinuteSecondToStringConverter</span> <span style="color: #000066;">x:Key</span>=<span style="color: #ff0000;">&quot;minuteSecondConverter&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/UserControl.Resources<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Border</span> <span style="color: #000066;">BorderBrush</span>=<span style="color: #ff0000;">&quot;Black&quot;</span> <span style="color: #000066;">BorderThickness</span>=<span style="color: #ff0000;">&quot;1&quot;</span> <span style="color: #000066;">CornerRadius</span>=<span style="color: #ff0000;">&quot;1&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Grid</span> <span style="color: #000066;">x:Name</span>=<span style="color: #ff0000;">&quot;LayoutRoot&quot;</span> <span style="color: #000066;">Width</span>=<span style="color: #ff0000;">&quot;Auto&quot;</span> <span style="color: #000066;">Height</span>=<span style="color: #ff0000;">&quot;Auto&quot;</span> <span style="color: #000066;">Margin</span>=<span style="color: #ff0000;">&quot;2&quot;</span> <span style="color: #000066;">Background</span>=<span style="color: #ff0000;">&quot;White&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Grid.ColumnDefinitions<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ColumnDefinition</span> <span style="color: #000066;">Width</span>=<span style="color: #ff0000;">&quot;0.2*&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ColumnDefinition</span> <span style="color: #000066;">Width</span>=<span style="color: #ff0000;">&quot;0.05*&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ColumnDefinition</span> <span style="color: #000066;">Width</span>=<span style="color: #ff0000;">&quot;0.2*&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ColumnDefinition</span> <span style="color: #000066;">Width</span>=<span style="color: #ff0000;">&quot;0.05*&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ColumnDefinition</span> <span style="color: #000066;">Width</span>=<span style="color: #ff0000;">&quot;0.2*&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Grid.ColumnDefinitions<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Grid</span> <span style="color: #000066;">x:Name</span>=<span style="color: #ff0000;">&quot;hour&quot;</span> <span style="color: #000066;">Focusable</span>=<span style="color: #ff0000;">&quot;True&quot;</span> <span style="color: #000066;">KeyDown</span>=<span style="color: #ff0000;">&quot;Down&quot;</span> <span style="color: #000066;">GotFocus</span>=<span style="color: #ff0000;">&quot;Grid_GotFocus&quot;</span> <span style="color: #000066;">LostFocus</span>=<span style="color: #ff0000;">&quot;Grid_LostFocus&quot;</span> <span style="color: #000066;">MouseDown</span>=<span style="color: #ff0000;">&quot;Grid_MouseDown&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;TextBlock</span> <span style="color: #000066;">TextWrapping</span>=<span style="color: #ff0000;">&quot;Wrap&quot;</span> <span style="color: #000066;">Text</span>=<span style="color: #ff0000;">&quot;{Binding Path=Hours, ElementName=UserControl, Mode=Default}&quot;</span></span>
<span style="color: #009900;">                 <span style="color: #000066;">TextAlignment</span>=<span style="color: #ff0000;">&quot;Center&quot;</span> <span style="color: #000066;">VerticalAlignment</span>=<span style="color: #ff0000;">&quot;Center&quot;</span> <span style="color: #000066;">FontSize</span>=<span style="color: #ff0000;">&quot;{Binding ElementName=UserControl, Path=FontSize}&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Grid<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Grid</span>  <span style="color: #000066;">Grid.Column</span>=<span style="color: #ff0000;">&quot;1&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;TextBlock</span>  <span style="color: #000066;">x:Name</span>=<span style="color: #ff0000;">&quot;sep1&quot;</span> <span style="color: #000066;">TextWrapping</span>=<span style="color: #ff0000;">&quot;Wrap&quot;</span> <span style="color: #000066;">VerticalAlignment</span>=<span style="color: #ff0000;">&quot;Center&quot;</span> <span style="color: #000066;">Background</span>=<span style="color: #ff0000;">&quot;{x:Null}&quot;</span></span>
<span style="color: #009900;">                  <span style="color: #000066;">FontSize</span>=<span style="color: #ff0000;">&quot;{Binding ElementName=UserControl, Path=FontSize}&quot;</span> <span style="color: #000066;">Text</span>=<span style="color: #ff0000;">&quot;:&quot;</span> <span style="color: #000066;">TextAlignment</span>=<span style="color: #ff0000;">&quot;Center&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Grid<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Grid</span>  <span style="color: #000066;">Grid.Column</span>=<span style="color: #ff0000;">&quot;2&quot;</span> <span style="color: #000066;">x:Name</span>=<span style="color: #ff0000;">&quot;min&quot;</span> <span style="color: #000066;">Focusable</span>=<span style="color: #ff0000;">&quot;True&quot;</span> <span style="color: #000066;">KeyDown</span>=<span style="color: #ff0000;">&quot;Down&quot;</span> <span style="color: #000066;">GotFocus</span>=<span style="color: #ff0000;">&quot;Grid_GotFocus&quot;</span> <span style="color: #000066;">LostFocus</span>=<span style="color: #ff0000;">&quot;Grid_LostFocus&quot;</span> <span style="color: #000066;">MouseDown</span>=<span style="color: #ff0000;">&quot;Grid_MouseDown&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;TextBlock</span>  <span style="color: #000066;">TextWrapping</span>=<span style="color: #ff0000;">&quot;Wrap&quot;</span> <span style="color: #000066;">Text</span>=<span style="color: #ff0000;">&quot;{Binding Path=Minutes, ElementName=UserControl, Mode=Default, Converter={StaticResource minuteSecondConverter}}&quot;</span></span>
<span style="color: #009900;">                  <span style="color: #000066;">TextAlignment</span>=<span style="color: #ff0000;">&quot;Center&quot;</span> <span style="color: #000066;">VerticalAlignment</span>=<span style="color: #ff0000;">&quot;Center&quot;</span> <span style="color: #000066;">FontSize</span>=<span style="color: #ff0000;">&quot;{Binding ElementName=UserControl, Path=FontSize}&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Grid<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Grid</span>  <span style="color: #000066;">Grid.Column</span>=<span style="color: #ff0000;">&quot;4&quot;</span> <span style="color: #000066;">Name</span>=<span style="color: #ff0000;">&quot;half&quot;</span> <span style="color: #000066;">Focusable</span>=<span style="color: #ff0000;">&quot;True&quot;</span> <span style="color: #000066;">KeyDown</span>=<span style="color: #ff0000;">&quot;Down&quot;</span> <span style="color: #000066;">GotFocus</span>=<span style="color: #ff0000;">&quot;Grid_GotFocus&quot;</span> <span style="color: #000066;">LostFocus</span>=<span style="color: #ff0000;">&quot;Grid_LostFocus&quot;</span> <span style="color: #000066;">MouseDown</span>=<span style="color: #ff0000;">&quot;Grid_MouseDown&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>                
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;TextBlock</span> <span style="color: #000066;">TextWrapping</span>=<span style="color: #ff0000;">&quot;Wrap&quot;</span> <span style="color: #000066;">Text</span>=<span style="color: #ff0000;">&quot;{Binding Path=DayHalf, ElementName=UserControl, Mode=Default}&quot;</span></span>
<span style="color: #009900;">                 <span style="color: #000066;">TextAlignment</span>=<span style="color: #ff0000;">&quot;Center&quot;</span> <span style="color: #000066;">VerticalAlignment</span>=<span style="color: #ff0000;">&quot;Center&quot;</span> <span style="color: #000066;">FontSize</span>=<span style="color: #ff0000;">&quot;{Binding ElementName=UserControl, Path=FontSize}&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Grid<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Grid<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Border<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/UserControl<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Code:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Windows</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Windows.Controls</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Windows.Input</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Windows.Media</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Windows.Data</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">namespace</span> CGS
<span style="color: #008000;">&#123;</span>
    <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
    <span style="color: #008080; font-style: italic;">/// Interaction logic for TimeControl.xaml</span>
    <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
    <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">partial</span> <span style="color: #6666cc; font-weight: bold;">class</span> TimeControl <span style="color: #008000;">:</span> UserControl
    <span style="color: #008000;">&#123;</span>
        <span style="color: #0600FF; font-weight: bold;">const</span> <span style="color: #6666cc; font-weight: bold;">string</span> amText <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;am&quot;</span><span style="color: #008000;">;</span>
        <span style="color: #0600FF; font-weight: bold;">const</span> <span style="color: #6666cc; font-weight: bold;">string</span> pmText <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;pm&quot;</span><span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">static</span> SolidColorBrush brBlue <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> SolidColorBrush<span style="color: #008000;">&#40;</span>Colors<span style="color: #008000;">.</span><span style="color: #0000FF;">LightBlue</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #0600FF; font-weight: bold;">static</span> SolidColorBrush brWhite <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> SolidColorBrush<span style="color: #008000;">&#40;</span>Colors<span style="color: #008000;">.</span><span style="color: #0000FF;">White</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
        DateTime _lastKeyDown<span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">public</span> TimeControl<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            InitializeComponent<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            _lastKeyDown <span style="color: #008000;">=</span> DateTime<span style="color: #008000;">.</span><span style="color: #0000FF;">Now</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">public</span> TimeSpan Value
        <span style="color: #008000;">&#123;</span>
            get <span style="color: #008000;">&#123;</span> <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #008000;">&#40;</span>TimeSpan<span style="color: #008000;">&#41;</span>GetValue<span style="color: #008000;">&#40;</span>ValueProperty<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
            set <span style="color: #008000;">&#123;</span> SetValue<span style="color: #008000;">&#40;</span>ValueProperty, value<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
        <span style="color: #008000;">&#125;</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #0600FF; font-weight: bold;">readonly</span> DependencyProperty ValueProperty <span style="color: #008000;">=</span>
        DependencyProperty<span style="color: #008000;">.</span><span style="color: #0000FF;">Register</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Value&quot;</span>, <span style="color: #008000;">typeof</span><span style="color: #008000;">&#40;</span>TimeSpan<span style="color: #008000;">&#41;</span>, <span style="color: #008000;">typeof</span><span style="color: #008000;">&#40;</span>TimeControl<span style="color: #008000;">&#41;</span>,
        <span style="color: #008000;">new</span> UIPropertyMetadata<span style="color: #008000;">&#40;</span>DateTime<span style="color: #008000;">.</span><span style="color: #0000FF;">Now</span><span style="color: #008000;">.</span><span style="color: #0000FF;">TimeOfDay</span>, <span style="color: #008000;">new</span> PropertyChangedCallback<span style="color: #008000;">&#40;</span>OnValueChanged<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">void</span> OnValueChanged<span style="color: #008000;">&#40;</span>DependencyObject obj, DependencyPropertyChangedEventArgs e<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            TimeControl control <span style="color: #008000;">=</span> obj <span style="color: #0600FF; font-weight: bold;">as</span> TimeControl<span style="color: #008000;">;</span>
&nbsp;
            TimeSpan newTime <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>TimeSpan<span style="color: #008000;">&#41;</span>e<span style="color: #008000;">.</span><span style="color: #0000FF;">NewValue</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #6666cc; font-weight: bold;">int</span> timehours <span style="color: #008000;">=</span> newTime<span style="color: #008000;">.</span><span style="color: #0000FF;">Hours</span><span style="color: #008000;">;</span>
            <span style="color: #6666cc; font-weight: bold;">int</span> hours <span style="color: #008000;">=</span> timehours <span style="color: #008000;">%</span> <span style="color: #FF0000;">12</span><span style="color: #008000;">;</span>
            hours <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span>hours <span style="color: #008000;">&gt;</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">?</span> hours <span style="color: #008000;">:</span> <span style="color: #FF0000;">12</span><span style="color: #008000;">;</span>
&nbsp;
            control<span style="color: #008000;">.</span>_hours <span style="color: #008000;">=</span> newTime<span style="color: #008000;">.</span><span style="color: #0000FF;">Hours</span><span style="color: #008000;">;</span>
            control<span style="color: #008000;">.</span><span style="color: #0000FF;">Hours</span> <span style="color: #008000;">=</span> hours<span style="color: #008000;">;</span>
            control<span style="color: #008000;">.</span><span style="color: #0000FF;">Minutes</span> <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>TimeSpan<span style="color: #008000;">&#41;</span>e<span style="color: #008000;">.</span><span style="color: #0000FF;">NewValue</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Minutes</span><span style="color: #008000;">;</span>
            control<span style="color: #008000;">.</span><span style="color: #0000FF;">DayHalf</span> <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>timehours <span style="color: #008000;">-</span> <span style="color: #FF0000;">12</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&gt;=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">?</span> pmText <span style="color: #008000;">:</span> amText<span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">int</span> _hours<span style="color: #008000;">;</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">int</span> Hours
        <span style="color: #008000;">&#123;</span>
            get <span style="color: #008000;">&#123;</span> <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#41;</span>GetValue<span style="color: #008000;">&#40;</span>HoursProperty<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
            set <span style="color: #008000;">&#123;</span> SetValue<span style="color: #008000;">&#40;</span>HoursProperty, value<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
        <span style="color: #008000;">&#125;</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #0600FF; font-weight: bold;">readonly</span> DependencyProperty HoursProperty <span style="color: #008000;">=</span>
        DependencyProperty<span style="color: #008000;">.</span><span style="color: #0000FF;">Register</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Hours&quot;</span>, <span style="color: #008000;">typeof</span><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#41;</span>, <span style="color: #008000;">typeof</span><span style="color: #008000;">&#40;</span>TimeControl<span style="color: #008000;">&#41;</span>,
        <span style="color: #008000;">new</span> UIPropertyMetadata<span style="color: #008000;">&#40;</span><span style="color: #FF0000;">0</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">int</span> Minutes
        <span style="color: #008000;">&#123;</span>
            get <span style="color: #008000;">&#123;</span> <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#41;</span>GetValue<span style="color: #008000;">&#40;</span>MinutesProperty<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
            set <span style="color: #008000;">&#123;</span> SetValue<span style="color: #008000;">&#40;</span>MinutesProperty, value<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
        <span style="color: #008000;">&#125;</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #0600FF; font-weight: bold;">readonly</span> DependencyProperty MinutesProperty <span style="color: #008000;">=</span>
        DependencyProperty<span style="color: #008000;">.</span><span style="color: #0000FF;">Register</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Minutes&quot;</span>, <span style="color: #008000;">typeof</span><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#41;</span>, <span style="color: #008000;">typeof</span><span style="color: #008000;">&#40;</span>TimeControl<span style="color: #008000;">&#41;</span>,
        <span style="color: #008000;">new</span> UIPropertyMetadata<span style="color: #008000;">&#40;</span><span style="color: #FF0000;">0</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">string</span> DayHalf
        <span style="color: #008000;">&#123;</span>
            get <span style="color: #008000;">&#123;</span> <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&#41;</span>GetValue<span style="color: #008000;">&#40;</span>DayHalfProperty<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
            set <span style="color: #008000;">&#123;</span> SetValue<span style="color: #008000;">&#40;</span>DayHalfProperty, value<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
        <span style="color: #008000;">&#125;</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #0600FF; font-weight: bold;">readonly</span> DependencyProperty DayHalfProperty <span style="color: #008000;">=</span>
        DependencyProperty<span style="color: #008000;">.</span><span style="color: #0000FF;">Register</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;DayHalf&quot;</span>, <span style="color: #008000;">typeof</span><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&#41;</span>, <span style="color: #008000;">typeof</span><span style="color: #008000;">&#40;</span>TimeControl<span style="color: #008000;">&#41;</span>,
        <span style="color: #008000;">new</span> UIPropertyMetadata<span style="color: #008000;">&#40;</span>amText<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">void</span> Down<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">object</span> sender, KeyEventArgs args<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            <span style="color: #6666cc; font-weight: bold;">bool</span> updateValue <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>args<span style="color: #008000;">.</span><span style="color: #0000FF;">Key</span> <span style="color: #008000;">==</span> Key<span style="color: #008000;">.</span><span style="color: #0000FF;">Up</span> <span style="color: #008000;">||</span> args<span style="color: #008000;">.</span><span style="color: #0000FF;">Key</span> <span style="color: #008000;">==</span> Key<span style="color: #008000;">.</span><span style="color: #0000FF;">Down</span><span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
                <span style="color: #0600FF; font-weight: bold;">switch</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>Grid<span style="color: #008000;">&#41;</span>sender<span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Name</span><span style="color: #008000;">&#41;</span>
                <span style="color: #008000;">&#123;</span>
                    <span style="color: #0600FF; font-weight: bold;">case</span> <span style="color: #666666;">&quot;min&quot;</span><span style="color: #008000;">:</span>
                        <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>args<span style="color: #008000;">.</span><span style="color: #0000FF;">Key</span> <span style="color: #008000;">==</span> Key<span style="color: #008000;">.</span><span style="color: #0000FF;">Up</span><span style="color: #008000;">&#41;</span>
                            <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Minutes</span> <span style="color: #008000;">+</span> <span style="color: #FF0000;">1</span> <span style="color: #008000;">&gt;</span> <span style="color: #FF0000;">59</span><span style="color: #008000;">&#41;</span>
                            <span style="color: #008000;">&#123;</span>
                                <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Minutes</span> <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span>
                                <span style="color: #0600FF; font-weight: bold;">goto</span> <span style="color: #0600FF; font-weight: bold;">case</span> <span style="color: #666666;">&quot;hour&quot;</span><span style="color: #008000;">;</span>
                            <span style="color: #008000;">&#125;</span>
                            <span style="color: #0600FF; font-weight: bold;">else</span>
                            <span style="color: #008000;">&#123;</span>
                                <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Minutes</span><span style="color: #008000;">++;</span>
                            <span style="color: #008000;">&#125;</span>
                        <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>args<span style="color: #008000;">.</span><span style="color: #0000FF;">Key</span> <span style="color: #008000;">==</span> Key<span style="color: #008000;">.</span><span style="color: #0000FF;">Down</span><span style="color: #008000;">&#41;</span>
                            <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Minutes</span> <span style="color: #008000;">-</span> <span style="color: #FF0000;">1</span> <span style="color: #008000;">&lt;</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">&#41;</span>
                            <span style="color: #008000;">&#123;</span>
                                <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Minutes</span> <span style="color: #008000;">=</span> <span style="color: #FF0000;">59</span><span style="color: #008000;">;</span>
                                <span style="color: #0600FF; font-weight: bold;">goto</span> <span style="color: #0600FF; font-weight: bold;">case</span> <span style="color: #666666;">&quot;hour&quot;</span><span style="color: #008000;">;</span>
                            <span style="color: #008000;">&#125;</span>
                            <span style="color: #0600FF; font-weight: bold;">else</span>
                            <span style="color: #008000;">&#123;</span>
                                <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Minutes</span><span style="color: #008000;">--;</span>
                            <span style="color: #008000;">&#125;</span>
                        <span style="color: #0600FF; font-weight: bold;">break</span><span style="color: #008000;">;</span>
&nbsp;
                    <span style="color: #0600FF; font-weight: bold;">case</span> <span style="color: #666666;">&quot;hour&quot;</span><span style="color: #008000;">:</span>
                        <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>args<span style="color: #008000;">.</span><span style="color: #0000FF;">Key</span> <span style="color: #008000;">==</span> Key<span style="color: #008000;">.</span><span style="color: #0000FF;">Up</span><span style="color: #008000;">&#41;</span>
                            <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span>_hours <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span>_hours <span style="color: #008000;">+</span> <span style="color: #FF0000;">1</span> <span style="color: #008000;">&gt;</span> <span style="color: #FF0000;">23</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">?</span> <span style="color: #FF0000;">0</span> <span style="color: #008000;">:</span> _hours <span style="color: #008000;">+</span> <span style="color: #FF0000;">1</span><span style="color: #008000;">;</span>
                        <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>args<span style="color: #008000;">.</span><span style="color: #0000FF;">Key</span> <span style="color: #008000;">==</span> Key<span style="color: #008000;">.</span><span style="color: #0000FF;">Down</span><span style="color: #008000;">&#41;</span>
                            <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span>_hours <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span>_hours <span style="color: #008000;">-</span> <span style="color: #FF0000;">1</span> <span style="color: #008000;">&lt;</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">?</span> <span style="color: #FF0000;">23</span> <span style="color: #008000;">:</span> _hours <span style="color: #008000;">-</span> <span style="color: #FF0000;">1</span><span style="color: #008000;">;</span>
                        <span style="color: #0600FF; font-weight: bold;">break</span><span style="color: #008000;">;</span>
&nbsp;
                    <span style="color: #0600FF; font-weight: bold;">case</span> <span style="color: #666666;">&quot;half&quot;</span><span style="color: #008000;">:</span>
                        <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">DayHalf</span> <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">DayHalf</span> <span style="color: #008000;">==</span> amText<span style="color: #008000;">&#41;</span> <span style="color: #008000;">?</span> pmText <span style="color: #008000;">:</span> amText<span style="color: #008000;">;</span>
&nbsp;
                        <span style="color: #6666cc; font-weight: bold;">int</span> timeHours <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Hours</span><span style="color: #008000;">;</span>
                        timeHours <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span>timeHours <span style="color: #008000;">==</span> <span style="color: #FF0000;">12</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">?</span> <span style="color: #FF0000;">0</span> <span style="color: #008000;">:</span> timeHours<span style="color: #008000;">;</span>
                        timeHours <span style="color: #008000;">+=</span> <span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">DayHalf</span> <span style="color: #008000;">==</span> amText<span style="color: #008000;">&#41;</span> <span style="color: #008000;">?</span> <span style="color: #FF0000;">0</span> <span style="color: #008000;">:</span> <span style="color: #FF0000;">12</span><span style="color: #008000;">;</span>
&nbsp;
                        _hours <span style="color: #008000;">=</span> timeHours<span style="color: #008000;">;</span>
                        <span style="color: #0600FF; font-weight: bold;">break</span><span style="color: #008000;">;</span>
                <span style="color: #008000;">&#125;</span>
&nbsp;
                updateValue <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span>
&nbsp;
                args<span style="color: #008000;">.</span><span style="color: #0000FF;">Handled</span> <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span>
            <span style="color: #008000;">&#125;</span>
            <span style="color: #0600FF; font-weight: bold;">else</span> <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>args<span style="color: #008000;">.</span><span style="color: #0000FF;">Key</span> <span style="color: #008000;">&gt;=</span> Key<span style="color: #008000;">.</span><span style="color: #0000FF;">D0</span> <span style="color: #008000;">&amp;&amp;</span> args<span style="color: #008000;">.</span><span style="color: #0000FF;">Key</span> <span style="color: #008000;">&lt;=</span> Key<span style="color: #008000;">.</span><span style="color: #0000FF;">D9</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">||</span> <span style="color: #008000;">&#40;</span>args<span style="color: #008000;">.</span><span style="color: #0000FF;">Key</span> <span style="color: #008000;">&gt;=</span> Key<span style="color: #008000;">.</span><span style="color: #0000FF;">NumPad0</span> <span style="color: #008000;">&amp;&amp;</span> args<span style="color: #008000;">.</span><span style="color: #0000FF;">Key</span> <span style="color: #008000;">&lt;=</span> Key<span style="color: #008000;">.</span><span style="color: #0000FF;">NumPad9</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
                <span style="color: #6666cc; font-weight: bold;">int</span> keyValue <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#41;</span>args<span style="color: #008000;">.</span><span style="color: #0000FF;">Key</span><span style="color: #008000;">;</span>
                <span style="color: #6666cc; font-weight: bold;">int</span> number <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span>
&nbsp;
                number <span style="color: #008000;">=</span> keyValue <span style="color: #008000;">-</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>args<span style="color: #008000;">.</span><span style="color: #0000FF;">Key</span> <span style="color: #008000;">&gt;=</span> Key<span style="color: #008000;">.</span><span style="color: #0000FF;">D0</span> <span style="color: #008000;">&amp;&amp;</span> args<span style="color: #008000;">.</span><span style="color: #0000FF;">Key</span> <span style="color: #008000;">&lt;=</span> Key<span style="color: #008000;">.</span><span style="color: #0000FF;">D9</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">?</span>
                                        <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#41;</span>Key<span style="color: #008000;">.</span><span style="color: #0000FF;">D0</span> <span style="color: #008000;">:</span>
                                        <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#41;</span>Key<span style="color: #008000;">.</span><span style="color: #0000FF;">NumPad0</span>
                                    <span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
                <span style="color: #6666cc; font-weight: bold;">bool</span> attemptAdd <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span>DateTime<span style="color: #008000;">.</span><span style="color: #0000FF;">Now</span> <span style="color: #008000;">-</span> _lastKeyDown<span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">TotalSeconds</span> <span style="color: #008000;">&lt;</span> <span style="color: #FF0000;">1.5</span><span style="color: #008000;">;</span>
&nbsp;
                <span style="color: #0600FF; font-weight: bold;">switch</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>Grid<span style="color: #008000;">&#41;</span>sender<span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Name</span><span style="color: #008000;">&#41;</span>
                <span style="color: #008000;">&#123;</span>
                    <span style="color: #0600FF; font-weight: bold;">case</span> <span style="color: #666666;">&quot;min&quot;</span><span style="color: #008000;">:</span>
                        <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>attemptAdd<span style="color: #008000;">&#41;</span>
                        <span style="color: #008000;">&#123;</span>
                            number <span style="color: #008000;">+=</span> <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Minutes</span> <span style="color: #008000;">*</span> <span style="color: #FF0000;">10</span><span style="color: #008000;">;</span>
&nbsp;
                            <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>number <span style="color: #008000;">&lt;</span> <span style="color: #FF0000;">0</span> <span style="color: #008000;">||</span> number <span style="color: #008000;">&gt;=</span> <span style="color: #FF0000;">60</span><span style="color: #008000;">&#41;</span>
                            <span style="color: #008000;">&#123;</span>
                                number <span style="color: #008000;">-=</span> <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Minutes</span> <span style="color: #008000;">*</span> <span style="color: #FF0000;">10</span><span style="color: #008000;">;</span>
                            <span style="color: #008000;">&#125;</span>
                        <span style="color: #008000;">&#125;</span>
&nbsp;
                        <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Minutes</span> <span style="color: #008000;">=</span> number<span style="color: #008000;">;</span>
                        <span style="color: #0600FF; font-weight: bold;">break</span><span style="color: #008000;">;</span>
&nbsp;
                    <span style="color: #0600FF; font-weight: bold;">case</span> <span style="color: #666666;">&quot;hour&quot;</span><span style="color: #008000;">:</span>
                        <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>attemptAdd<span style="color: #008000;">&#41;</span>
                        <span style="color: #008000;">&#123;</span>
                            number <span style="color: #008000;">+=</span> <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Hours</span> <span style="color: #008000;">*</span> <span style="color: #FF0000;">10</span><span style="color: #008000;">;</span>
&nbsp;
                            <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>number <span style="color: #008000;">&lt;</span> <span style="color: #FF0000;">0</span> <span style="color: #008000;">||</span> number <span style="color: #008000;">&gt;=</span> <span style="color: #FF0000;">13</span><span style="color: #008000;">&#41;</span>
                            <span style="color: #008000;">&#123;</span>
                                number <span style="color: #008000;">-=</span> <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Hours</span> <span style="color: #008000;">*</span> <span style="color: #FF0000;">10</span><span style="color: #008000;">;</span>
                            <span style="color: #008000;">&#125;</span>
                        <span style="color: #008000;">&#125;</span>
&nbsp;
                        number <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span>number <span style="color: #008000;">==</span> <span style="color: #FF0000;">12</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">?</span> <span style="color: #FF0000;">0</span> <span style="color: #008000;">:</span> number<span style="color: #008000;">;</span>
                        number <span style="color: #008000;">+=</span> <span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">DayHalf</span> <span style="color: #008000;">==</span> amText<span style="color: #008000;">&#41;</span> <span style="color: #008000;">?</span> <span style="color: #FF0000;">0</span> <span style="color: #008000;">:</span> <span style="color: #FF0000;">12</span><span style="color: #008000;">;</span>
&nbsp;
                        _hours <span style="color: #008000;">=</span> number<span style="color: #008000;">;</span>
                        <span style="color: #0600FF; font-weight: bold;">break</span><span style="color: #008000;">;</span>
&nbsp;
                    <span style="color: #0600FF; font-weight: bold;">default</span><span style="color: #008000;">:</span>
                        <span style="color: #0600FF; font-weight: bold;">break</span><span style="color: #008000;">;</span>
                <span style="color: #008000;">&#125;</span>
&nbsp;
                updateValue <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span>
&nbsp;
                args<span style="color: #008000;">.</span><span style="color: #0000FF;">Handled</span> <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span>
            <span style="color: #008000;">&#125;</span>
            <span style="color: #0600FF; font-weight: bold;">else</span> <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>args<span style="color: #008000;">.</span><span style="color: #0000FF;">Key</span> <span style="color: #008000;">==</span> Key<span style="color: #008000;">.</span><span style="color: #0000FF;">A</span> <span style="color: #008000;">||</span> args<span style="color: #008000;">.</span><span style="color: #0000FF;">Key</span> <span style="color: #008000;">==</span> Key<span style="color: #008000;">.</span><span style="color: #0000FF;">P</span><span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
                <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>Grid<span style="color: #008000;">&#41;</span>sender<span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Name</span> <span style="color: #008000;">==</span> <span style="color: #666666;">&quot;half&quot;</span><span style="color: #008000;">&#41;</span>
                <span style="color: #008000;">&#123;</span>
                    <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">DayHalf</span> <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span>args<span style="color: #008000;">.</span><span style="color: #0000FF;">Key</span> <span style="color: #008000;">==</span> Key<span style="color: #008000;">.</span><span style="color: #0000FF;">A</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">?</span> amText <span style="color: #008000;">:</span> pmText<span style="color: #008000;">;</span>
&nbsp;
                    updateValue <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span> 
                <span style="color: #008000;">&#125;</span>
            <span style="color: #008000;">&#125;</span>
&nbsp;
            <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>updateValue<span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
                <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Value</span> <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> TimeSpan<span style="color: #008000;">&#40;</span>_hours, <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Minutes</span>, <span style="color: #FF0000;">0</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #008000;">&#125;</span>
&nbsp;
            _lastKeyDown <span style="color: #008000;">=</span> DateTime<span style="color: #008000;">.</span><span style="color: #0000FF;">Now</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">void</span> Grid_GotFocus<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">object</span> sender, RoutedEventArgs e<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            var grd <span style="color: #008000;">=</span> sender <span style="color: #0600FF; font-weight: bold;">as</span> Grid<span style="color: #008000;">;</span>
&nbsp;
            grd<span style="color: #008000;">.</span><span style="color: #0000FF;">Background</span> <span style="color: #008000;">=</span> brBlue<span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">void</span> Grid_LostFocus<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">object</span> sender, RoutedEventArgs e<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            var grd <span style="color: #008000;">=</span> sender <span style="color: #0600FF; font-weight: bold;">as</span> Grid<span style="color: #008000;">;</span>
&nbsp;
            grd<span style="color: #008000;">.</span><span style="color: #0000FF;">Background</span> <span style="color: #008000;">=</span> brWhite<span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">void</span> Grid_MouseDown<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">object</span> sender, MouseButtonEventArgs e<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            var grd <span style="color: #008000;">=</span> sender <span style="color: #0600FF; font-weight: bold;">as</span> Grid<span style="color: #008000;">;</span>
&nbsp;
            grd<span style="color: #008000;">.</span><span style="color: #0000FF;">Focus</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
    <span style="color: #008000;">&#125;</span>
&nbsp;
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> MinuteSecondToStringConverter <span style="color: #008000;">:</span> IValueConverter
    <span style="color: #008000;">&#123;</span>
        <span style="color: #008080;">#region IValueConverter Members</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">object</span> Convert<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">object</span> value, Type targetType, <span style="color: #6666cc; font-weight: bold;">object</span> parameter, <span style="color: #000000;">System.<span style="color: #0000FF;">Globalization</span></span><span style="color: #008000;">.</span><span style="color: #0000FF;">CultureInfo</span> culture<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>value <span style="color: #008000;">!=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
                <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>value <span style="color: #008000;">is</span> <span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#41;</span>
                <span style="color: #008000;">&#123;</span>
                    <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#41;</span>value<span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ToString</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;00&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #008000;">&#125;</span>
            <span style="color: #008000;">&#125;</span>
&nbsp;
            <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Empty</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">object</span> ConvertBack<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">object</span> value, Type targetType, <span style="color: #6666cc; font-weight: bold;">object</span> parameter, <span style="color: #000000;">System.<span style="color: #0000FF;">Globalization</span></span><span style="color: #008000;">.</span><span style="color: #0000FF;">CultureInfo</span> culture<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>value <span style="color: #008000;">!=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
                <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>value <span style="color: #008000;">is</span> <span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&#41;</span>
                <span style="color: #008000;">&#123;</span>
                    <span style="color: #6666cc; font-weight: bold;">int</span> number<span style="color: #008000;">;</span>
                    <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">.</span><span style="color: #0000FF;">TryParse</span><span style="color: #008000;">&#40;</span>value <span style="color: #0600FF; font-weight: bold;">as</span> <span style="color: #6666cc; font-weight: bold;">string</span>, <span style="color: #0600FF; font-weight: bold;">out</span> number<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
                    <span style="color: #008000;">&#123;</span>
                        <span style="color: #0600FF; font-weight: bold;">return</span> number<span style="color: #008000;">;</span>
                    <span style="color: #008000;">&#125;</span>
                <span style="color: #008000;">&#125;</span>
            <span style="color: #008000;">&#125;</span>
&nbsp;
            <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #008080;">#endregion</span>
    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>And here&#8217;s an example of how to use it:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;cgs:TimeControl</span> <span style="color: #000066;">x:Name</span>=<span style="color: #ff0000;">&quot;timeControl&quot;</span> <span style="color: #000066;">Margin</span>=<span style="color: #ff0000;">&quot;15,0,0,0&quot;</span> <span style="color: #000066;">Height</span>=<span style="color: #ff0000;">&quot;25&quot;</span> <span style="color: #000066;">Width</span>=<span style="color: #ff0000;">&quot;70&quot;</span></span>
<span style="color: #009900;">                                 <span style="color: #000066;">xmlns:cgs</span>=<span style="color: #ff0000;">&quot;clr-namespace:CGS&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008080; font-style: italic;">// Set the time of the control</span>
<span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">timeControl</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Value</span> <span style="color: #008000;">=</span> DateTime<span style="color: #008000;">.</span><span style="color: #0000FF;">Now</span><span style="color: #008000;">.</span><span style="color: #0000FF;">TimeOfDay</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #008080; font-style: italic;">// Get the time from the control</span>
TimeSpan time <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">timeControl</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Value</span><span style="color: #008000;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://mel-green.com/2010/03/wpf-time-control-12-hour-format/feed/</wfw:commentRss>
		<slash:comments>19</slash:comments>
		</item>
		<item>
		<title>ProgressStream: A Stream with Read and Write events</title>
		<link>http://mel-green.com/2010/01/progressstream/</link>
		<comments>http://mel-green.com/2010/01/progressstream/#comments</comments>
		<pubDate>Tue, 19 Jan 2010 18:41:46 +0000</pubDate>
		<dc:creator>Mel</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[.Net]]></category>
		<category><![CDATA[Event]]></category>
		<category><![CDATA[Stream]]></category>
		<category><![CDATA[WCF]]></category>

		<guid isPermaLink="false">http://mel-green.com/?p=451</guid>
		<description><![CDATA[In my experience with WCF I&#8217;ve implemented several solutions that leverage the message streaming capabilities present in the framework. Specifically in a client/server scenario when either side needs to transfer a file to the other side it is really convenient to be able to just pass a FileStream to a WCF service call and have [...]]]></description>
			<content:encoded><![CDATA[<p>In my experience with WCF I&#8217;ve implemented several solutions that leverage the message streaming capabilities present in the framework. Specifically in a client/server scenario when either side needs to transfer a file to the other side it is really convenient to be able to just pass a <a href="http://msdn.microsoft.com/en-us/library/system.io.filestream.aspx">FileStream</a> to a WCF service call and have the server read bytes from it and write them to disk as it pleases.</p>
<p>However, in this exact scenario, while the server can monitor and control how the bytes are read from the stream and track the progress, the client has no inherent way of determining how much of the file has been read across the network by the server. It would be really useful if the client could track this upload progress and display a progress bar or percentage to the user.</p>
<p>Well, I&#8217;ve created one of probably many possible solutions to this dilemma. I&#8217;ve written a class that inherits from <a href="http://msdn.microsoft.com/en-us/library/system.io.stream.aspx">Stream</a> and exposes some events that are raised when bytes are read or written to/from the stream. These events provide information for how many bytes were read from the stream, what the current position is in the stream, and what the stream&#8217;s total length is.</p>
<p>The <em>ProgressStream</em>, as I call it, accepts any <a href="http://msdn.microsoft.com/en-us/library/system.io.stream.aspx">Stream</a> object and encapsulates it, forwarding all regular stream calls to the underlying object. With this you can use the <em>ProgressStream</em> in conjunction with any other stream in .Net and leverage the added functionality.</p>
<p>Well enough explanation, here&#8217;s the code:</p>
<p><a href="http://mel-green.com/Uploads/ProgressStream.cs">ProgressStream.cs</a> <strong>(C#)</strong><br />
<a href="http://mel-green.com/Uploads/ProgressStream.vb">ProgressStream.vb</a> <strong>(VB.Net)</strong></p>
<p>And here&#8217;s a simple example in C# of how to use it:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.IO</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">CGS</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">namespace</span> ConsoleApplication1
<span style="color: #008000;">&#123;</span>
    <span style="color: #6666cc; font-weight: bold;">class</span> Program
    <span style="color: #008000;">&#123;</span>
        <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">void</span> Main<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> args<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            var test <span style="color: #008000;">=</span> File<span style="color: #008000;">.</span><span style="color: #0000FF;">OpenRead</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">@&quot;C:\Test\Test.doc&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            var pStream <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> ProgressStream<span style="color: #008000;">&#40;</span>test<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            pStream<span style="color: #008000;">.</span><span style="color: #0000FF;">BytesRead</span> <span style="color: #008000;">+=</span> 
                <span style="color: #008000;">new</span> ProgressStreamReportDelegate<span style="color: #008000;">&#40;</span>pStream_BytesRead<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #6666cc; font-weight: bold;">int</span> bSize <span style="color: #008000;">=</span> <span style="color: #FF0000;">4320</span><span style="color: #008000;">;</span>
            <span style="color: #6666cc; font-weight: bold;">byte</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> buffer <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> <span style="color: #6666cc; font-weight: bold;">byte</span><span style="color: #008000;">&#91;</span>bSize<span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span>
            <span style="color: #0600FF; font-weight: bold;">while</span> <span style="color: #008000;">&#40;</span>pStream<span style="color: #008000;">.</span><span style="color: #0000FF;">Read</span><span style="color: #008000;">&#40;</span>buffer, <span style="color: #FF0000;">0</span>, bSize<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&gt;</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span> <span style="color: #008000;">&#125;</span>
&nbsp;
            Console<span style="color: #008000;">.</span><span style="color: #0000FF;">ReadKey</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">void</span> pStream_BytesRead<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">object</span> sender, 
                                      ProgressStreamReportEventArgs args<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            Console<span style="color: #008000;">.</span><span style="color: #0000FF;">WriteLine</span><span style="color: #008000;">&#40;</span>
                <span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Format</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;{2} bytes moved | {0} of {1} total&quot;</span>, 
                    args<span style="color: #008000;">.</span><span style="color: #0000FF;">StreamPosition</span>, 
                    args<span style="color: #008000;">.</span><span style="color: #0000FF;">StreamLength</span>, 
                    args<span style="color: #008000;">.</span><span style="color: #0000FF;">BytesMoved</span>
                <span style="color: #008000;">&#41;</span>
           <span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://mel-green.com/2010/01/progressstream/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Call of Duty: Modern Warfare 2 Multiple Profiles</title>
		<link>http://mel-green.com/2009/11/modern-warfare-2-multiple-profiles-loader/</link>
		<comments>http://mel-green.com/2009/11/modern-warfare-2-multiple-profiles-loader/#comments</comments>
		<pubDate>Sat, 14 Nov 2009 21:37:15 +0000</pubDate>
		<dc:creator>Mel</dc:creator>
				<category><![CDATA[Computers]]></category>
		<category><![CDATA[Games]]></category>
		<category><![CDATA[Call of Duty]]></category>
		<category><![CDATA[Loader]]></category>
		<category><![CDATA[Modern Warfare 2]]></category>
		<category><![CDATA[Multiple Profile]]></category>

		<guid isPermaLink="false">http://mel-green.com/?p=431</guid>
		<description><![CDATA[I created this launcher to provide multiple profiles for the single player game of Call of Duty: Modern Warfare 2. As there are multiple ways to acquire this game and install it, this may not work for everyone. Instructions: Download the zip file here Extract the contents to the install directory for Modern Warfare 2 [...]]]></description>
			<content:encoded><![CDATA[<p><img class="aligncenter size-full wp-image-435" title="Modern Warfare 2 Launcher" src="http://mel-green.com/wp-content/uploads/2009/11/mw2_launcher.png" alt="Modern Warfare 2 Launcher" width="460" height="310" /></p>
<p>I created this launcher to provide multiple profiles for the single player game of <em>Call of Duty: Modern Warfare 2</em>. As there are multiple ways to acquire this game and install it, this may not work for everyone.</p>
<p><strong>Instructions:</strong></p>
<ol>
<li>Download the zip file <a href="http://mel-green.com/Uploads/MW2_Multiple_Profiles_Loader.zip">here</a></li>
<li>Extract the contents to the install directory for <em>Modern Warfare 2</em></li>
<li>Create a shortcut on your desktop for <em>MW2 Loader.exe</em> and use it instead of launching the game directly.</li>
<li>When you click &#8220;Launch&#8221; and you&#8217;re asked to select a program or shortcut to run, navigate to the shortcut you would normally use to launch the single player game and select it. This will ensure that the game is run through Steam.</li>
<li>If for some reason you need to re-select a program or shortcut to run, you can do this by resetting the Loader. To do this you need to delete the <em>profiles.xml</em> file located in:<br /> <strong>(XP)</strong> <em>C:\Documents and Settings\All Users\Application Data\MW2_Loader\</em> <br /> <strong>(Vista)</strong> <em>C:\Program Data\MW2_Loader\</em> <br /> <strong>(Win7)</strong> <em>C:\ProgramData\MW2_Loader\</em></li>
<li>If you don&#8217;t already have the Microsoft .Net Framework 3.5 installed on your system, you will need to download it <a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=333325FD-AE52-4E35-B531-508D977D32A6&amp;displaylang=en">here</a></li>
</ol>
<p>Here&#8217;s a picture of what the game directory should look like after you&#8217;ve extracted the file:<br />
<img class="aligncenter size-full wp-image-435" title="mw2_dir" src="http://mel-green.com/wp-content/uploads/2009/11/mw2_dir1.png" alt="mw2_dir" width="491" height="641" /></p>
<p>Note: This only works for the PC version of the game and as far as I know only changes your Single Player profile, which includes all game settings and saved games.</p>
<p>If you have any questions or comments please feel free to post them below. Feedback and praise is always welcome!</p>
<p><strong><span style="color: #0000ff;">Updates</span></strong><span style="color: #0000ff;">:</span></p>
<p><span style="color: #000000;"><strong>2009-11-16:</strong></span></p>
<ul>
<li>Fixed <em><span style="color: #808080;">System.IO.FileFormatException: The image format is unrecognized</span></em> bug.</li>
</ul>
<p><strong>2009-11-15: </strong></p>
<ul>
<li>Fixed bug with new profiles disappearing when not launched.</li>
<li>Changed program icon in an attempt to better support Vista and WPF.</li>
<li>Implemented ability to choose program or shortcut to launch after loading a profile. You should use this to select the shortcut you regularly use to launch the game with Steam.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://mel-green.com/2009/11/modern-warfare-2-multiple-profiles-loader/feed/</wfw:commentRss>
		<slash:comments>203</slash:comments>
		</item>
		<item>
		<title>WPF: Simple Vista Image Viewer</title>
		<link>http://mel-green.com/2009/09/wpf-simple-vista-image-viewer/</link>
		<comments>http://mel-green.com/2009/09/wpf-simple-vista-image-viewer/#comments</comments>
		<pubDate>Fri, 25 Sep 2009 21:40:55 +0000</pubDate>
		<dc:creator>Mel</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[XAML]]></category>
		<category><![CDATA[Image]]></category>
		<category><![CDATA[Viewer]]></category>
		<category><![CDATA[Zoom]]></category>

		<guid isPermaLink="false">http://mel-green.com/?p=398</guid>
		<description><![CDATA[Download source code &#8211; 72.2 KB Download sample app &#8211; 67.8 KB What does it do? This lightweight WPF UserControl will display a single image in a manner similar to the Windows Photo Gallery. It doesn&#8217;t manage more than one image in a gallery or slideshow fashion however, but it does: Zoom In/Out both with [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://mel-green.com/wp-content/uploads/2009/09/ImageViewSample.png" alt="Preview of WPF Image Viewer" title="Preview of WPF Image Viewer" width="397" height="450" class="size-full wp-image-399" /></p>
<p/>
<a href="http://mel-green.com/wp-content/uploads/ImageViewer.zip">Download source code &#8211; 72.2 KB</a><br />
<a href="http://mel-green.com/wp-content/uploads/ImageViewerSample.zip">Download sample app &#8211; 67.8 KB</a></p>
<h4 style="margin-bottom: 15px;">What does it do?</h4>
<p>This lightweight WPF UserControl will display a single image in a manner similar to the <em>Windows Photo Gallery</em>. It doesn&#8217;t manage more than one image in a gallery or slideshow fashion however, but it does:<br />
<strong>
<ul>
<li>Zoom In/Out both with the mouse and with a slider control</li>
<li>Pan the image with the mouse</li>
<li>Rotate the image clockwise or counter-clockwise 90 degrees</li>
<li>Keep the image fully visible in the display area when not in zoom mode</li>
</ul>
<p></strong></p>
<p></p>
<h4 style="margin-bottom: 15px;">How can I use it?</h4>
<p>You can use this image viewer in any WPF application with little effort since it&#8217;s built as a WPF UserControl. By leveraging the <strong>WPF Interoperability</strong> in WinForms it&#8217;s possible to use this in a Windows Forms application as well, see the article <a href="http://www.switchonthecode.com/tutorials/wpf-tutorial-using-wpf-in-winforms">here</a> for instructions on accomplishing that.</p>
<p>To get started using the control, download the source project from the above link. You can play around with the sample application to see an example of how to use the image viewer. The sample program simply provides a Window for the control and sets the path for the image to display; the control does all the rest.</p>
<p>To use the control in your own application you simply need to include the necessary source files in your own project or solution (<em>CgsImageViewer.xaml(.cs)</em>, <em>PanAndZoom.cs</em>, and the images for the buttons). Once you&#8217;ve got them, you&#8217;ll begin by inserting the viewer into your XAML, like so:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Window</span> <span style="color: #000066;">x:Class</span>=<span style="color: #ff0000;">&quot;ImageViewer.Window1&quot;</span></span>
<span style="color: #009900;">    <span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;</span></span>
<span style="color: #009900;">    <span style="color: #000066;">xmlns:x</span>=<span style="color: #ff0000;">&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;</span></span>
<span style="color: #009900;">    <span style="color: #000066;">xmlns:iv</span>=<span style="color: #ff0000;">&quot;clr-namespace:ImageViewer&quot;</span></span>
<span style="color: #009900;">    <span style="color: #000066;">Title</span>=<span style="color: #ff0000;">&quot;Image Viewer Sample&quot;</span> <span style="color: #000066;">Height</span>=<span style="color: #ff0000;">&quot;418&quot;</span> <span style="color: #000066;">Width</span>=<span style="color: #ff0000;">&quot;410&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Grid<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;iv:CgsImageViewer</span> <span style="color: #000066;">x:Name</span>=<span style="color: #ff0000;">&quot;cgsImageViewer&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Grid<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Window<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>This is just placing the image viewer in a window and giving it a name. Now to load up an image all that you need to do is provide a path to the image or a <em>BitmapImage</em> object. You can do this in the business code or in the XAML by means of a data binding. Here&#8217;s an example of setting the image in the business code:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">cgsImageViewer<span style="color: #008000;">.</span><span style="color: #0000FF;">CurrentImagePath</span> <span style="color: #008000;">=</span> <span style="color: #666666;">@&quot;c:\test images\cat-plans-your-doom.jpg&quot;</span><span style="color: #008000;">;</span></pre></div></div>

<p>That&#8217;s all you really need to know to use the image viewer. Continue on for some extra info.</p>
<p></p>
<h4 style="margin-bottom: 15px;">Class Members you might want to know about:</h4>
<ul>
<li style="list-style: none;"><img src="http://i.msdn.microsoft.com/ms619221.pubproperty(en-us,VS.90).gif" />&nbsp;<strong>CurrentImage</strong> &#8211; Gets or sets the current <a href="http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.bitmapimage.aspx">BitmapImage</a> used by the viewer.</li>
<li style="list-style: none;"><img src="http://i.msdn.microsoft.com/ms619221.pubproperty(en-us,VS.90).gif" />&nbsp;<strong>CurrentImagePath</strong> &#8211; Gets or sets a string representing the Uri to load an image from.</li>
<li style="list-style: none; margin-bottom: 5px;"><img src="http://i.msdn.microsoft.com/ms619221.pubproperty(en-us,VS.90).gif" />&nbsp;<strong>ZoomLevel</strong> &#8211; Gets or sets a double representing the percentage to zoom.</li>
<li style="list-style: none;"><img src="http://i.msdn.microsoft.com/ms619221.pubmethod(en-us,VS.90).gif" />&nbsp;<strong>ScaleToFit</strong> &#8211; Resizes the image to fit within the visible bounds.</li>
<li style="list-style: none;"><img src="http://i.msdn.microsoft.com/ms619221.pubmethod(en-us,VS.90).gif" />&nbsp;<strong>RotateLeft</strong> &#8211; Rotates the image 90 degrees to the left and scales it to fit.</li>
<li style="list-style: none;"><img src="http://i.msdn.microsoft.com/ms619221.pubmethod(en-us,VS.90).gif" />&nbsp;<strong>RotateRight</strong> &#8211; Rotates the image 90 degrees to the right and scales it to fit.</li>
</ul>
<p>
<em>(Note: The code for panning and zooming was found <a href="http://blogs.windowsclient.net/joeyw/archive/2008/08/05/pan-and-zoom-deepzoom-style-in-wpf.aspx">here</a>)</em>
</p>
<p></p>
<h4 style="margin-bottom: 15px;">A little background and explanation:</h4>
<p>I wrote this control in a grand total of about two days, which included testing. It was written for use in a WPF project I&#8217;m currently working on where users needed to be able to preview graphic files inside the program. I decided to make something that could be re-used and would provide simple viewing capabilities.</p>
<p>So here you go. If you&#8217;ve used it and like it why not leave a comment or trackback. If you find any bugs or have some ideas to improve on it let me know. I&#8217;m always looking to make things better!</p>
]]></content:encoded>
			<wfw:commentRss>http://mel-green.com/2009/09/wpf-simple-vista-image-viewer/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>WPF: CheckBox as GroupBox Header</title>
		<link>http://mel-green.com/2009/08/wpf-checkbox-as-groupbox-header/</link>
		<comments>http://mel-green.com/2009/08/wpf-checkbox-as-groupbox-header/#comments</comments>
		<pubDate>Fri, 07 Aug 2009 23:24:27 +0000</pubDate>
		<dc:creator>Mel</dc:creator>
				<category><![CDATA[Software]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[XAML]]></category>
		<category><![CDATA[Binding]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[CheckBox]]></category>
		<category><![CDATA[Enabled]]></category>
		<category><![CDATA[GroupBox]]></category>

		<guid isPermaLink="false">http://mel-green.com/?p=383</guid>
		<description><![CDATA[This is a followup post to the one I wrote on Enabling Controls with a CheckBox. In that post we created some XAML that would enable/disable controls in the GUI based on the IsChecked property of a checkbox. Here&#8217;s an enhancement to that: So what we&#8217;re doing is giving the controls on our dialog a [...]]]></description>
			<content:encoded><![CDATA[<p>This is a followup post to the one I wrote on <a href="http://mel-green.com/2009/07/wpf-bind-control-enabled-to-checkbox-ecked/">Enabling Controls with a CheckBox</a>. In that post we created some XAML that would enable/disable controls in the GUI based on the <em>IsChecked</em> property of a checkbox.</p>
<p>Here&#8217;s an enhancement to that:</p>
<p><img src="http://mel-green.com/wp-content/uploads/2009/08/chk_gbx_enabled.png" alt="Checkbox as header for Groupbox" width="380" height="184" class="size-full wp-image-385" /></p>
<p>So what we&#8217;re doing is giving the controls on our dialog a nice visual grouping letting the user know that they&#8217;re associated. The <strong>GroupBox</strong> element has long existed to fulfill this need. However, with this little XAML change it also doubles as a sort of access control for the items it contains.</p>
<p>Here&#8217;s the XAML:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;GroupBox</span> <span style="color: #000066;">Padding</span>=<span style="color: #ff0000;">&quot;5&quot;</span> <span style="color: #000066;">HorizontalAlignment</span>=<span style="color: #ff0000;">&quot;Stretch&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;GroupBox.Header<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;CheckBox</span> <span style="color: #000066;">x:Name</span>=<span style="color: #ff0000;">&quot;chkEnableBackup&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>Run Backup Sets<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/CheckBox<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/GroupBox.Header<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;StackPanel<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;StackPanel</span> <span style="color: #000066;">Orientation</span>=<span style="color: #ff0000;">&quot;Horizontal&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Label</span> <span style="color: #000066;">Margin</span>=<span style="color: #ff0000;">&quot;12,0,0,0&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>Run backup every<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Label<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ComboBox</span> <span style="color: #000066;">Width</span>=<span style="color: #ff0000;">&quot;70&quot;</span> <span style="color: #000066;">SelectedIndex</span>=<span style="color: #ff0000;">&quot;0&quot;</span></span>
<span style="color: #009900;">            <span style="color: #000066;">IsEnabled</span>=<span style="color: #ff0000;">&quot;{Binding ElementName=chkEnableBackup, Path=IsChecked}&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ComboBoxItem<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Minute<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ComboBoxItem<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ComboBoxItem<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Hour<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ComboBoxItem<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ComboBoxItem<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Day<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ComboBoxItem<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ComboBox<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/StackPanel<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;StackPanel</span> <span style="color: #000066;">Margin</span>=<span style="color: #ff0000;">&quot;12,10,0,0&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Label<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Path to Backup:<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Label<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;TextBox</span> <span style="color: #000066;">Width</span>=<span style="color: #ff0000;">&quot;200&quot;</span> <span style="color: #000066;">Margin</span>=<span style="color: #ff0000;">&quot;5,0,0,0&quot;</span></span>
<span style="color: #009900;">            <span style="color: #000066;">IsEnabled</span>=<span style="color: #ff0000;">&quot;{Binding ElementName=chkEnableBackup, Path=IsChecked}&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/StackPanel<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/StackPanel<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/GroupBox<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>So all we&#8217;ve done here is add the <strong>CheckBox</strong> to the <strong><em>&lt;GroupBox.Header&gt;</em> </strong>element of the <strong>GroupBox</strong>. Pretty slick!</p>
<p>This little technique is complete UI Candy and in my opinion illustrates one of the many powerful features of WPF: the ability to customize the GUI in any way you want, down to any level!</p>
]]></content:encoded>
			<wfw:commentRss>http://mel-green.com/2009/08/wpf-checkbox-as-groupbox-header/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic page generated in 0.837 seconds. -->
<!-- Cached page generated by WP-Super-Cache on 2012-05-19 01:50:40 -->

