<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>I Love To Code</title>
	<atom:link href="http://iltc.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://iltc.wordpress.com</link>
	<description>Just another WPF blog</description>
	<lastBuildDate>Thu, 23 Jun 2011 11:49:18 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='iltc.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>I Love To Code</title>
		<link>http://iltc.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://iltc.wordpress.com/osd.xml" title="I Love To Code" />
	<atom:link rel='hub' href='http://iltc.wordpress.com/?pushpress=hub'/>
		<item>
		<title>.Net 4.0 Printing Made Easy &#8211; Part 1 &#8211; Introduction</title>
		<link>http://iltc.wordpress.com/2011/02/27/net-printing-made-easy-part-1-introduction/</link>
		<comments>http://iltc.wordpress.com/2011/02/27/net-printing-made-easy-part-1-introduction/#comments</comments>
		<pubDate>Sun, 27 Feb 2011 22:26:28 +0000</pubDate>
		<dc:creator>ilovetocode</dc:creator>
				<category><![CDATA[.Net 4.0]]></category>
		<category><![CDATA[Printing]]></category>
		<category><![CDATA[Source Code]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://iltc.wordpress.com/?p=141</guid>
		<description><![CDATA[Welcome to the fist part of my '.Net Printing Made Easy' series. In this part we'll take a quick look at the .Net printing support, what it does do for us and just as important, what it doesn't do for us.

In .Net 3.0 we were given a great new printing framework based around XPS documents. This immediately opened up a world of vector based printing where you can print your WPF vector controls and have them appear as sharp as ever, or if printing to an XPS or PDF document, your print out will be preserved in its full vector glory. What makes this even better is that you as a developer don't have to worry about any of this, you just send your data off to one of the many methods provided and the rest is done for you. There are of course some instances where you can't print raw vector data out and need to handled rasterised data. This too is very simple and there are a few tricks you can use to make it even easier.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=iltc.wordpress.com&amp;blog=5112722&amp;post=141&amp;subd=iltc&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Welcome to the fist part of my &#8216;.Net 4.0 Printing Made Easy&#8217; series. In this part we&#8217;ll take a quick look at the .Net printing support, what it does do for us and just as important, what it doesn&#8217;t do for us.</p>
<p>In .Net 3.0 we were given a great new printing framework based around XPS documents. This immediately opened up a world of vector based printing where you can print your WPF vector controls and have them appear as sharp as ever, or if printing to an XPS or PDF document, your print out will be preserved in its full vector glory. What makes this even better is that you as a developer don&#8217;t have to worry about any of this, you just send your data off to one of the many methods provided and the rest is done for you. There are of course some instances where you can&#8217;t print raw vector data out and need to handled rasterised data. This too is very simple and there are a few tricks you can use to make it even easier.</p>
<p><a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2filtc.wordpress.com%2f2011%2f02%2f27%2fnet-printing-made-easy-part-1-introduction%2f"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url%3Dhttp%253a%252f%252filtc.wordpress.com%252f2011%252f02%252f27%252fnet-printing-made-easy-part-1-introduction%252f&amp;border=F78B0C&amp;fgcolor=818181&amp;bgcolor=FFFFFF&amp;cfgcolor=FFFFFF&amp;cbgcolor=818181" border="0" alt="kick it on DotNetKicks.com" /></a></p>
<p><span id="more-141"></span></p>
<h2>Using the PrintDialog</h2>
<p>One of the first things you&#8217;ll want to do when it comes to printing is to choose a printer. There are a few different ways of enumerating printers visible to a machine and the method that is best for you will depend on the approach you take to printing in your application. The first method and perhaps the simplest is the good old <a title="MSDN: System.Windows.Controls.PrintDialog" href="http://msdn.microsoft.com/en-us/library/system.windows.controls.printdialog.aspx">PrintDialog</a> class defined in the <em>System.Windows.Controls</em> namespace (PresentationFramework.dll).</p>
<p>The <a title="MSDN: System.Windows.Controls.PrintDialog" href="http://msdn.microsoft.com/en-us/library/system.windows.controls.printdialog.aspx">PrintDialog</a> object gives us a handy, pre-built dialog for choosing and customising a printer and page setup. The dialog can then be used to send your job to the selected printer with very little coding required (of course you&#8217;ll still need to code the generation of the content to be printed). Below is a very simple method that creates a new instance of a <a title="MSDN: System.Windows.Controls.PrintDialog" href="http://msdn.microsoft.com/en-us/library/system.windows.controls.printdialog.aspx">PrintDialog</a> and displays it. The OnShowPrintDialogButtonClick method is set as the click event handler in the Window&#8217;s XAML. Those of you familiar with dialogs in .Net will be familiar with this. The result of the call to <a title="MSDN: PrintDialog.ShowDialog()" href="http://msdn.microsoft.com/en-us/library/system.windows.controls.printdialog.showdialog.aspx">ShowDialog()</a> will give us a <a title="MSDN: Nullable Types" href="http://msdn.microsoft.com/en-us/library/2cf62fcy.aspx">Nullable&lt;Boolean&gt;</a> which can be used to determine whether clicked the &#8216;Ok&#8217; button or not (and the reason using the explicit quality operator).<br />
<code><br />
private void OnShowPrintDialogButtonClick(object sender, EventArgs e)<br />
{<br />
PrintDialog printDialog = new PrintDialog();<br />
if (printDialog.ShowDialog() == false)<br />
return;</code></p>
<p><code> // ..<br />
}<br />
</code></p>
<p>Here is the print dialog in all its glory:</p>
<div id="attachment_147" class="wp-caption aligncenter" style="width: 310px"><a href="http://iltc.files.wordpress.com/2011/02/1-printdialog.png"><img class="size-medium wp-image-147" title="1-PrintDialog" src="http://iltc.files.wordpress.com/2011/02/1-printdialog.png?w=300&#038;h=271" alt="The PrintDialog on screen." width="300" height="271" /></a><p class="wp-caption-text">PrintDialog</p></div>
<p>It&#8217;s not much to look at but in just a few lines of code you have a complete list of available printers along with access to ceach device&#8217;s configuration settings as well as a few other treats. All of the printer and page setup data can be accessed through the dialog&#8217;s <a title="MSDN: PrintDialog.PrintTicket" href="http://msdn.microsoft.com/en-us/library/system.windows.controls.printdialog.printticket(v=VS.100).aspx">PrintTicket</a> property which returns a <a title="MSDN: System.Printing.PrintTicket" href="http://msdn.microsoft.com/en-us/library/system.printing.printticket.aspx">PrintTicket</a> object, defined in the System.Printing namespace (ReachFramework.dll). In a nutshell the print ticket details the settings and configuration for the print job as defined by the user from the print dialog, namely paper size, orientation etc. This print ticket will be used a lot when generating content to be printed.</p>
<h2>Finding Available Print Queues</h2>
<p>The <a title="MSDN: PrintDialog" href="http://msdn.microsoft.com/en-us/library/system.windows.controls.printdialog.aspx">PrintDialog</a> isn&#8217;t always going to be suited to your needs, if for example you&#8217;re creating a rich print preview control a la Microsoft Word 2010 etc. For this you&#8217;ll need to provide configuration options for all the features you&#8217;ll want to support. The first step in this process is to get a list of available printers, which we do so through a <a title="MSDN: PrintServer" href="http://msdn.microsoft.com/en-us/library/system.printing.printserver.aspx">PrintServer</a> defined in the System.Printing namespace (System.Printing.dll). The <a title="PrintServer" href="http://msdn.microsoft.com/en-us/library/system.printing.printserver.aspx">PrintServer</a> object is quite powerful and can be used for myriad print queue related activities, but for now all we need is a list of <a title="MSDN: PrintQueue" href="http://msdn.microsoft.com/en-us/library/system.printing.printqueue.aspx">PrintQueue</a> objects known to the print server. The code snippet below demonstrates the retrieval of a collection of printers (print queues).</p>
<p><code> private IEnumerable GetPrintQueues()<br />
{<br />
PrintServer printServer = new PrintServer();</code></p>
<p><code> PrintQueueCollection printQueues<br />
= printServer.GetPrintQueues(new[]<br />
{<br />
EnumeratedPrintQueueTypes.Local,<br />
EnumeratedPrintQueueTypes.Connections<br />
});</code></p>
<p><code> </code></p>
<p><span style="font-family:monospace;"> return printQueues;<br />
</span><span style="font-family:monospace;">}</span></p>
<p>There are several overloads for the <a title="MSDN: GetPrintQueues Overloads" href="http://msdn.microsoft.com/en-us/library/system.printing.printserver.getprintqueues.aspx">GetPrintQueues()</a> method, the one you use will depend entirely on your situation. Here we use a method that allows us to pass in <a title="MSND: EnumeratedPrintQueueTypes" href="http://msdn.microsoft.com/en-us/library/system.printing.enumeratedprintqueuetypes.aspx">EnumeratedPrintQueueTypes</a> values that ensure we get both local and network printers. You can take the collection of print queues and present them in the UI somehow allowing the user to select their desired printer. Like the <a title="MSDN: PrintDialog" href="http://msdn.microsoft.com/en-us/library/system.windows.controls.printdialog.aspx">PrintDialog</a>, a <a title="MSDN: PrintQueue" href="http://msdn.microsoft.com/en-us/library/system.printing.printqueue.aspx">PrintQueue</a> also exposes a print ticket object, UserPrintTicket and DefaultPrintTicket, allowing you to access and modify printer and page settings, something you will need later when you come to provide configuration options such as selected page size and orientation etc.</p>
<h2>Finding the User&#8217;s Default Print Queue</h2>
<p>A nice little touch we can add here is to discover the user&#8217;s default printer and use that as the default in the app. Using the <a title="MSDN: LocalPrintServer" href="http://www.google.co.uk/url?sa=t&amp;source=web&amp;cd=1&amp;ved=0CBYQFjAA&amp;url=http%3A%2F%2Fmsdn.microsoft.com%2Fen-us%2Flibrary%2Fsystem.printing.localprintserver.aspx&amp;ei=YspqTf_nGIGAOo_q8IwL&amp;usg=AFQjCNH0UrRugzOmPtdWOBqkhPefGdvcCg">LocalPrintServer</a> class&#8217; static method <a title="MSDN: LocalPrintServer.GetDefaultPrintQueue()" href="http://msdn.microsoft.com/en-us/library/system.printing.localprintserver.getdefaultprintqueue.aspx">GetDefaultPrintQueue</a>, it&#8217;s easy to find.</p>
<p><code> private PrintQueue GetDefaultPrintQueue()<br />
{<br />
return LocalPrintServer.GetDefaultPrintQueue();<br />
}</code></p>
<h2>Using a PrintTicket</h2>
<p>Now that you have a list of printers and the local default printer, the next step is to allow the user to change aspects of the active <a title="MSDN: PrintTicket" href="http://msdn.microsoft.com/en-us/library/system.printing.printticket.aspx">PrintTicket</a> object. A print ticket is a collection of properties defining features of the print job. These include settings such as page orientation, page size etc. Many of the properties won&#8217;t be of interest to you and can safely be ignored. We&#8217;ll look at two properties here: page orientation (<a title="MSDN: PrintTicket.PageOrientation" href="http://msdn.microsoft.com/en-us/library/system.printing.printticket.pageorientation.aspx">PageOrientation</a>) and page size (<a title="MSDN: PrintTicket.PageMediaSize" href="http://msdn.microsoft.com/en-us/library/system.printing.printticket.pagemediasize.aspx">PageMediaSize</a>).</p>
<p>To get a print ticket you can either create one or use an existing one. The easiest way to get a print ticket object is through the <a title="MSDN: PrintTicket.UserPrintTicket" href="http://msdn.microsoft.com/en-us/library/system.printing.printqueue.userprintticket.aspx">UserPrintTicket</a> property (or  <a title="MSDN: PrintTicket.DefaultPrintTicket" href="http://msdn.microsoft.com/en-us/library/system.printing.printqueue.defaultprintticket.aspx">DefaultPrintTicket</a> property if the former is null) of the active <a title="MSDN: PrintQueue" href="http://msdn.microsoft.com/en-us/library/system.printing.printqueue.aspx">PrintQueue</a>. In some rare instances, reading either of these properties may result in a <a title="MSDN: PrintSystemException" href="http://msdn.microsoft.com/en-us/library/system.printing.printsystemexception.aspx">PrintSystemException</a> (System.Printing namespace, ReachFramework.dll) being thrown when the printer driver doesn&#8217;t provide valid values. In this instance just create a new <a title="MSDN: PrintTicket" href="http://msdn.microsoft.com/en-us/library/system.printing.printticket.aspx">PrintTicket</a> object and use that. Print tickets are used again a bit later on, when it comes to sending data to the printer, something we&#8217;ll cover in part 2.</p>
<h2>Measuring Capability with PrintCapabilities</h2>
<p>When dealing with settings in a print ticket, you first need to know what the target print queue is capable of. There&#8217;s no point showing options for duplexing and sending those commands if the target printer doesn&#8217;t support duplexing in the first place. To gain a heads-up on the target printer&#8217;s capabilities, there exist a <a title="MSDN: PrintCapabilities" href="http://msdn.microsoft.com/en-us/library/system.printing.printcapabilities.aspx">PrintCapabilities</a> class in the System.Printing namespace (Reachframework.dll). This is a sealed class with read-only properties defining the features supported by a given print queue. A <a title="MSDN: PrintCapabilities" href="http://msdn.microsoft.com/en-us/library/system.printing.printcapabilities.aspx">PrintCapabilities</a> object can now be used to remove features which are not supported.</p>
<p><code> var p</code>ageMediaSizes<br />
= pc.PageMediaSizeCapability.OrderBy(<br />
i =&gt; i.PageMediaSizeName).Select(<br />
i =&gt; { return i.PageMediaSizeName.ToString(); }).ToList();</p>
<h2>Putting it all together</h2>
<p>I&#8217;ve created a simple demo app that puts these concepts together giving a practical example. The app comprises of a window with a few simple controls with a view model that defines the properties and methods described above. There&#8217;s a huge amount going on here, but hopefully it gives a good introduction to some of the common classes you&#8217;ll see when dealing with printing. The following class diagram below gives an overview of the app.</p>
<p><a href="http://iltc.files.wordpress.com/2011/02/classdiagram11.jpg"><img class="aligncenter size-medium wp-image-154" title="Application Class Diagram" src="http://iltc.files.wordpress.com/2011/02/classdiagram11.jpg?w=300&#038;h=178" alt="Application Class Diagram" width="300" height="178" /></a></p>
<p>Here&#8217;s a preview of the app running.</p>
<p><a href="http://iltc.files.wordpress.com/2011/02/screenshot.jpg"><img class="aligncenter size-medium wp-image-157" title="Screenshot" src="http://iltc.files.wordpress.com/2011/02/screenshot.jpg?w=300&#038;h=100" alt="Application Screenshot" width="300" height="100" /></a></p>
<p><a title="Download Application Source" href="http://code.google.com/p/ilovetocode/downloads/detail?name=Printing-Part1_.Net4_VS2010.zip&amp;can=2&amp;q=">Download </a>the .Net 4, Visual Studio 2010 source for this application.</p>
<h2>Next Steps</h2>
<p>In the next part I&#8217;ll look at actually sending something to a print queue and look at the different approaches you can take to this.</p>
<p><a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2filtc.wordpress.com%2f2011%2f02%2f27%2fnet-printing-made-easy-part-1-introduction%2f"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url%3Dhttp%253a%252f%252filtc.wordpress.com%252f2011%252f02%252f27%252fnet-printing-made-easy-part-1-introduction%252f&amp;border=F78B0C&amp;fgcolor=818181&amp;bgcolor=FFFFFF&amp;cfgcolor=FFFFFF&amp;cbgcolor=818181" border="0" alt="kick it on DotNetKicks.com" /></a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/iltc.wordpress.com/141/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/iltc.wordpress.com/141/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/iltc.wordpress.com/141/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/iltc.wordpress.com/141/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/iltc.wordpress.com/141/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/iltc.wordpress.com/141/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/iltc.wordpress.com/141/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/iltc.wordpress.com/141/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/iltc.wordpress.com/141/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/iltc.wordpress.com/141/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/iltc.wordpress.com/141/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/iltc.wordpress.com/141/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/iltc.wordpress.com/141/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/iltc.wordpress.com/141/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=iltc.wordpress.com&amp;blog=5112722&amp;post=141&amp;subd=iltc&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://iltc.wordpress.com/2011/02/27/net-printing-made-easy-part-1-introduction/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">ilovetocode</media:title>
		</media:content>

		<media:content url="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url%3Dhttp%253a%252f%252filtc.wordpress.com%252f2011%252f02%252f27%252fnet-printing-made-easy-part-1-introduction%252f&#38;border=F78B0C&#38;fgcolor=818181&#38;bgcolor=FFFFFF&#38;cfgcolor=FFFFFF&#38;cbgcolor=818181" medium="image">
			<media:title type="html">kick it on DotNetKicks.com</media:title>
		</media:content>

		<media:content url="http://iltc.files.wordpress.com/2011/02/1-printdialog.png?w=300" medium="image">
			<media:title type="html">1-PrintDialog</media:title>
		</media:content>

		<media:content url="http://iltc.files.wordpress.com/2011/02/classdiagram11.jpg?w=300" medium="image">
			<media:title type="html">Application Class Diagram</media:title>
		</media:content>

		<media:content url="http://iltc.files.wordpress.com/2011/02/screenshot.jpg?w=300" medium="image">
			<media:title type="html">Screenshot</media:title>
		</media:content>

		<media:content url="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url%3Dhttp%253a%252f%252filtc.wordpress.com%252f2011%252f02%252f27%252fnet-printing-made-easy-part-1-introduction%252f&#38;border=F78B0C&#38;fgcolor=818181&#38;bgcolor=FFFFFF&#38;cfgcolor=FFFFFF&#38;cbgcolor=818181" medium="image">
			<media:title type="html">kick it on DotNetKicks.com</media:title>
		</media:content>
	</item>
		<item>
		<title>.Net 4.0 Printing Made Easy &#8211; Part 0</title>
		<link>http://iltc.wordpress.com/2011/02/27/net-4-0-printing-made-easy-part-0/</link>
		<comments>http://iltc.wordpress.com/2011/02/27/net-4-0-printing-made-easy-part-0/#comments</comments>
		<pubDate>Sun, 27 Feb 2011 22:18:11 +0000</pubDate>
		<dc:creator>ilovetocode</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://iltc.wordpress.com/?p=134</guid>
		<description><![CDATA[When asked about printing, most developers will recoil in horror and rather avoid the topic. For some us though, we don&#8217;t have any choice but to tackle the problem full on. Luckily, in true .Net style, printing has become a much easier problem to take on. I recently undertook a large printing task that required [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=iltc.wordpress.com&amp;blog=5112722&amp;post=134&amp;subd=iltc&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>When asked about printing, most developers will recoil in horror and rather avoid the topic. For some us though, we don&#8217;t have any choice but to tackle the problem full on. Luckily, in true .Net style, printing has become a much easier problem to take on. I recently undertook a large printing task that required designing and architecting a printing framework that could be used in a rich desktop application, allowing pretty much any control in the application (third-party or in-house), to be printable through a common print preview view complete with WYSIWYG page setup, headers / footers etc etc. Quite a task!</p>
<p>As usual there is a wealth of information on the web on the topic of printing, although I found most of it to be quite disparate and specialised with very few complete examples and gotchas. In this series of posts I intend to cover as many aspects of printing as possible to try and give a better understanding and concrete examples, as a kind of map through the printing underworld. To this end, this series of posts will spare the detail in favour of providing a more general end-to-end look at printing with links to greater detail for those that are interested.</p>
<p>In <a title=".Net Printing Made Easy – Part 1 – Introduction" href="http://iltc.wordpress.com/2011/02/27/net-printing-made-easy-part-1-introduction/">part 1</a> I will try to give a brief overview of printing in WPF and get you started with some code for getting hold of a list of local printers and what you can do with that information.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/iltc.wordpress.com/134/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/iltc.wordpress.com/134/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/iltc.wordpress.com/134/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/iltc.wordpress.com/134/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/iltc.wordpress.com/134/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/iltc.wordpress.com/134/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/iltc.wordpress.com/134/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/iltc.wordpress.com/134/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/iltc.wordpress.com/134/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/iltc.wordpress.com/134/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/iltc.wordpress.com/134/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/iltc.wordpress.com/134/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/iltc.wordpress.com/134/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/iltc.wordpress.com/134/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=iltc.wordpress.com&amp;blog=5112722&amp;post=134&amp;subd=iltc&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://iltc.wordpress.com/2011/02/27/net-4-0-printing-made-easy-part-0/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">ilovetocode</media:title>
		</media:content>
	</item>
		<item>
		<title>Silverlight 2.0 Elliptical Control 3D!</title>
		<link>http://iltc.wordpress.com/2008/10/25/silverlight-20-elliptical-control-3d/</link>
		<comments>http://iltc.wordpress.com/2008/10/25/silverlight-20-elliptical-control-3d/#comments</comments>
		<pubDate>Sat, 25 Oct 2008 17:34:02 +0000</pubDate>
		<dc:creator>ilovetocode</dc:creator>
				<category><![CDATA[3D]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Silverlight 2.0]]></category>
		<category><![CDATA[Source Code]]></category>
		<category><![CDATA[.Net 3+]]></category>
		<category><![CDATA[Examples]]></category>

		<guid isPermaLink="false">http://iltc.wordpress.com/?p=90</guid>
		<description><![CDATA[Well it has been a busy time for me since my last post, so this one took a little longer to get out. Fuelled by the launch of Silverlight 2.0 and my desire to give it another go (being a WPF developer I was a little put off by the bareness of 1.0) and set [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=iltc.wordpress.com&amp;blog=5112722&amp;post=90&amp;subd=iltc&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Well it has been a busy time for me since my last post, so this one took a little longer to get out. Fuelled by the launch of Silverlight 2.0 and my desire to give it another go (being a WPF developer I was a little put off by the bareness of 1.0) and set about finding a little project I could undertake to help me learn the ropes. I had several ideas (read, future blog posts!), but the most logical was to port the 3D ellipse control I wrote in WPF across to Silverlight 2.0. It was a fairly straightforward port and a real eye-opener to what the differences between Silverlight and WPF really mean.</p>
<p>The biggest challenge was the lack of the <a href="http://msdn.microsoft.com/en-us/library/system.windows.media.media3d.aspx">Media3D</a> namespace. This prompted me to start building up a library of classes that aren&#8217;t included in Silverlight. So far I have created a Point3 (<a href="http://msdn.microsoft.com/en-us/library/system.windows.media.media3d.point3d.aspx">Point3D</a>), Vector3 (<a href="http://msdn.microsoft.com/en-us/library/system.windows.media.media3d.vector3d.aspx">Vector3D</a>) and Quaternion (<a href="http://msdn.microsoft.com/en-us/library/system.windows.media.media3d.quaternion.aspx">Quaternion</a>). They are all basic implementations at the moment and contain just enough functionality to allow me to create the sample.</p>
<p>To overcome the lack of <a href="http://msdn.microsoft.com/en-us/library/system.windows.media.media3d.viewport2dvisual3d.aspx">Viewport2DVisual3D</a>, I calculate the scale for each child control based on it&#8217;s depth in the scene. This is a bit of a hack rather than a proper perspective correct transformation as I didn&#8217;t have the time to spend creating a camera implementation and setting everything up properly. Instead I make do with a camera focal length and combine that with the z value of each object to calculate how big it should appear on the screen, otherwise you wouldn&#8217;t be able to tell which controls are further away from the screen. Using a <a href="http://msdn.microsoft.com/en-us/library/system.windows.media.scaletransform(VS.95).aspx">ScaleTransform</a> ensures that the control appears correctly, but with a sense of depth.</p>
<p><a href="http://msdn.microsoft.com/en-us/library/cc189087(VS.95).aspx#z_order">Z-ordering</a> is also taken care of, ensuring items deeper in to the scene appear underneath items which are closer to the screen. There are also a few little extras in there such as being able to animate the rotation of the ellipse, which when played around with can create some awesome effects.</p>
<p>The screenshot below shows the app running in full swing. Animation is enabled and a very small focal length is used, making the objects close to the camera appear much larger than those further back. There were around 200 buttons in the control at the time and it coped really well.</p>
<p style="text-align:center;"><a href="http://iltc.files.wordpress.com/2008/10/2008-10-24_ellipticallayoutpanel3d_silverlight_screenshot.png"><img class="size-medium wp-image-92 aligncenter" title="2008-10-24_ellipticallayoutpanel3d_silverlight_screenshot" src="http://iltc.files.wordpress.com/2008/10/2008-10-24_ellipticallayoutpanel3d_silverlight_screenshot.png?w=300&#038;h=262" alt="" width="300" height="262" /></a></p>
<p><a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2filtc.wordpress.com%2f2008%2f10%2f25%2fsilverlight-20-elliptical-control-3d%2f"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2filtc.wordpress.com%2f2008%2f10%2f25%2fsilverlight-20-elliptical-control-3d%2f&amp;border=F78B0C&amp;fgcolor=818181&amp;bgcolor=FFFFFF&amp;cfgcolor=FFFFFF&amp;cbgcolor=818181" border="0" alt="kick it on DotNetKicks.com" /></a></p>
<p style="text-align:left;"><span id="more-90"></span><strong>The Idea</strong></p>
<p style="text-align:left;">The idea of this project is to re-create the <a title="Read WPF Elliptical Layout Control - 3D!" rel="bookmark" href="http://iltc.wordpress.com/2008/10/11/wpf-elliptical-layout-control-3d/">WPF Elliptical Layout Control</a><strong> </strong>in Silverlight 2.0, giving me a chance to get my hands dirty with Silverlight and to discover what really is the difference between Silverlight and WPF.</p>
<p style="text-align:left;">After copying and pasting my code in to a new Silverlight project I quickly noticed that my XAML would need a bit of attention, which is when I realised the &#8216;ElementName&#8217; markup extension used in bindings is not included. I also used this as a chance to add a quick example of animating the rotation of the layout ellipse, as a carosuel isn&#8217;t much fun if it doesn&#8217;t go around by itself!</p>
<p style="text-align:left;"><strong>The Theory</strong></p>
<p style="text-align:left;">The lack of &#8216;ElementName&#8217; is easy to get around by creating a <a href="http://www.thejoyofcode.com/Workaround_for_missing_ElementName_in_Silverlight_2_0_Binding.aspx">BindingHelper</a>, a well documented topic. Something which took me by suprise was the lack of <a href="http://msdn.microsoft.com/en-us/library/system.windows.frameworkpropertymetadata.aspx">FrameworkPropertyMetadata</a> which was being used in almost all of my dependency properties. This allowed me to use the <a href="http://msdn.microsoft.com/en-us/library/system.windows.frameworkpropertymetadataoptions.aspx">FrameworkPropertyMetadataOptions.AffectsArrange</a> value when registering the dependency property, forcing an update of the control when the value of the property changed. To work around this I defined a <a href="http://msdn.microsoft.com/en-us/library/system.windows.propertychangedcallback.aspx">PropertyChangedCallback</a> method which then goes on to mark the control as needing an update by calling <a href="http://msdn.microsoft.com/en-us/library/system.windows.uielement.invalidatemeasure(VS.95).aspx">InvalidateMeasure</a> and <a href="http://msdn.microsoft.com/en-us/library/system.windows.uielement.invalidatearrange(VS.95).aspx">InvalidateArrange</a> methods. This is defined for any dependency property that will invalidate the control&#8217;s state when its value changes and defined in each property&#8217;s <a href="http://msdn.microsoft.com/en-us/library/system.windows.propertymetadata(VS.95).aspx">PropertyMetaData</a>.</p>
<pre class="brush: csharp;">
private static void EllipseDefinitionPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
    EllipseLayoutPanel3D ep = d as EllipseLayoutPanel3D;

    if (d != null)
    {
        ep.InvalidateMeasure();
        ep.InvalidateArrange();
    }
}
</pre>
<p style="text-align:left;">Another suprise was the lack of a <a href="http://msdn.microsoft.com/en-us/library/system.windows.uielement.cliptobounds.aspx">ClipToBounds</a> property, usually found on <a href="http://msdn.microsoft.com/en-us/library/system.windows.uielement.aspx">UIElement</a>. This property is used to determine whether its content can be rendered outside of its bounds (e.g. control with a negative margin in a Canvas), or whether clipping should occur. You can still achieve the same thing in Silverlight, but you have to do a little bit more work. Instead of ClipToBounds we have the <a href="http://msdn.microsoft.com/en-us/library/system.windows.uielement.clip(VS.95).aspx">UIElement.Clip</a> property of type <a href="http://msdn.microsoft.com/en-us/library/system.windows.media.geometry(VS.95).aspx">Geometry</a>. As our control is a plain old rectangle, we just need to create a <a href="http://msdn.microsoft.com/en-us/library/system.windows.media.rectanglegeometry(VS.95).aspx">RectangleGeometry</a> with a <a href="http://msdn.microsoft.com/en-us/library/system.windows.media.rectanglegeometry.rect(VS.95).aspx">Rect</a> which defines the bounds of the control, but because our control can take any size, we need to make sure we update the clip bounds to match.</p>
<p style="text-align:left;">Getting notified when the width or the height of the control changes is very simple, all we need to do is add a handler to the <a href="http://msdn.microsoft.com/en-us/library/system.windows.frameworkelement.sizechanged.aspx">FrameworkElement.SizeChanged</a> event, in the contrsuctor, and update the Clip property like so:</p>
<pre class="brush: csharp;">
private void EllipseLayoutPanel3D_SizeChanged(object sender, SizeChangedEventArgs e)
{
    RectangleGeometry rg = new RectangleGeometry();
    rg.Rect = new Rect(0d, 0d, e.NewSize.Width, e.NewSize.Height);
    Clip = rg;
}
</pre>
<p style="text-align:left;">The really interesting part of this implementation was getting around the fact that we have no 3D support in Silverlight. In the WPF version of the control I was able to make use of the various 3D controls to do all of the work when it comes to making things appear as if they are sat in a 3-dimensional space. In Silverlight though we do not have this luxury so we have to come up with a way of achieving the same thing. The obvious choice is to setup a 3D pipeline and camera system that we can use to properly calculate the position and scaling of objects as they move toward and away from the screen. The other option is to ignore the camera and take a short-cut for calculating the approximate scale of objects based on their depth.</p>
<p style="text-align:left;">I decided to take the second option as it&#8217;s much quicker and far easier. The problem we are trying to solve is how to determine a scale factor that should be applied to an object such that it appears at a perspectively correct size, i.e. the further in to the scene it is located, the smaller it appears on the screen. Without having a full camera and 3D projection pipeline, I calculate the scale of the object using an approach based on <a href="http://en.wikipedia.org/wiki/Thales_theorem">Thales&#8217; Theorem</a> (there&#8217;s a great explanation <a href="http://www.kirupa.com/developer/mx/perspective.htm">here</a>). This takes in to account the z value (depth) of an object and the focal length for an imaginary camera to calculate the scale of an object. Easy! There is an additonal check in my code which takes a -ve scale and adjusts it so as to avoid any strange rendering behavior. Here&#8217;s a look at the code which calculates the scale:</p>
<pre class="brush: csharp;">
double scale = (-FocalLength / (-FocalLength + rotatedPoint.Z));

if (scale &lt; 0d)
{
    scale = Math.Abs(scale) / 100d;
}
</pre>
<p> </p>
<p style="text-align:left;">When creating the <a href="http://msdn.microsoft.com/en-us/library/system.windows.media.scaletransform(VS.95).aspx">ScaleTransform</a>, and <a href="http://msdn.microsoft.com/en-us/library/system.windows.media.translatetransform(VS.95).aspx">TranslateTransform</a>, we have to take in to account the position of the layout ellipse to ensure that each child control appears in the correct position and with the correct scale. This is as simple as adding in the position of the layout ellipse&#8217;s origin to the control&#8217;s position when defining our transforms.</p>
<pre class="brush: csharp;">
TranslateTransform translate = new TranslateTransform();
translate.X = (rotatedPoint.X) + EllipseCentreX;
translate.Y = (rotatedPoint.Y) + EllipseCentreY;
...
ScaleTransform scaleTransform = new ScaleTransform();
scaleTransform.CenterX = rotatedPoint.X + EllipseCentreX;
scaleTransform.CenterY = rotatedPoint.Y + EllipseCentreY;
scaleTransform.ScaleX = scale;
scaleTransform.ScaleY = scale;
</pre>
<p style="text-align:left;">On the topic of transformations, I created a method for asserting a <a href="http://msdn.microsoft.com/en-us/library/system.windows.media.transform(VS.95).aspx">Transform</a> for a UIElement, just like the AssertTransform3D method in the WPF version of the control. The method looks at the <a href="http://msdn.microsoft.com/en-us/library/system.windows.uielement.rendertransform(VS.95).aspx">RenderTransform</a> property of the given UIElement and if the value is a Transform it is added in to a new <a href="http://msdn.microsoft.com/en-us/library/system.windows.media.transformgroup(VS.95).aspx">TransformGroup</a> which is then set as the value of the RenderTransform property. This TransformGroup is then inspected to see if it contains a Transform matching the type of the generic parameter T. If a match is found, the existing value is replaced with the new value (with the exception of when the new value is a null reference), otherwise the new transform is added to the TransformGroup.</p>
<p style="text-align:left;">The last thing we have to take care of is the <a href="http://msdn.microsoft.com/en-us/library/cc189087(VS.95).aspx#z_order">z ordering</a> of each item. Because we are manipulating 2D objects in a 2D space to appear 3D, they are all painted on the same surface. This is important because the order in which the controls are rendered will have an effect on their perceived depth. If one object appears to obscure another object, that object must be closer to the viewer than the object it is obscuring. If in your scene a control that is meant to be deep in to the scene is rendered on top of a control which is meant to be much closer to the screen, the perception of depth will be lost. This was taken care of for us in the Viewport3D control, but not this time. Luckily we can use the Canvas.ZIndexProperty attached property to set the z-index of a particular control. The lower the value, the higher the control appears in the rendering order, i.e. it will be rendered earlier.</p>
<p style="text-align:left;">The ZIndex property is an int, so we round the z value of the control&#8217;s position and use that as the z-index of the control.</p>
<pre class="brush: csharp;">
Canvas.SetZIndex(child, (int)Math.Round(rotatedPoint.Z));
</pre>
<p> </p>
<p style="text-align:left;">Animating the layout ellipse&#8217;s orientation was easily achieved using a <a href="http://msdn.microsoft.com/en-us/library/system.threading.timer(VS.95).aspx">Timer</a> in the main Page hosting the ellipse control, with a period equivalent to 60 frames per second. In the example this value is hard-coded but easy enough to make variable. Each time the timer callback is fired, it updates the value of the rotation sliders by an amount goverened by the speed slider, slidSpeed. Plain and simple.</p>
<pre class="brush: csharp;">
private Timer animationTimer;

private void tbtnAnimate_Click(object sender, RoutedEventArgs e)
{
    if (tbtnAnimate.IsChecked == true)
    {
        //Start up an animation, running @ 16fps
        animationTimer = new Timer(AnimationTimer_Callback, null, 0, 16);
    }
    else if (animationTimer != null)
    {
        //We're done with animation for now.
        animationTimer.Dispose();
    }
}

private void AnimationTimer_Callback(object state)
{
    Dispatcher.BeginInvoke(Update);
}

private void Update()
{
    double speed = slidSpeed.Value / 100d;

    //For each slider, if the value is off the scale, wrap it back around to 0.
    slidEllipseRotationX.Value = slidEllipseRotationX.Value + 1d &gt; slidEllipseRotationX.Maximum ? 0d : slidEllipseRotationX.Value + speed;
    slidEllipseRotationY.Value = slidEllipseRotationY.Value + 1d &gt; slidEllipseRotationY.Maximum ? 0d : slidEllipseRotationY.Value + speed;
    slidEllipseRotationZ.Value = slidEllipseRotationZ.Value + 1d &gt; slidEllipseRotationZ.Maximum ? 0d : slidEllipseRotationZ.Value + speed;
}
</pre>
<p> </p>
<p style="text-align:left;"><strong>The Solution</strong></p>
<p style="text-align:left;">Here I present a simple demonstration of the above in the attached solution. The solution contains a simple Page which hosts the custom 3D ellipse layout control. The ellipse layout control is included in the EllipiseLayoutPanel3D class and adds several dependency properties and a few methods to the Panel class. The Missing3D library is included as a dll at the moment, until I get a chance to fix it up. By all means check it out in <a href="http://www.red-gate.com/products/reflector/">Reflector</a>, although there&#8217;s not much to see there yet.</p>
<div id="attachment_122" class="wp-caption alignright" style="width: 193px"><a href="http://iltc.files.wordpress.com/2008/10/2008-10-24_ellipticallayoutpanel3d_silverlight_classdiagram.png"><img class="size-medium wp-image-122 " title="2008-10-24_ellipticallayoutpanel3d_silverlight_classdiagram" src="http://iltc.files.wordpress.com/2008/10/2008-10-24_ellipticallayoutpanel3d_silverlight_classdiagram.png?w=183&#038;h=300" alt="EllipseLayoutPanel3D Class Diagram" width="183" height="300" /></a><p class="wp-caption-text">EllipseLayoutPanel3D Class Diagram</p></div>
<p>The main Page also contains a few controls which allow you to interact with the layout control, allowing you to specify the size, location and pose of the layout control as well as add or remove items to the control. </p>
<p>With the default orientation of the ellipse when the demo app first runs, changes made to the z-rotation slider will have the effect of spinning the controls around, in the fashion of a carousel.</p>
<p>The control also has a button which toggles animation of the layout ellipse&#8217;s orientation by adding a value to each rotation slider every 16 milliseconds, wrapping back around when the end of the slider is reached. Staggering the rotation sliders will give the best effect. The slider underneath the animation button is used to control how much each slider moves on each time period. The further right the slider is the faster the control spins.</p>
<p>To the right is a class diagram, showing the structure of the layout control. You can see it’s pretty simple and doesn’t need to add much to its FrameworkElement ancestor. </p>
<p>Below is a screen-shot of the demo application in action. The values of the sliders are bound to the ellipse control&#8217;s dependency properties via the binding helper. There is a small amount of code behind to handle the locking of the height and width sliders, the add and remove buttons and the animation toggle button.</p>
<p style="text-align:center;"><a href="http://iltc.files.wordpress.com/2008/10/2008-10-24_ellipticallayoutpanel3d_silverlight_screenshot2.png"><img class="size-medium wp-image-121 aligncenter" title="2008-10-24_ellipticallayoutpanel3d_silverlight_screenshot2" src="http://iltc.files.wordpress.com/2008/10/2008-10-24_ellipticallayoutpanel3d_silverlight_screenshot2.png?w=300&#038;h=200" alt="" width="300" height="200" /></a></p>
<p style="text-align:left;">The code is available for <a href="http://ilovetocode.googlecode.com/files/EllipseControl3D_Silverlight2_VS2008_v0.2.zip">download</a> as a Visual Studio 2008 (SP1) solution (+Silverlight Tools), built against Silverlight 2.0, .Net 3.5 SP1.</p>
<p style="text-align:left;"><strong>Going Forwards</strong></p>
<p style="text-align:left;">At present the level of user interaction with the control itself is fairly minimal, sure you can interact with items in the control, but there is little in terms of controlling the position of items in the list using the position of the mouse, or any concept of focusing on a particular item etc.</p>
<p style="text-align:left;">There are many optimizations to be made in the 3D aspects of the demo. The transformation of points and scale calculations could be performed in a pipeline, use of lookup tables for the outputs of the sin and cos functions etc.</p>
<p><a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2filtc.wordpress.com%2f2008%2f10%2f25%2fsilverlight-20-elliptical-control-3d%2f"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2filtc.wordpress.com%2f2008%2f10%2f25%2fsilverlight-20-elliptical-control-3d%2f&amp;border=F78B0C&amp;fgcolor=818181&amp;bgcolor=FFFFFF&amp;cfgcolor=FFFFFF&amp;cbgcolor=818181" border="0" alt="kick it on DotNetKicks.com" /></a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/iltc.wordpress.com/90/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/iltc.wordpress.com/90/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/iltc.wordpress.com/90/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/iltc.wordpress.com/90/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/iltc.wordpress.com/90/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/iltc.wordpress.com/90/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/iltc.wordpress.com/90/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/iltc.wordpress.com/90/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/iltc.wordpress.com/90/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/iltc.wordpress.com/90/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/iltc.wordpress.com/90/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/iltc.wordpress.com/90/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/iltc.wordpress.com/90/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/iltc.wordpress.com/90/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=iltc.wordpress.com&amp;blog=5112722&amp;post=90&amp;subd=iltc&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://iltc.wordpress.com/2008/10/25/silverlight-20-elliptical-control-3d/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">ilovetocode</media:title>
		</media:content>

		<media:content url="http://iltc.files.wordpress.com/2008/10/2008-10-24_ellipticallayoutpanel3d_silverlight_screenshot.png?w=300" medium="image">
			<media:title type="html">2008-10-24_ellipticallayoutpanel3d_silverlight_screenshot</media:title>
		</media:content>

		<media:content url="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2filtc.wordpress.com%2f2008%2f10%2f25%2fsilverlight-20-elliptical-control-3d%2f&#38;border=F78B0C&#38;fgcolor=818181&#38;bgcolor=FFFFFF&#38;cfgcolor=FFFFFF&#38;cbgcolor=818181" medium="image">
			<media:title type="html">kick it on DotNetKicks.com</media:title>
		</media:content>

		<media:content url="http://iltc.files.wordpress.com/2008/10/2008-10-24_ellipticallayoutpanel3d_silverlight_classdiagram.png?w=183" medium="image">
			<media:title type="html">2008-10-24_ellipticallayoutpanel3d_silverlight_classdiagram</media:title>
		</media:content>

		<media:content url="http://iltc.files.wordpress.com/2008/10/2008-10-24_ellipticallayoutpanel3d_silverlight_screenshot2.png?w=300" medium="image">
			<media:title type="html">2008-10-24_ellipticallayoutpanel3d_silverlight_screenshot2</media:title>
		</media:content>

		<media:content url="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2filtc.wordpress.com%2f2008%2f10%2f25%2fsilverlight-20-elliptical-control-3d%2f&#38;border=F78B0C&#38;fgcolor=818181&#38;bgcolor=FFFFFF&#38;cfgcolor=FFFFFF&#38;cbgcolor=818181" medium="image">
			<media:title type="html">kick it on DotNetKicks.com</media:title>
		</media:content>
	</item>
		<item>
		<title>Updates + Book</title>
		<link>http://iltc.wordpress.com/2008/10/13/updates-book/</link>
		<comments>http://iltc.wordpress.com/2008/10/13/updates-book/#comments</comments>
		<pubDate>Mon, 13 Oct 2008 11:46:25 +0000</pubDate>
		<dc:creator>ilovetocode</dc:creator>
				<category><![CDATA[Blog Info]]></category>
		<category><![CDATA[WPF Recipes]]></category>

		<guid isPermaLink="false">http://iltc.wordpress.com/?p=84</guid>
		<description><![CDATA[I managed to get around to updating the sidebar this morning so that it is now a little more useful. This whole blogging thing has turned out much more simple and enjoyable than I first thought it would be. I also decided to put a mention in for the book which I, along with two [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=iltc.wordpress.com&amp;blog=5112722&amp;post=84&amp;subd=iltc&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I managed to get around to updating the sidebar this morning so that it is now a little more useful. This whole blogging thing has turned out much more simple and enjoyable than I first thought it would be.</p>
<p>I also decided to put a mention in for the book which I, along with two former colleagues, spent the last year writing, WPF Recipes in C# 2008: not for the money as we see very little out of it, but more so that people can get in touch with me in relation to its content.</p>
<p>We wrote the book in our evenings and weekends as an attempt to provide a collection of worked examples of various everyday problems, something we yearned for during our early days of using .Net 3.0. We hope it can help you avoid many of headaches we encountered on our WPF journey!</p>
<p>So be it questions, comments or corrections relating to the following chapters, get <a href="mailto:samnoble.iltc@gmail.com">in touch</a>.</p>
<ul>
<li>1 &#8211; Building and Debugging WPF Applications</li>
<li>7 &#8211; Working with Text, Documents, and Printing</li>
<li>10 &#8211; Working with 3D Graphics</li>
<li>11 &#8211; Creating Animation</li>
</ul>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/iltc.wordpress.com/84/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/iltc.wordpress.com/84/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/iltc.wordpress.com/84/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/iltc.wordpress.com/84/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/iltc.wordpress.com/84/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/iltc.wordpress.com/84/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/iltc.wordpress.com/84/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/iltc.wordpress.com/84/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/iltc.wordpress.com/84/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/iltc.wordpress.com/84/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/iltc.wordpress.com/84/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/iltc.wordpress.com/84/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/iltc.wordpress.com/84/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/iltc.wordpress.com/84/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=iltc.wordpress.com&amp;blog=5112722&amp;post=84&amp;subd=iltc&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://iltc.wordpress.com/2008/10/13/updates-book/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">ilovetocode</media:title>
		</media:content>
	</item>
		<item>
		<title>WPF Elliptical Layout Control &#8211; 3D!</title>
		<link>http://iltc.wordpress.com/2008/10/11/wpf-elliptical-layout-control-3d/</link>
		<comments>http://iltc.wordpress.com/2008/10/11/wpf-elliptical-layout-control-3d/#comments</comments>
		<pubDate>Sat, 11 Oct 2008 21:40:08 +0000</pubDate>
		<dc:creator>ilovetocode</dc:creator>
				<category><![CDATA[3D]]></category>
		<category><![CDATA[Source Code]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[.Net 3+]]></category>
		<category><![CDATA[Examples]]></category>
		<category><![CDATA[LINQ]]></category>

		<guid isPermaLink="false">http://iltc.wordpress.com/?p=54</guid>
		<description><![CDATA[After finishing my last post, WPF Elliptical Layout Control, I sat down and wondered what to do next. It occurred to me that creating a 3D carousel in WPF is a common question and one that doesn&#8217;t have all that many examples. A 3D control is also a natural progression from the 2D control and is not [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=iltc.wordpress.com&amp;blog=5112722&amp;post=54&amp;subd=iltc&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>After finishing my last post, <a title="Read WPF Elliptical Layout Control" rel="bookmark" href="http://iltc.wordpress.com/2008/10/08/wpf-elliptical-layout-control/">WPF Elliptical Layout Control</a>, I sat down and wondered what to do next. It occurred to me that creating a 3D carousel in WPF is a common question and one that doesn&#8217;t have all that many examples. A 3D control is also a natural progression from the 2D control and is not all that different. All we need to do is layout the objects in 2D, then rotate those points according to the orientation of the imaginary layout ellipse, taking in to account depth.</p>
<p>This example creates a new control which derives from <a href="http://msdn.microsoft.com/en-us/library/system.windows.frameworkelement.aspx">FrameworkElement </a>and is very similar to the implementation of the <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.viewport3d.aspx">Viewport3D</a> control. The new control overrides the measure and layout methods of FrameworkElement and positions the child controls (supplied as a collection of UIElements) according to the orientation of an imaginary 2D ellipse in 3D space.</p>
<p>It is assumed that the reader has some knowledge of custom controls, <a href="http://msdn.microsoft.com/en-us/netframework/aa904594.aspx">LINQ </a>and <a href="http://msdn.microsoft.com/en-us/library/ms747437.aspx">3D </a>in WPF. The code provided is by no means an ideal implementation of the theory, it should be thought of more as a quick demonstration of the concept. And remember, in WPF there is almost always more than one way of doing the same thing, mine is just my take on the problem :0)</p>
<div id="attachment_55" class="wp-caption aligncenter" style="width: 520px"><a href="http://iltc.files.wordpress.com/2008/10/2008-10-11_ellipticallayoutpanel3d_screenshot.png"><img class="size-large wp-image-55" title="2008-10-11_ellipticallayoutpanel3d_screenshot" src="http://iltc.files.wordpress.com/2008/10/2008-10-11_ellipticallayoutpanel3d_screenshot.png?w=510&#038;h=346" alt="3D Elliptical Layout Panel Demo" width="510" height="346" /></a><p class="wp-caption-text">3D Elliptical Layout Panel Demo</p></div>
<p><a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2filtc.wordpress.com%2f2008%2f10%2f11%2fwpf-elliptical-layout-control-3d%2f"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2filtc.wordpress.com%2f2008%2f10%2f11%2fwpf-elliptical-layout-control-3d%2f&amp;border=F78B0C&amp;fgcolor=818181&amp;bgcolor=FFFFFF&amp;cfgcolor=FFFFFF&amp;cbgcolor=818181" border="0" alt="kick it on DotNetKicks.com" /></a></p>
<p><span id="more-54"></span></p>
<p><strong>The Idea</strong></p>
<p>In the last example, we worked out how to lay out controls as if they were positioned at equal intervals around the edge of an imaginary ellipse. We now want to take that ellipse from a 2D space in to 3D, giving a sense of depth in the control.</p>
<p>Taking the existing layout logic in to the third dimension is fairly trivial if we remember that the positions we calculate for child controls in the 2D version could be thought of as being 3D points, all at the same distance away from the screen, i.e. z = 0. So by treating the points that are generated as 3D points, each with a value of zero for z (their depth), we can then rotate them to match the orientation of the layout ellipse (defined by an x, y and z axis rotation).</p>
<p>In short, we calculate the position of each child element as before, then rotate that point in 3D to match the rotation of a virtual layout ellipse. The layout ellipse will be configured as before, although this time we need to allow a way to configure its orientation. This is as simple as adding three new properties to allow an angle of rotation to be specified for each axis.</p>
<p>When it comes to the control, we need to look to 3D controls in WPF. We could create our own control which lays out its content, then projects it in to 3D and renders the control scaled such that they appear to be 3D, but that&#8217;s no fun and way too much effort! It would somehow be great if we could take advantage of the relatively new <a href="http://msdn.microsoft.com/en-us/library/system.windows.media.media3d.viewport2dvisual3d.aspx">Viewport2DVisual3D</a> control, effictively a 3D wrapper for a <a href="http://msdn.microsoft.com/en-us/library/system.windows.uielement.aspx">UIElement</a>. It would also be great if the control exposed just a collection of UIElements, which internally it could wrap in a Viewport2DVisual3D control. </p>
<p>Now we know what our items are doing, we need to think of a suitable container. If we look at the <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.viewport3d.aspx">Viewport3D</a> control, we can see that it wraps a <a href="http://msdn.microsoft.com/en-us/library/system.windows.media.media3d.viewport3dvisual.aspx">Viewport3DVisual</a>, exposing a collection of UIElement objects which it implicitly converts to <a href="http://msdn.microsoft.com/en-us/library/system.windows.media.media3d.visual3d.aspx">Visual3D </a>objects and adds to the inner Viewport3DVisual, as well as one or two other things. This is very similar to what we want to do, with the difference that we want to also define the layout mechanism too.</p>
<p><strong>The Theory</strong></p>
<p>I guess the first thing to tackle here is how to take the generated 2D position for each child control and turn that in to a 3D point, which we can use to create a <a href="http://msdn.microsoft.com/en-us/library/system.windows.media.media3d.translatetransform3d.aspx">TranslateTransform3D</a>. For each point we generate on the ellipse, create a <a href="http://msdn.microsoft.com/en-us/library/system.windows.media.media3d.point3d.aspx">Point3D</a> object using the x and y values of the 2D point and supply a z value of 0d (or whatever you want for the ellipse&#8217;s distance from the image plane).</p>
<p>Next, rotate the point around each axis using the rotations used to describe the layout ellipse&#8217;s orientation.  If you&#8217;re familiar with 3D graphics you may well be aware of <a href="http://en.wikipedia.org/wiki/Gimbal_lock">Gimbal lock</a>, something we want to avoid when we&#8217;re rotating the child control positions. To combat this, the rotation method will use quaternions. If you&#8217;ve not come across quaternions before, I recommend a quick look on <a href="http://www.google.co.uk/search?hl=en&amp;q=quaternion">Google</a> as there are far better explanations out there than I can give. Also look at <a href="http://www.genesis3d.com/~kdtop/Quaternions-UsingToRepresentRotation.htm">this</a> site which gives the theory behind the math used to rotate a point.</p>
<pre class="brush: csharp;">
private readonly static Vector3D UnitXAxis3D = new Vector3D(1d, 0d, 0d);
private readonly static Vector3D UnitYAxis3D = new Vector3D(0d, 1d, 0d);
private readonly static Vector3D UnitZAxis3D = new Vector3D(0d, 0d, 1d);

private static Point3D RotatePoint3D(Point3D point, double xRotation, double yRotation, double zRotation)
{
    Quaternion xQ = new Quaternion(UnitXAxis3D, xRotation);
    Quaternion yQ = new Quaternion(UnitYAxis3D, yRotation);
    Quaternion zQ = new Quaternion(UnitZAxis3D, zRotation);

    Quaternion xyzQ = xQ * yQ * zQ;
    Quaternion xyzQc = xyzQ;
    xyzQc.Conjugate();

    Quaternion pQ = new Quaternion(point.X, point.Y, point.Z, 0d);
    Quaternion q = xyzQ * pQ * xyzQc;
    Point3D rotatedPoint = new Point3D(q.X, q.Y, q.Z);

    return rotatedPoint;
 }
</pre>
<p>With the Point3D in hand, a TranslateTransform3D object can be created and applied to the child Viewport2DVisual3D control. This leads to the next question of how we are going to handle the wrapping of UIElements. With the addition of the Viewport2DVisual3D control, it is now possible to easily use a UIElement in a 3D scene, maintaining all the usual input handling, so no more messing around with visual brushes and models! You don&#8217;t get off too lightly though as you still need to provide the Viewport2DVisual3D with some information. This includes a <a href="http://msdn.microsoft.com/en-us/library/system.windows.media.media3d.geometry3d.aspx">Geometry3D</a> object detailing a mesh that defines the surface which the inner <a href="http://msdn.microsoft.com/en-us/library/system.windows.media.visual.aspx">Visual</a> is to be rendered on; the material which should be used when rendering the Visual on the mesh and finally the Visual object itself.</p>
<p>To keep things simple, we can define a basic mesh containing a unit square. This mesh is going to be used as the geometry for each control surface, so we need a way of sizing it according to the dimensions of the control being rendered. This is again a trivial problem and is solved by creating a <a href="http://msdn.microsoft.com/en-us/library/system.windows.media.media3d.scaletransform3d.aspx">ScaleTransform3D</a> object which scales the Viewport2DVisual3D control so that it is scaled by the dimensions of the inner Visual object, ignoring z. Nice!</p>
<p>The scale transform is created for each Viewport2DVisual3D control each time the MeasureOverride method is called. There is no particular reason to place this code here, other than it keeps the sizing logic separate from the layout logic, keeping things a bit better organised. The next code snippet is included to highlight the use of the <a href="http://msdn.microsoft.com/en-us/library/bb360913.aspx">OfType&lt;T&gt;()</a> LINQ extension method, used on the Children property of the control&#8217;s inner Viewport3DVisual. This method returns an IEnumerable&lt;T&gt; object containing all the items in the collection with a type specified by T. Because we know that our Children collection contains a light somewhere within it, we want to skip over that when scaling the child objects.</p>
<pre class="brush: csharp;">
protected override Size MeasureOverride(Size availableSize)
{
    //Iterate all the children of the inner viewport.
    foreach (Viewport2DVisual3D visualChild 
        in viewport3DVisual.Children.OfType&lt;Viewport2DVisual3D&gt;())
    {
        //Get the inner UIElement
        UIElement element = visualChild.Visual as UIElement;
        //Create a scale transform so that the control appears the right size
        ScaleTransform3D scaleTransform
            = new ScaleTransform3D(element.DesiredSize.Width, element.DesiredSize.Height, 0d);

        //Add the scale transform in to the Viewport2DVisual3D's transform group.
        AssertTransform3D&lt;ScaleTransform3D&gt;(scaleTransform, visualChild);
    }

    return availableSize;
}
</pre>
<p>The container that will hold all of these Viewport2DVisual3D controls will need to be a Viewport3DVisual. Again because we are dealing with 3D we need to define a few extra things for the Viewport3DVisual. The first is a <a href="http://msdn.microsoft.com/en-us/library/system.windows.media.media3d.camera.aspx">Camera</a> object which defines how controls displayed in the Viewport3DVisual appear to the viewer. The second is a <a href="http://msdn.microsoft.com/en-us/library/system.windows.media.media3d.light.aspx">Light</a> object which defines an <a href="http://msdn.microsoft.com/en-us/library/system.windows.media.media3d.ambientlight.aspx">AmbientLight</a> object used to provide a uniform white light in the 3D scene (otherwise everything would be dark and you&#8217;d see nothing more than a black screen).</p>
<p>To make the controls appear to be positioned within 3-dimensional space, we will use a <a href="http://msdn.microsoft.com/en-us/library/system.windows.media.media3d.perspectivecamera.aspx">PerspectiveCamera</a>, meaning objects which are placed deeper in to the control (further from the screen) will appear smaller than those which are closer to the screen. All we need to do to configure the camera is tell it where it is and the direction it is looking. Because we are keeping things simple here, we&#8217;ll position our camera somewhere along the positive z-axis, and have it looking down the z-axis (towards the origin). This means our camera will be looking straight on at the objects placed within the control, with the layout ellipse&#8217;s origin at the origin of the scene.</p>
<p><strong>The Solution</strong></p>
<p>Here I present a simple demonstration of the above in the attached solution. The solution contains a simple Window which hosts the custom 3D ellipse layout control. The ellipse layout control is included in the ElliptiseLayout3DPanel class and adds several dependency properties and a few methods to the FrameworkElement class.</p>
<div id="attachment_67" class="wp-caption alignright" style="width: 137px"><a href="http://iltc.files.wordpress.com/2008/10/2008-10-11_ellipticallayoutpanel3d_classdiagram1.png"><img class="size-full wp-image-67     " title="2008-10-11_ellipticallayoutpanel3d_classdiagram1" src="http://iltc.files.wordpress.com/2008/10/2008-10-11_ellipticallayoutpanel3d_classdiagram1.png?w=127&#038;h=331" alt="EllipticalLayoutPanel3D Class Diagram" width="127" height="331" /></a><p class="wp-caption-text">EllipticalLayoutPanel3D Class Diagram</p></div>
<p>The main window also contains a few controls which allow you to interact with the layout control, allowing you to specify the size, location and pose of the layout control as well as add or remove items to the control. There are also two buttons will moves the controls around the ellipse, one at a time. This is a bit of a jig and is as simple as removing an item from the top of the collection held in the control&#8217;s Children property and adding it to the end of the collection. The reverse is true for moving back through the items. The light sometimes gets caught up in this, so you may not see anything happen for a click or two when switching direction.</p>
<p>With the default orientation of the ellipse when the demo app first runs, changes made to the z-rotation slider will have the effect of spinning the controls around, in the fashion of a carousel. This could be used to animate the rotation items in the control.</p>
<p>To the right is a class diagram, showing the structure of the layout control. You can see it’s pretty simple and doesn’t need to add much to its FrameworkElement ancestor. </p>
<p>Below is a screen-shot of the demo application in action. The values of the sliders are directly bound to the panel’s dependency properties, meaning the only code-behind is for the four button event handlers.</p>
<p> </p>
<div id="attachment_55" class="wp-caption aligncenter" style="width: 520px"><a href="http://iltc.files.wordpress.com/2008/10/2008-10-11_ellipticallayoutpanel3d_screenshot.png"><img class="size-large wp-image-55" title="2008-10-11_ellipticallayoutpanel3d_screenshot" src="http://iltc.files.wordpress.com/2008/10/2008-10-11_ellipticallayoutpanel3d_screenshot.png?w=510&#038;h=346" alt="3D Elliptical Layout Panel Demo" width="510" height="346" /></a><p class="wp-caption-text">3D Elliptical Layout Panel Demo</p></div>
<p>The code is available for <a href="http://ilovetocode.googlecode.com/files/EllipticalLayoutControl3DDemo_VS2008.zip">download</a> as a Visual Studio 2008 (SP1) solution, built against .Net 3.5 SP1.</p>
<p><strong>Going Forwards</strong></p>
<p>The light source and other properties of the control are not configurable. You may want to expose the lights as a separate collection, or at least allow the colour to be altered.</p>
<p>The control will need some more work to enable it to be used in an ItemsPanelTemplate, so it won&#8217;t work out of the box.</p>
<p>You may want to add proper methods for controlling the order of items in the control, possibly animating this.</p>
<p>All and any comments / bugs / suggestions are welcomed!</p>
<p><a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2filtc.wordpress.com%2f2008%2f10%2f11%2fwpf-elliptical-layout-control-3d%2f"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2filtc.wordpress.com%2f2008%2f10%2f11%2fwpf-elliptical-layout-control-3d%2f&amp;border=F78B0C&amp;fgcolor=818181&amp;bgcolor=FFFFFF&amp;cfgcolor=FFFFFF&amp;cbgcolor=818181" border="0" alt="kick it on DotNetKicks.com" /></a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/iltc.wordpress.com/54/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/iltc.wordpress.com/54/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/iltc.wordpress.com/54/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/iltc.wordpress.com/54/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/iltc.wordpress.com/54/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/iltc.wordpress.com/54/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/iltc.wordpress.com/54/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/iltc.wordpress.com/54/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/iltc.wordpress.com/54/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/iltc.wordpress.com/54/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/iltc.wordpress.com/54/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/iltc.wordpress.com/54/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/iltc.wordpress.com/54/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/iltc.wordpress.com/54/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=iltc.wordpress.com&amp;blog=5112722&amp;post=54&amp;subd=iltc&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://iltc.wordpress.com/2008/10/11/wpf-elliptical-layout-control-3d/feed/</wfw:commentRss>
		<slash:comments>19</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">ilovetocode</media:title>
		</media:content>

		<media:content url="http://iltc.files.wordpress.com/2008/10/2008-10-11_ellipticallayoutpanel3d_screenshot.png?w=510" medium="image">
			<media:title type="html">2008-10-11_ellipticallayoutpanel3d_screenshot</media:title>
		</media:content>

		<media:content url="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2filtc.wordpress.com%2f2008%2f10%2f11%2fwpf-elliptical-layout-control-3d%2f&#38;border=F78B0C&#38;fgcolor=818181&#38;bgcolor=FFFFFF&#38;cfgcolor=FFFFFF&#38;cbgcolor=818181" medium="image">
			<media:title type="html">kick it on DotNetKicks.com</media:title>
		</media:content>

		<media:content url="http://iltc.files.wordpress.com/2008/10/2008-10-11_ellipticallayoutpanel3d_classdiagram1.png" medium="image">
			<media:title type="html">2008-10-11_ellipticallayoutpanel3d_classdiagram1</media:title>
		</media:content>

		<media:content url="http://iltc.files.wordpress.com/2008/10/2008-10-11_ellipticallayoutpanel3d_screenshot.png?w=510" medium="image">
			<media:title type="html">2008-10-11_ellipticallayoutpanel3d_screenshot</media:title>
		</media:content>

		<media:content url="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2filtc.wordpress.com%2f2008%2f10%2f11%2fwpf-elliptical-layout-control-3d%2f&#38;border=F78B0C&#38;fgcolor=818181&#38;bgcolor=FFFFFF&#38;cfgcolor=FFFFFF&#38;cbgcolor=818181" medium="image">
			<media:title type="html">kick it on DotNetKicks.com</media:title>
		</media:content>
	</item>
		<item>
		<title>WPF Elliptical Layout Control</title>
		<link>http://iltc.wordpress.com/2008/10/08/wpf-elliptical-layout-control/</link>
		<comments>http://iltc.wordpress.com/2008/10/08/wpf-elliptical-layout-control/#comments</comments>
		<pubDate>Wed, 08 Oct 2008 22:23:38 +0000</pubDate>
		<dc:creator>ilovetocode</dc:creator>
				<category><![CDATA[Source Code]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[.Net 3+]]></category>
		<category><![CDATA[Examples]]></category>

		<guid isPermaLink="false">http://iltc.wordpress.com/?p=5</guid>
		<description><![CDATA[Today I was talking to a good friend and former colleague and he asked how I would go about laying out a collection of controls as if they were equally spread out around the edge of an ellipse. I did a quick Google and didn&#8217;t find much in the way of examples, so I decided [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=iltc.wordpress.com&amp;blog=5112722&amp;post=5&amp;subd=iltc&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p style="text-align:left;">Today I was talking to a good friend and former colleague and he asked how I would go about laying out a collection of controls as if they were equally spread out around the edge of an ellipse. I did a quick Google and didn&#8217;t find much in the way of examples, so I decided to knock one together. An hour later and we have what I present here.</p>
<p style="text-align:left;">This is a fully working, but a little rough, demonstration of creating your own control and performing custom layout logic.</p>
<p style="text-align:center;"><a href="http://iltc.files.wordpress.com/2008/10/ellipticallayoutpaneldemoscreenshot.png"><img class="size-large wp-image-7 aligncenter" title="ellipticallayoutpaneldemoscreenshot" src="http://iltc.files.wordpress.com/2008/10/ellipticallayoutpaneldemoscreenshot.png?w=450&#038;h=290" alt="The demo in action" width="450" height="290" /></a></p>
<p><a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2filtc.wordpress.com%2f2008%2f10%2f08%2fwpf-elliptical-layout-control%2f"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2filtc.wordpress.com%2f2008%2f10%2f08%2fwpf-elliptical-layout-control%2f&amp;border=F78B0C&amp;fgcolor=515151&amp;bgcolor=FFFFFF&amp;cfgcolor=FFFFFF&amp;cbgcolor=515151" border="0" alt="kick it on DotNetKicks.com" /></a></p>
<p><span id="more-5"></span></p>
<p><strong>The Idea</strong></p>
<p style="text-align:left;">The problem we are trying to solve requires working out the location that a control should be positioned at within its containing panel, such that all of the controls are positioned as if they are placed along the edge of an invisible ellipse.</p>
<p style="text-align:left;">We can simpify the problem by modelling the edge of the ellipse as a long piece of string that we can straighten out in to a straight line and also assume that each point on the ellipse&#8217;s edge is at an angle one unit (degree or radian) greater than the last. This means that the angle to the location of the control around the edge of the ellipse is directly proportional to the distance that the control needs to be from the start of a straight line.</p>
<p style="text-align:left;">For the control itself I chose to create a new control that inherits System.Windows.Controls.Canvas. The reasoning for this is that Canvas provides everything that we need, meaning we only have to override how items are laid out and a few additional properties to configure the layout.</p>
<p><strong>The Theory</strong></p>
<p style="text-align:left;">Here we will approach the solution in two steps. The first of which will give us the spacing of the controls, which will allow us to go on and calculate the location of the control.</p>
<p style="text-align:left;">To calculate how far around the ellipse each control should be placed, we need to know the number of items we want to display and the length of the line we have to display them on. Simple! First, the amount of spacing (space) between each item (where count is the number of items, length is the length of the line) is calculated using:</p>
<p style="text-align:center;"><img src='http://s0.wp.com/latex.php?latex=space+%3D+%5Cfrac%7B%5Ctextsf%7Blength%7D%7D%7B%5Ctextsf%7Bcount%7D%7D&amp;bg=ffffff&amp;fg=555555&amp;s=0' alt='space = &#92;frac{&#92;textsf{length}}{&#92;textsf{count}}' title='space = &#92;frac{&#92;textsf{length}}{&#92;textsf{count}}' class='latex' /></p>
<p style="text-align:left;">There is one unknown in the above formula: the legth of the line; or more accurately, the circumference of the ellipse. It may come as a suprise to learn that there is no finite equation which will give the circumference of an ellipse. Don&#8217;t worry though, we don&#8217;t have to get our hands dirty with second degree integrals as some clever chaps have devised equations which will approximate the circumference. </p>
<p style="text-align:left;"><a href="http://local.wasp.uwa.edu.au/~pbourke/geometry/ellipsecirc/">Several methods</a> exist, each with varying degrees of accuracy. The most accurate of which is the second form of Ramanujan&#8217;s approximation (although the accuracy degrades for ellipses where the width is much greater than the height and vice versa) and is given by:</p>
<p style="text-align:center;"><img src='http://s0.wp.com/latex.php?latex=%5CPi%28a+%2B+b%29+%5B+1+%2B+3+h+%2F+%2810+%2B+%284+-+3+h%29%5E%7B%5Cfrac%7B1%7D%7B2%7D%7D%29+%5D&amp;bg=ffffff&amp;fg=555555&amp;s=0' alt='&#92;Pi(a + b) [ 1 + 3 h / (10 + (4 - 3 h)^{&#92;frac{1}{2}}) ]' title='&#92;Pi(a + b) [ 1 + 3 h / (10 + (4 - 3 h)^{&#92;frac{1}{2}}) ]' class='latex' /></p>
<p>Where:</p>
<p style="text-align:center;"><img src='http://s0.wp.com/latex.php?latex=h+%3D+%5Cfrac%7B%28a+-+b%29%5E%7B2%7D%7D%7B%28a+%2B+b%29%5E%7B2%7D%7D&amp;bg=ffffff&amp;fg=555555&amp;s=0' alt='h = &#92;frac{(a - b)^{2}}{(a + b)^{2}}' title='h = &#92;frac{(a - b)^{2}}{(a + b)^{2}}' class='latex' /></p>
<p style="text-align:center;"><img src='http://s0.wp.com/latex.php?latex=a+%3D+%5Ctextsf%7Bwidth+of+ellipse+%28length+of+major+axis%29%7D&amp;bg=ffffff&amp;fg=555555&amp;s=0' alt='a = &#92;textsf{width of ellipse (length of major axis)}' title='a = &#92;textsf{width of ellipse (length of major axis)}' class='latex' /></p>
<p style="text-align:center;"><img src='http://s0.wp.com/latex.php?latex=b+%3D+%5Ctextsf%7Bheight+of+ellipse+%28length+of+minor+axis%29%7D&amp;bg=ffffff&amp;fg=555555&amp;s=0' alt='b = &#92;textsf{height of ellipse (length of minor axis)}' title='b = &#92;textsf{height of ellipse (length of minor axis)}' class='latex' /></p>
<p style="text-align:left;">In code it looks like this:</p>
<pre class="brush: csharp;">
private double CalculateEllipseCircumferenceRamanujan2(double a, double b)
{
    double h = Math.Pow(a - b, 2) / Math.Pow(a + b, 2);
    //pi (a + b) [ 1 + 3 h / (10 + (4 - 3 h)^1/2 ) ]            
    double result = Math.PI * (a + b) * (1 + 3 * h / (10 + Math.Pow((4 - 3 * h), 0.5)));
    return result;
}
</pre>
<p style="text-align:left;">Now each control&#8217;s distance from the start of the line can be calculated as:</p>
<p style="text-align:center;"><img src='http://s0.wp.com/latex.php?latex=%5Ctextsf%7Boffset%7D+%3D+%5Ctextsf%7Bindex%7D+%2A+%5Ctextsf%7Bspace%7D&amp;bg=ffffff&amp;fg=555555&amp;s=0' alt='&#92;textsf{offset} = &#92;textsf{index} * &#92;textsf{space}' title='&#92;textsf{offset} = &#92;textsf{index} * &#92;textsf{space}' class='latex' /></p>
<p style="text-align:left;">Where &#8216;index&#8217; is the 0-based index of the control in its parent collection, or some other value which indicates the ordering of elements. It is important to note that by using a 0-based index, our spacing allows space for one extra item which doesn&#8217;t actually exist. If we didn&#8217;t do this, the last item in the control would be placed on top of the first as they&#8217;d both occupy the same position when wrapped around the ellipse.</p>
<p style="text-align:left;">Given the offset of the control from the start of the line, we need to convert this in to an angle of rotation from the start point of the ellipse&#8217;s edge. As stated before, we can assume that each point on the ellipse&#8217;s edge directly relates to the distance from the start of the ellipse. So all we need to do is map our value on to a radian number range.</p>
<p style="text-align:center;"><img src='http://s0.wp.com/latex.php?latex=%5Ctextsf%7BangleInRadians%7D+%3D+2%5CPi%28%5Cfrac%7B%5Ctextsf%7Boffset%7D%7D%7B%5Ctextsf%7BellipseCircumference%7D%7D%29&amp;bg=ffffff&amp;fg=555555&amp;s=0' alt='&#92;textsf{angleInRadians} = 2&#92;Pi(&#92;frac{&#92;textsf{offset}}{&#92;textsf{ellipseCircumference}})' title='&#92;textsf{angleInRadians} = 2&#92;Pi(&#92;frac{&#92;textsf{offset}}{&#92;textsf{ellipseCircumference}})' class='latex' /></p>
<p style="text-align:left;">In code:</p>
<pre class="brush: csharp;">
double theta = (Math.PI * 2) * ((i * itemSpacing) / layoutCirfumference);
</pre>
<p style="text-align:left;"><span style="font-family:'Lucida Grande';line-height:19px;white-space:normal;">We&#8217;re almost there! The last step is to now take that angle along with the characterisitcs of the ellipse and calculate a point for a given angle. Thankfully the parametric equations for a point on the edge of an ellipse are nice and simple:</span></p>
<p style="text-align:center;"><img src='http://s0.wp.com/latex.php?latex=x+%3D+%5Ctextsf%7BellipseOriginX%7D+%2B+%28%5Ctextsf%7BellipseWidth%7D+%2A+Cos%28%5Ctextsf%7Bangle%7D%29%29&amp;bg=ffffff&amp;fg=555555&amp;s=0' alt='x = &#92;textsf{ellipseOriginX} + (&#92;textsf{ellipseWidth} * Cos(&#92;textsf{angle}))' title='x = &#92;textsf{ellipseOriginX} + (&#92;textsf{ellipseWidth} * Cos(&#92;textsf{angle}))' class='latex' /></p>
<p style="text-align:center;"><img src='http://s0.wp.com/latex.php?latex=y+%3D+%5Ctextsf%7BellipseOriginY%7D+%2B+%28%5Ctextsf%7BellipseHeight%7D+%2A+Sin%28%5Ctextsf%7Bangle%7D%29%29&amp;bg=ffffff&amp;fg=555555&amp;s=0' alt='y = &#92;textsf{ellipseOriginY} + (&#92;textsf{ellipseHeight} * Sin(&#92;textsf{angle}))' title='y = &#92;textsf{ellipseOriginY} + (&#92;textsf{ellipseHeight} * Sin(&#92;textsf{angle}))' class='latex' /></p>
<p style="text-align:left;">In code:</p>
<pre class="brush: csharp;">
private Point GetPointOnEllipse(double width, double height, Point origin, double theta)
{
    double x = origin.X + (width * Math.Cos(theta));
    double y = origin.Y + (height * Math.Sin(theta));
    return new Point(x, y);
}</pre>
<p style="text-align:left;"><span style="font-family:'Lucida Grande';line-height:19px;white-space:normal;">Now if we use the above method for each child control, we will have a collection of evenly spaced points plotting the edge of the ellipse! Woo hoo. Note that when setting the location of a control, you will need to offset these values slightly such that the control is centred on the point, rather than having its top left corner at the point.</span></p>
<p style="text-align:left;">The last point of interest in the control&#8217;s code is the metadata used to define the characteristics of its dependency properties. Each dependency property registration specifies a <a title="FrameworkPropertyMetadata" href="http://msdn.microsoft.com/en-us/library/system.windows.frameworkpropertymetadata.aspx">FrameworkPropertyMetadata</a> class which makes use of the value <a title="FrameworkPropertyMetadataOptions" href="http://msdn.microsoft.com/en-us/library/system.windows.frameworkpropertymetadataoptions.aspx">FrameworkPropertyMetadataOptions</a>.AffectsArrange. In a nutshell, each time the the value of the property changes, the control&#8217;s ArrangeOverride is invoked, updating the layout of any child controls.</p>
<pre class="brush: csharp;">
public static readonly DependencyProperty EllipseHeightProperty
            = DependencyProperty.Register(&quot;EllipseHeight&quot;, typeof(double), typeof(EllipticalLayoutPanel),
                                          new FrameworkPropertyMetadata(75d, FrameworkPropertyMetadataOptions.AffectsArrange));
</pre>
<p style="text-align:left;">So what&#8217;s so great about that? Well it means we don&#8217;t have to bother specifying <a title="PropertyChangedCallback" href="http://msdn.microsoft.com/en-us/library/system.windows.propertychangedcallback.aspx">PropertyChangedCallbacks </a>and  then some internal update method, WPF does it for us! If you&#8217;re interested in learning more about dependency properties, check out <a title="Dependency Properties Overview" href="http://msdn.microsoft.com/en-us/library/ms752914.aspx">MSDN</a> or for some worked examples, look at my chapter on application development (chapter 1) in &#8216;WPF Recipes in C# 2008&#8242;.</p>
<p><strong>The Solution</strong></p>
<div id="attachment_32" class="wp-caption alignright" style="width: 256px"><a href="http://iltc.files.wordpress.com/2008/10/ellipticallayoutpanelclassdiagram.png"><img class="size-full wp-image-32 " title="ellipticallayoutpanelclassdiagram" src="http://iltc.files.wordpress.com/2008/10/ellipticallayoutpanelclassdiagram.png?w=246&#038;h=297" alt="EllipticalLayoutPanel Class Diagram" width="246" height="297" /></a><p class="wp-caption-text">EllipticalLayoutPanel Class Diagram</p></div>
<p style="text-align:left;">Here I present a simple demonstration of the above in the attached solution. The solution contains a simple Window which hosts the custom ellipse layout control. The ellipse layout control is included in the EllipticalLayoutPanel class and adds several dependency properties and a few methods to the Canvas class.</p>
<p style="text-align:left;">The main window also contains a few controls which allow you to interact with the layout control, allowing you to specify the size and location of the control as well as add or remove items to the control.</p>
<p style="text-align:left;">To the right is a class diagram, showing the structure of the layout control. You can see it&#8217;s pretty simple and doesn&#8217;t need to add much to its Canvas ancestor. The dependency properties are there only for testing as really the dimensions of the ellipse should be automatically calculated using the available size of the control. If there is any desire for this, I could easily extend the solution to perform this, just give me a shout.</p>
<p style="text-align:left;">Below is a screenshot of the demo application in action. The values of the sliders are directly bound to the panel&#8217;s dependency properties, meaning the only code-behind is for the two button event handlers.</p>
<div id="attachment_7" class="wp-caption aligncenter" style="width: 460px"><a href="http://iltc.files.wordpress.com/2008/10/ellipticallayoutpaneldemoscreenshot.png"><img class="size-large wp-image-7 " title="ellipticallayoutpaneldemoscreenshot" src="http://iltc.files.wordpress.com/2008/10/ellipticallayoutpaneldemoscreenshot.png?w=450&#038;h=290" alt="The demo in action" width="450" height="290" /></a><p class="wp-caption-text">The demo in action</p></div>
<p style="text-align:left;">The code is available for <a title="Get the code!" href="http://ilovetocode.googlecode.com/files/EllipticalLayoutPanelDemo_VS2008.zip">download </a>as a Visual Studio 2008 (SP1) solution, built against .Net 3.5 SP1.</p>
<p style="text-align:left;">All and any comments / bugs / suggestions are welcomed!</p>
<p><a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2filtc.wordpress.com%2f2008%2f10%2f08%2fwpf-elliptical-layout-control%2f"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2filtc.wordpress.com%2f2008%2f10%2f08%2fwpf-elliptical-layout-control%2f&amp;border=F78B0C&amp;fgcolor=515151&amp;bgcolor=FFFFFF&amp;cfgcolor=FFFFFF&amp;cbgcolor=515151" border="0" alt="kick it on DotNetKicks.com" /></a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/iltc.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/iltc.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/iltc.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/iltc.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/iltc.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/iltc.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/iltc.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/iltc.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/iltc.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/iltc.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/iltc.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/iltc.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/iltc.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/iltc.wordpress.com/5/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=iltc.wordpress.com&amp;blog=5112722&amp;post=5&amp;subd=iltc&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://iltc.wordpress.com/2008/10/08/wpf-elliptical-layout-control/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">ilovetocode</media:title>
		</media:content>

		<media:content url="http://iltc.files.wordpress.com/2008/10/ellipticallayoutpaneldemoscreenshot.png?w=500" medium="image">
			<media:title type="html">ellipticallayoutpaneldemoscreenshot</media:title>
		</media:content>

		<media:content url="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2filtc.wordpress.com%2f2008%2f10%2f08%2fwpf-elliptical-layout-control%2f&#38;border=F78B0C&#38;fgcolor=515151&#38;bgcolor=FFFFFF&#38;cfgcolor=FFFFFF&#38;cbgcolor=515151" medium="image">
			<media:title type="html">kick it on DotNetKicks.com</media:title>
		</media:content>

		<media:content url="http://iltc.files.wordpress.com/2008/10/ellipticallayoutpanelclassdiagram.png" medium="image">
			<media:title type="html">ellipticallayoutpanelclassdiagram</media:title>
		</media:content>

		<media:content url="http://iltc.files.wordpress.com/2008/10/ellipticallayoutpaneldemoscreenshot.png?w=500" medium="image">
			<media:title type="html">ellipticallayoutpaneldemoscreenshot</media:title>
		</media:content>

		<media:content url="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2filtc.wordpress.com%2f2008%2f10%2f08%2fwpf-elliptical-layout-control%2f&#38;border=F78B0C&#38;fgcolor=515151&#38;bgcolor=FFFFFF&#38;cfgcolor=FFFFFF&#38;cbgcolor=515151" medium="image">
			<media:title type="html">kick it on DotNetKicks.com</media:title>
		</media:content>
	</item>
		<item>
		<title>Welcomes and Hellos</title>
		<link>http://iltc.wordpress.com/2008/10/08/welcomes-and-hellos/</link>
		<comments>http://iltc.wordpress.com/2008/10/08/welcomes-and-hellos/#comments</comments>
		<pubDate>Wed, 08 Oct 2008 19:06:45 +0000</pubDate>
		<dc:creator>ilovetocode</dc:creator>
				<category><![CDATA[Blog Info]]></category>

		<guid isPermaLink="false">http://iltc.wordpress.com/?p=3</guid>
		<description><![CDATA[Hello readers and welcome to my blog. I have been meaning to do this for a while now but have never gotten around to it, mostly because I know that I will actually have to come back and update this thing! So a little about me. Well as the blog&#8217;s title suggests, I love to [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=iltc.wordpress.com&amp;blog=5112722&amp;post=3&amp;subd=iltc&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Hello readers and welcome to my blog. I have been meaning to do this for a while now but have never gotten around to it, mostly because I know that I will actually have to come back and update this thing!</p>
<p>So a little about me. Well as the blog&#8217;s title suggests, I love to code! Presently I am working exclusively in .Net 3.5 and am an avid fan of WPF. I am currently working for <a href="http://www.smithbayes.com">SmithBayes</a> where I have been working with .Net 3 (especially WPF) since the early CTP releases building a large decision making platform application.</p>
<p>The purpose of this blog is to be a place where I can share the knowledge in WPF I have gained over the years and get to know fellow .Net 3x fans.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/iltc.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/iltc.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/iltc.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/iltc.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/iltc.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/iltc.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/iltc.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/iltc.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/iltc.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/iltc.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/iltc.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/iltc.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/iltc.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/iltc.wordpress.com/3/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=iltc.wordpress.com&amp;blog=5112722&amp;post=3&amp;subd=iltc&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://iltc.wordpress.com/2008/10/08/welcomes-and-hellos/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">ilovetocode</media:title>
		</media:content>
	</item>
	</channel>
</rss>
