<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Dev102.com</title>
	
	<link>http://www.dev102.com</link>
	<description>What I Know, You Know...</description>
	<pubDate>Thu, 28 May 2009 21:00:54 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<creativeCommons:license>http://creativecommons.org/licenses/by/2.0/</creativeCommons:license><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner.com/Dev102feed" type="application/rss+xml" /><feedburner:emailServiceId>Dev102feed</feedburner:emailServiceId><feedburner:feedburnerHostname>http://feedburner.google.com</feedburner:feedburnerHostname><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com" /><item>
		<title>Formatting Your WPF Data – String.Format Is In the House!</title>
		<link>http://feedproxy.google.com/~r/Dev102feed/~3/0cVbBlkromE/</link>
		<comments>http://www.dev102.com/2009/05/28/formatting-your-wpf-data-stringformat-is-in-the-house/#comments</comments>
		<pubDate>Thu, 28 May 2009 12:32:30 +0000</pubDate>
		<dc:creator>Amit</dc:creator>
		
		<category><![CDATA[.Net]]></category>

		<category><![CDATA[WPF]]></category>

		<category><![CDATA[.NET 3.5 SP1]]></category>

		<category><![CDATA[Binding]]></category>

		<category><![CDATA[property]]></category>

		<category><![CDATA[String.Format]]></category>

		<category><![CDATA[ValueConverter]]></category>

		<guid isPermaLink="false">http://www.dev102.com/?p=1226</guid>
		<description><![CDATA[<p>Hi</p>

<p>&#160;</p>

<p>When working with WPF I always found myself thinking how to handle Data formatting when a WPF control was bound to it. Let’s look at the following example of a window with a TextBlock that displays a DateTime:</p>

<div id="codeSnippetWrapper">
  <div id="codeSnippet" style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none">
    <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"><span id="lnum1" style="color: #606060">   1:</span> <span style="color: #0000ff">&#60;</span><span style="color: #800000">Window</span> <span style="color: #ff0000">x:Class</span><span style="color: #0000ff">=&#34;BindingFormat.Window1&#34;</span></pre>
<!--CRLF-->

    <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"><span id="lnum2" style="color: #606060">   2:</span>     <span style="color: #ff0000">xmlns</span><span style="color: #0000ff">=&#34;http://schemas.microsoft.com/winfx/2006/xaml/presentation&#34;</span></pre>
<!--CRLF-->

    <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"><span id="lnum3" style="color: #606060">   3:</span>     <span style="color: #ff0000">xmlns:x</span><span style="color: #0000ff">=&#34;http://schemas.microsoft.com/winfx/2006/xaml&#34;</span></pre>
<!--CRLF-->

    <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"><span id="lnum4" style="color: #606060">   4:</span>     <span style="color: #ff0000">Title</span><span style="color: #0000ff">=&#34;Window1&#34;</span> <span style="color: #ff0000">Height</span><span style="color: #0000ff">=&#34;300&#34;</span> <span style="color: #ff0000">Width</span><span style="color: #0000ff">=&#34;300&#34;</span><span style="color: #0000ff">&#62;</span></pre>
<!--CRLF-->

    <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"><span id="lnum5" style="color: #606060">   5:</span>     <span style="color: #0000ff">&#60;</span><span style="color: #800000">Grid</span><span style="color: #0000ff">&#62;</span></pre>
<!--CRLF-->

    <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"><span id="lnum6" style="color: #606060">   6:</span>         <span style="color: #0000ff">&#60;</span><span style="color: #800000">TextBlock</span> <span style="color: #ff0000">Text</span><span style="color: #0000ff">=&#34;{Binding}&#34;</span><span style="color: #0000ff">&#62;&#60;/</span><span style="color: #800000">TextBlock</span><span style="color: #0000ff">&#62;</span></pre>
<!--CRLF-->

    <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"><span id="lnum7" style="color: #606060">   7:</span>     <span style="color: #0000ff">&#60;/</span><span style="color: #800000">Grid</span><span style="color: #0000ff">&#62;</span></pre>
<!--CRLF-->

    <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"><span id="lnum8" style="color: #606060">   8:</span> <span style="color: #0000ff">&#60;/</span><span style="color: #800000">Window</span><span style="color: #0000ff">&#62;</span></pre>
<!--CRLF--></div>
</div>]]></description>
			<content:encoded><![CDATA[<p>Hi</p>
<p> </p>
<p>When working with WPF I always found myself thinking how to handle Data formatting when a <a href="http://www.dev102.com/2008/08/07/how-to-access-a-wpf-control-which-is-located-in-a-datatemplate/">WPF control </a>was bound to it. Let’s look at the following example of a window with a TextBlock that displays a DateTime:</p>
<div id="codeSnippetWrapper">
<div id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum1" style="color: #606060">   1:</span> <span style="color: #0000ff">&lt;</span><span style="color: #800000">Window</span> <span style="color: #ff0000">x:Class</span><span style="color: #0000ff">="BindingFormat.Window1"</span></pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum2" style="color: #606060">   2:</span>     <span style="color: #ff0000">xmlns</span><span style="color: #0000ff">="http://schemas.microsoft.com/winfx/2006/xaml/presentation"</span></pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum3" style="color: #606060">   3:</span>     <span style="color: #ff0000">xmlns:x</span><span style="color: #0000ff">="http://schemas.microsoft.com/winfx/2006/xaml"</span></pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum4" style="color: #606060">   4:</span>     <span style="color: #ff0000">Title</span><span style="color: #0000ff">="Window1"</span> <span style="color: #ff0000">Height</span><span style="color: #0000ff">="300"</span> <span style="color: #ff0000">Width</span><span style="color: #0000ff">="300"</span><span style="color: #0000ff">&gt;</span></pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum5" style="color: #606060">   5:</span>     <span style="color: #0000ff">&lt;</span><span style="color: #800000">Grid</span><span style="color: #0000ff">&gt;</span></pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum6" style="color: #606060">   6:</span>         <span style="color: #0000ff">&lt;</span><span style="color: #800000">TextBlock</span> <span style="color: #ff0000">Text</span><span style="color: #0000ff">="{Binding}"</span><span style="color: #0000ff">&gt;&lt;/</span><span style="color: #800000">TextBlock</span><span style="color: #0000ff">&gt;</span></pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum7" style="color: #606060">   7:</span>     <span style="color: #0000ff">&lt;/</span><span style="color: #800000">Grid</span><span style="color: #0000ff">&gt;</span></pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum8" style="color: #606060">   8:</span> <span style="color: #0000ff">&lt;/</span><span style="color: #800000">Window</span><span style="color: #0000ff">&gt;</span></pre>
<p><!--CRLF--></p>
</div>
</div>
<p>And the code behind:</p>
<div id="codeSnippetWrapper">
<div id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum1" style="color: #606060">   1:</span> <span style="color: #0000ff">public</span> Window1()</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum2" style="color: #606060">   2:</span> {</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum3" style="color: #606060">   3:</span>     InitializeComponent();</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum4" style="color: #606060">   4:</span>     DateTime d = DateTime.Now;</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum5" style="color: #606060">   5:</span>     <span style="color: #0000ff">this</span>.DataContext = d;</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum6" style="color: #606060">   6:</span> }</pre>
<p><!--CRLF--></p>
</div>
</div>
<p>Very Simple.</p>
<p> </p>
<p>The outcome is this:</p>
<p> </p>
<p align="center"><a href="http://dev102.com/Dev102/wp-content/uploads/2009/05/bindingnoformat.png"><img style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" title="Binding no Format" src="http://dev102.com/Dev102/wp-content/uploads/2009/05/bindingnoformat-thumb.png" border="0" alt="Binding no Format" width="292" height="293" /></a></p>
<p>But what if we wanted to change the format of the DateTime? Before<a href="http://www.dev102.com/2009/05/04/4-grea-tips-for-custom-wpf-controls-developers/"> .NET 3.5 SP1 </a>we had 2 options:</p>
<p> </p>
<h3><span style="text-decoration: underline;">Adding a Property</span></h3>
<p>That was the easiest and fastest way to make the data in the UI formatted in the way you wanted let’s say we wanted the DateTime to display like this: 11:49 2/5/2009, we would have done this:</p>
<div id="codeSnippetWrapper">
<div id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum1" style="color: #606060">   1:</span> <span style="color: #0000ff">public</span> Window1()</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum2" style="color: #606060">   2:</span> {</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum3" style="color: #606060">   3:</span>     InitializeComponent();</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum4" style="color: #606060">   4:</span>     <span style="color: #0000ff">this</span>.DataContext = <span style="color: #0000ff">this</span>;</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum5" style="color: #606060">   5:</span> }</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum6" style="color: #606060">   6:</span> </pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum7" style="color: #606060">   7:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">string</span> Now</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum8" style="color: #606060">   8:</span> {</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum9" style="color: #606060">   9:</span>     get</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum10" style="color: #606060">  10:</span>     {</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum11" style="color: #606060">  11:</span>         <span style="color: #0000ff">return</span> DateTime.Now.ToString(<span style="color: #006080">"HH:MM d/M/yyyy"</span>);</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum12" style="color: #606060">  12:</span>     }</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum13" style="color: #606060">  13:</span> }</pre>
<p><!--CRLF--></p>
</div>
</div>
<p>and have the UI bind to the Now property:</p>
<div id="codeSnippetWrapper">
<div id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum1" style="color: #606060">   1:</span> <span style="color: #0000ff">&lt;</span><span style="color: #800000">Window</span> <span style="color: #ff0000">x:Class</span><span style="color: #0000ff">="BindingFormat.Window1"</span></pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum2" style="color: #606060">   2:</span>     <span style="color: #ff0000">xmlns</span><span style="color: #0000ff">="http://schemas.microsoft.com/winfx/2006/xaml/presentation"</span></pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum3" style="color: #606060">   3:</span>     <span style="color: #ff0000">xmlns:x</span><span style="color: #0000ff">="http://schemas.microsoft.com/winfx/2006/xaml"</span></pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum4" style="color: #606060">   4:</span>     <span style="color: #ff0000">Title</span><span style="color: #0000ff">="Window1"</span> <span style="color: #ff0000">Height</span><span style="color: #0000ff">="300"</span> <span style="color: #ff0000">Width</span><span style="color: #0000ff">="300"</span><span style="color: #0000ff">&gt;</span></pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum5" style="color: #606060">   5:</span>     <span style="color: #0000ff">&lt;</span><span style="color: #800000">Grid</span><span style="color: #0000ff">&gt;</span></pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum6" style="color: #606060">   6:</span>         <span style="color: #0000ff">&lt;</span><span style="color: #800000">TextBlock</span> <span style="color: #ff0000">Text</span><span style="color: #0000ff">="{Binding Now}"</span><span style="color: #0000ff">&gt;&lt;/</span><span style="color: #800000">TextBlock</span><span style="color: #0000ff">&gt;</span></pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum7" style="color: #606060">   7:</span>     <span style="color: #0000ff">&lt;/</span><span style="color: #800000">Grid</span><span style="color: #0000ff">&gt;</span></pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum8" style="color: #606060">   8:</span> <span style="color: #0000ff">&lt;/</span><span style="color: #800000">Window</span><span style="color: #0000ff">&gt;</span></pre>
<p><!--CRLF--></p>
</div>
</div>
<p>The outcome is what we wanted:</p>
<p align="center"><a href="http://dev102.com/Dev102/wp-content/uploads/2009/05/usingpropertytoformat.png"><img style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" title="Using Property to format" src="http://dev102.com/Dev102/wp-content/uploads/2009/05/usingpropertytoformat-thumb.png" border="0" alt="Using Property to format" width="292" height="293" /></a></p>
<p>I don&#8217;t like this way of work for 2 reasons:</p>
<ol>
<li>It ads clutter to the code behind and mixes data and UI elements because the Now property is strictly UI but it resides in the Data of the application.</li>
<li>There is no way to reuse it, we would have to duplicate the property anywhere we need to display this particular format.</li>
</ol>
<h3><span style="text-decoration: underline;">Using a ValueConverter</span></h3>
<p>This is a much better way of work because it solves the 2 problems I had with the Property method of formatting data. Using a converter keeps UI logic in the UI, removes the clutter from the code behind and is reusable.</p>
<p> </p>
<p>Here is how we do it:</p>
<p> </p>
<p>First we add the converter:</p>
<div id="codeSnippetWrapper">
<div id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum1" style="color: #606060">   1:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">class</span> DateTimeConverter : IValueConverter</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum2" style="color: #606060">   2:</span> {</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum3" style="color: #606060">   3:</span>     <span style="color: #cc6633">#region</span> IValueConverter Members</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum4" style="color: #606060">   4:</span> </pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum5" style="color: #606060">   5:</span>     <span style="color: #0000ff">public</span> <span style="color: #0000ff">object</span> Convert(<span style="color: #0000ff">object</span> <span style="color: #0000ff">value</span>, Type targetType, <span style="color: #0000ff">object</span> parameter</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum6" style="color: #606060">   6:</span>                         , System.Globalization.CultureInfo culture)</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum7" style="color: #606060">   7:</span>     {</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum8" style="color: #606060">   8:</span>         <span style="color: #0000ff">if</span> (<span style="color: #0000ff">value</span> <span style="color: #0000ff">is</span> DateTime)</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum9" style="color: #606060">   9:</span>         {</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum10" style="color: #606060">  10:</span>             DateTime d = (DateTime)<span style="color: #0000ff">value</span>;</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum11" style="color: #606060">  11:</span>             <span style="color: #0000ff">return</span> d.ToString(<span style="color: #006080">"HH:MM d/M/yyyy"</span>);</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum12" style="color: #606060">  12:</span>         }</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum13" style="color: #606060">  13:</span>         <span style="color: #0000ff">return</span> <span style="color: #0000ff">string</span>.Empty;</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum14" style="color: #606060">  14:</span>     }</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum15" style="color: #606060">  15:</span> </pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum16" style="color: #606060">  16:</span>     <span style="color: #0000ff">public</span> <span style="color: #0000ff">object</span> ConvertBack(<span style="color: #0000ff">object</span> <span style="color: #0000ff">value</span>, Type targetType, <span style="color: #0000ff">object</span> parameter</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum17" style="color: #606060">  17:</span>                             , System.Globalization.CultureInfo culture)</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum18" style="color: #606060">  18:</span>     {</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum19" style="color: #606060">  19:</span>         <span style="color: #0000ff">throw</span> <span style="color: #0000ff">new</span> NotImplementedException();</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum20" style="color: #606060">  20:</span>     }</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum21" style="color: #606060">  21:</span> </pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum22" style="color: #606060">  22:</span>     <span style="color: #cc6633">#endregion</span></pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum23" style="color: #606060">  23:</span> }</pre>
<p><!--CRLF--></p>
</div>
</div>
<p>Use it with the binding:</p>
<div id="codeSnippetWrapper">
<div id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum1" style="color: #606060">   1:</span> <span style="color: #0000ff">&lt;</span><span style="color: #800000">Window</span> <span style="color: #ff0000">x:Class</span><span style="color: #0000ff">="BindingFormat.Window1"</span></pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum2" style="color: #606060">   2:</span>     <span style="color: #ff0000">xmlns</span><span style="color: #0000ff">="http://schemas.microsoft.com/winfx/2006/xaml/presentation"</span></pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum3" style="color: #606060">   3:</span>     <span style="color: #ff0000">xmlns:x</span><span style="color: #0000ff">="http://schemas.microsoft.com/winfx/2006/xaml"</span></pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum4" style="color: #606060">   4:</span>         <span style="color: #ff0000">xmlns:local</span><span style="color: #0000ff">="clr-namespace:BindingFormat"</span></pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum5" style="color: #606060">   5:</span>     <span style="color: #ff0000">Title</span><span style="color: #0000ff">="Window1"</span> <span style="color: #ff0000">Height</span><span style="color: #0000ff">="300"</span> <span style="color: #ff0000">Width</span><span style="color: #0000ff">="300"</span><span style="color: #0000ff">&gt;</span></pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum6" style="color: #606060">   6:</span>     <span style="color: #0000ff">&lt;</span><span style="color: #800000">Window.Resources</span><span style="color: #0000ff">&gt;</span></pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum7" style="color: #606060">   7:</span>         <span style="color: #0000ff">&lt;</span><span style="color: #800000">local:DateTimeConverter</span> <span style="color: #ff0000">x:Key</span><span style="color: #0000ff">="BindingCVR"</span><span style="color: #0000ff">/&gt;</span></pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum8" style="color: #606060">   8:</span>     <span style="color: #0000ff">&lt;/</span><span style="color: #800000">Window.Resources</span><span style="color: #0000ff">&gt;</span></pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum9" style="color: #606060">   9:</span>     <span style="color: #0000ff">&lt;</span><span style="color: #800000">Grid</span><span style="color: #0000ff">&gt;</span></pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum10" style="color: #606060">  10:</span>         <span style="color: #0000ff">&lt;</span><span style="color: #800000">TextBlock</span> <span style="color: #ff0000">Text</span><span style="color: #0000ff">="{Binding Converter={StaticResource BindingCVR}}"</span><span style="color: #0000ff">/&gt;</span></pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum11" style="color: #606060">  11:</span>     <span style="color: #0000ff">&lt;/</span><span style="color: #800000">Grid</span><span style="color: #0000ff">&gt;</span></pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum12" style="color: #606060">  12:</span> <span style="color: #0000ff">&lt;/</span><span style="color: #800000">Window</span><span style="color: #0000ff">&gt;</span></pre>
<p><!--CRLF--></p>
</div>
</div>
<p>And have the DataContext be DateTime.Now:</p>
<div id="codeSnippetWrapper">
<div id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum1" style="color: #606060">   1:</span> <span style="color: #0000ff">public</span> Window1()</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum2" style="color: #606060">   2:</span> {</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum3" style="color: #606060">   3:</span>    InitializeComponent();</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum4" style="color: #606060">   4:</span>    DateTime d = DateTime.Now;</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum5" style="color: #606060">   5:</span>    <span style="color: #0000ff">this</span>.DataContext = d;</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum6" style="color: #606060">   6:</span> }</pre>
<p><!--CRLF--></p>
</div>
</div>
<p>And the outcome? Just as before:</p>
<p align="center"><a href="http://dev102.com/Dev102/wp-content/uploads/2009/05/usingpropertytoformat.png"><img style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" title="Using Property to format" src="http://dev102.com/Dev102/wp-content/uploads/2009/05/usingpropertytoformat-thumb.png" border="0" alt="Using Property to format" width="292" height="293" /></a></p>
<p>The only drawback to this method is that it is takes more effort.</p>
<p> </p>
<p>But we just got lucky..</p>
<p> </p>
<h3><span style="text-decoration: underline;">Using Binding.StringFormat</span></h3>
<p>In .NET 3.5 SP1 we got the<a href="http://www.dev102.com/2008/04/16/how-to-use-aggregate-functions-with-linq-to-sql/"> StringFormat </a>option in Binding!</p>
<p> </p>
<p>This makes things so much easier All we have to do is have the Binding Expression look like this:</p>
<div id="codeSnippetWrapper">
<div id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum1" style="color: #606060">   1:</span> <span style="color: #0000ff">&lt;</span><span style="color: #800000">TextBlock</span> <span style="color: #ff0000">Text</span><span style="color: #0000ff">="{Binding StringFormat='HH:MM d/M/yyyy'}"</span><span style="color: #0000ff">/&gt;</span></pre>
<p><!--CRLF--></p>
</div>
</div>
<p>And that&#8217;s it, no extra Properties and ValueConverters.</p>
<p> </p>
<p>I could have copied the image again but trust me it gives the same outcome in a much more elegant way.</p>
<p> </p>
<p>Do you have a different way of work? let me know.</p>
<p> </p>
<p>Enjoy</p>
<p> </p>
<p>Amit</p>

<p><a href="http://feedads.g.doubleclick.net/~a/ytUpR-xzOCa7ZoUUr4ZT_s0z_p4/0/da"><img src="http://feedads.g.doubleclick.net/~a/ytUpR-xzOCa7ZoUUr4ZT_s0z_p4/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/ytUpR-xzOCa7ZoUUr4ZT_s0z_p4/1/da"><img src="http://feedads.g.doubleclick.net/~a/ytUpR-xzOCa7ZoUUr4ZT_s0z_p4/1/di" border="0" ismap="true"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/Dev102feed?a=0cVbBlkromE:A6e9ctC2NwY:NT3aGUK8eJ0"><img src="http://feeds.feedburner.com/~ff/Dev102feed?d=NT3aGUK8eJ0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Dev102feed?a=0cVbBlkromE:A6e9ctC2NwY:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/Dev102feed?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Dev102feed?a=0cVbBlkromE:A6e9ctC2NwY:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/Dev102feed?i=0cVbBlkromE:A6e9ctC2NwY:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Dev102feed?a=0cVbBlkromE:A6e9ctC2NwY:dnMXMwOfBR0"><img src="http://feeds.feedburner.com/~ff/Dev102feed?d=dnMXMwOfBR0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Dev102feed?a=0cVbBlkromE:A6e9ctC2NwY:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/Dev102feed?i=0cVbBlkromE:A6e9ctC2NwY:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Dev102feed?a=0cVbBlkromE:A6e9ctC2NwY:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/Dev102feed?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Dev102feed?a=0cVbBlkromE:A6e9ctC2NwY:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/Dev102feed?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Dev102feed?a=0cVbBlkromE:A6e9ctC2NwY:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/Dev102feed?i=0cVbBlkromE:A6e9ctC2NwY:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Dev102feed?a=0cVbBlkromE:A6e9ctC2NwY:TzevzKxY174"><img src="http://feeds.feedburner.com/~ff/Dev102feed?d=TzevzKxY174" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/Dev102feed/~4/0cVbBlkromE" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.dev102.com/2009/05/28/formatting-your-wpf-data-stringformat-is-in-the-house/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.dev102.com/2009/05/28/formatting-your-wpf-data-stringformat-is-in-the-house/</feedburner:origLink></item>
		<item>
		<title>Creating Gapped and Bulleted Shapes in WPF/Silverlight</title>
		<link>http://feedproxy.google.com/~r/Dev102feed/~3/qr1x-HU0Isk/</link>
		<comments>http://www.dev102.com/2009/05/25/creating-gapped-and-bulleted-shapes-in-wpfsilverlight/#comments</comments>
		<pubDate>Mon, 25 May 2009 18:25:45 +0000</pubDate>
		<dc:creator>Amit</dc:creator>
		
		<category><![CDATA[.Net]]></category>

		<category><![CDATA[Silverlight]]></category>

		<category><![CDATA[WPF]]></category>

		<category><![CDATA[BulletedPath]]></category>

		<category><![CDATA[Bullets]]></category>

		<category><![CDATA[OpacityMask]]></category>

		<category><![CDATA[Shape]]></category>

		<guid isPermaLink="false">http://www.dev102.com/2009/05/25/creating-gapped-and-bulleted-shapes-in-wpfsilverlight/</guid>
		<description><![CDATA[<p><u></u></p>

<p>This article was written by<em> Alan Mendelevich</em></p>

<p><em></em></p>

<h3><u>The Problem</u></h3>

<p>Creating a shape with bullets on the joints of it's segments sounds like a really trivial task at a first glance. Just plaster some bullets on top of the shape. And it is really something like this until you decide you want to have transparent outlined bullets or opaque bullets with transparent outline around them. Like the ones in this picture:</p>

<p align="center"><a href="http://dev102.com/Dev102/wp-content/uploads/2009/05/bulleted-path-samples-thumb.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="bulleted_path_samples" border="0" alt="bulleted_path_samples" src="http://dev102.com/Dev102/wp-content/uploads/2009/05/bulleted-path-samples.png" width="331" height="319" /></a> </p>

<p align="center">&#160;</p>]]></description>
			<content:encoded><![CDATA[<p><u></u></p>
<p>This article was written by<em> Alan Mendelevich</em></p>
<p><em></em></p>
<p><em></em></p>
<h3><u>The Problem</u></h3>
<p>Creating a shape with bullets on the joints of it&#8217;s segments sounds like a really trivial task at a first glance. Just plaster some bullets on top of the shape. And it is really something like this until you decide you want to have transparent outlined bullets or opaque bullets with transparent outline around them. Like the ones in this picture:</p>
<p align="center"><a href="http://dev102.com/Dev102/wp-content/uploads/2009/05/bulleted-path-samples.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="bulleted_path_samples" border="0" alt="bulleted_path_samples" src="http://dev102.com/Dev102/wp-content/uploads/2009/05/bulleted-path-samples-thumb.png" width="331" height="319" /></a> </p>
<p align="center">&#160;</p>
<p>In raster scenarios this could be solved by simply deleting the pixels around the joint points but since we are talking about <a href="http://www.dev102.com/2008/09/25/wpf-binding-converter-best-practices-continued/">WPF</a> or <a href="http://www.dev102.com/2009/02/26/creating-a-wpf-silverlight-control-with-a-semi-transparent-background/">Silverlight</a> (vector graphics) this is not an option. </p>
<p>If you have a simplistic figure like the first rectangle in the above picture you may think about just creating shorter lines for it&#8217;s sides. This is not a very complicated task. However in the second (triangle) example calculating the end points for the lines gets a little more complicated. And try doing this without a masters degree in mathematics for the third and fourth (bottom) examples utilizing arcs and Bezier curves.</p>
<p>The second option is to cheat a little. You can use background color for bullet&#8217;s fill or outline. This would work well on a solid color background. But what if you have a gradient background (like in our sample picture), image background or if your bullet falls on the edge of some object or the shape itself?</p>
<p>I have faced this issue when working on a <u><a href="http://wpf.amcharts.com/line/" rel="nofollow">line chart</a></u> portion of <u><a href="http://wpf.amcharts.com/" rel="nofollow">amCharts for WPF</a></u> and here&#8217;s how I solved it.</p>
<p>&#160;</p>
<h3><u>The Solution</u></h3>
<p>The magic word for my solution is <u><a href="http://msdn.microsoft.com/en-us/library/system.windows.uielement.opacitymask.aspx" rel="nofollow">OpacityMask</a></u>. To quote MSDN documentation what it does is:</p>
<blockquote><p>Gets or sets an opacity mask, as a Brush implementation that is applied to any alpha-channel masking for the rendered content of this element.</p>
</blockquote>
<p>In other words it lets you apply different levels of opacity to different portions of your element.</p>
<p>So, the general idea is to create an opacity mask which has zero opacity spots in place where we want to put our bullets and 100% opacity everywhere else. Below are the main parts of the implementation along with some small but very important details.</p>
<ul>
<li>We derive our BulletedPath class from the abstract <u><a href="http://msdn.microsoft.com/en-us/library/system.windows.shapes.shape.aspx" rel="nofollow">Shape</a></u> class. <u><a href="http://msdn.microsoft.com/en-us/library/system.windows.shapes.path.aspx" rel="nofollow">Path</a></u> could&#8217;ve been a better base class candidate, but unfortunately it&#8217;s sealed. </li>
<li>We add several bullet related dependency properties for controlling bullet shape, fill and outline. </li>
<li>We add a Data property which will store <u><a href="http://msdn.microsoft.com/en-us/library/system.windows.media.pathgeometry.aspx" rel="nofollow">PathGeometry</a></u> defining our shape. </li>
</ul>
<p>With all this done (you can see the implementation by downloading the source code for the control linked at the end of the article) we override OnRender method of our shape.</p>
<p>Here&#8217;s the method in it&#8217;s entirety and we&#8217;ll examine what it does below:</p>
<div id="codeSnippetWrapper">
<div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum1">   1:</span> <span style="color: #0000ff">protected</span> <span style="color: #0000ff">override</span> <span style="color: #0000ff">void</span> OnRender(DrawingContext drawingContext)</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum2">   2:</span> {</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum3">   3:</span>     Pen shapePen = <span style="color: #0000ff">new</span> Pen(<span style="color: #0000ff">this</span>.Stroke, <span style="color: #0000ff">this</span>.StrokeThickness);</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum4">   4:</span>     shapePen.StartLineCap = <span style="color: #0000ff">this</span>.StrokeStartLineCap;</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum5">   5:</span>     shapePen.EndLineCap = <span style="color: #0000ff">this</span>.StrokeEndLineCap;</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum6">   6:</span>     shapePen.DashCap = <span style="color: #0000ff">this</span>.StrokeDashCap;</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum7">   7:</span>     shapePen.LineJoin = <span style="color: #0000ff">this</span>.StrokeLineJoin;</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum8">   8:</span>     shapePen.MiterLimit = <span style="color: #0000ff">this</span>.StrokeMiterLimit;</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum9">   9:</span>     shapePen.DashStyle = </pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum10">  10:</span>         <span style="color: #0000ff">new</span> DashStyle(<span style="color: #0000ff">this</span>.StrokeDashArray, <span style="color: #0000ff">this</span>.StrokeDashOffset);</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum11">  11:</span>     <span style="color: #008000">// a create temporary drawing to find out </span></pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum12">  12:</span>     <span style="color: #008000">// real bounds of our shape using specified pen</span></pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum13">  13:</span>     GeometryDrawing maskBoundsDrawing = </pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum14">  14:</span>         <span style="color: #0000ff">new</span> GeometryDrawing(Brushes.Black, shapePen, <span style="color: #0000ff">this</span>.Data);</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum15">  15:</span>     Rect bounds = maskBoundsDrawing.Bounds;</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum16">  16:</span>     <span style="color: #008000">// create opacity mask for bullet holes</span></pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum17">  17:</span>     GeometryGroup holes = <span style="color: #0000ff">this</span>.GetHoles();</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum18">  18:</span>     RectangleGeometry maskRect = <span style="color: #0000ff">new</span> RectangleGeometry(bounds);</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum19">  19:</span>     Geometry maskGeometry = </pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum20">  20:</span>         Geometry.Combine(maskRect, holes, GeometryCombineMode.Exclude, <span style="color: #0000ff">null</span>);</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum21">  21:</span>     GeometryDrawing maskDrawing = </pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum22">  22:</span>         <span style="color: #0000ff">new</span> GeometryDrawing(Brushes.Black, <span style="color: #0000ff">null</span>, maskGeometry);</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum23">  23:</span>     DrawingBrush maskBrush = <span style="color: #0000ff">new</span> DrawingBrush(maskDrawing);</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum24">  24:</span>     maskBrush.Stretch = Stretch.None;</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum25">  25:</span>     <span style="color: #008000">// apply opacity mask</span></pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum26">  26:</span>     drawingContext.PushOpacityMask(maskBrush);</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum27">  27:</span>     <span style="color: #008000">// draw main shape</span></pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum28">  28:</span>     drawingContext.DrawGeometry(<span style="color: #0000ff">this</span>.Fill, shapePen, <span style="color: #0000ff">this</span>.Data);</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum29">  29:</span>     drawingContext.Pop();</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum30">  30:</span>     <span style="color: #008000">// draw bullets</span></pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum31">  31:</span>     RenderBullets(drawingContext);</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum32">  32:</span> }</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum33">  33:</span>&#160; </pre>
<p><!--CRLF--></div>
</div>
<p>First we construct a pen to use for drawing the outline of our shape. Oddly enough Shape class doesn&#8217;t provide one property for setting the Pen. This is justified by the fact that it&#8217;s easier to set (and animate) individual properties of the pen on the whole shape object in <a href="http://www.dev102.com/2009/03/02/tidy-up-your-xaml-and-code-behind-use-usercontrols-inside-templates/">XAML</a> rather than creating a dedicated object for the outline pen.</p>
<p>This is understandable, however it would be really nice of Microsoft to provide a method to get a real Pen out of all these individual properties. This is a good candidate for an extension method, but that&#8217;s another story and for now we just construct the pen manually.</p>
<div id="codeSnippetWrapper">
<div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum1">   1:</span> Pen shapePen = <span style="color: #0000ff">new</span> Pen(<span style="color: #0000ff">this</span>.Stroke, <span style="color: #0000ff">this</span>.StrokeThickness);</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum2">   2:</span> shapePen.StartLineCap = <span style="color: #0000ff">this</span>.StrokeStartLineCap;</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum3">   3:</span> shapePen.EndLineCap = <span style="color: #0000ff">this</span>.StrokeEndLineCap;</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum4">   4:</span> shapePen.DashCap = <span style="color: #0000ff">this</span>.StrokeDashCap;</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum5">   5:</span> shapePen.LineJoin = <span style="color: #0000ff">this</span>.StrokeLineJoin;</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum6">   6:</span> shapePen.MiterLimit = <span style="color: #0000ff">this</span>.StrokeMiterLimit;</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum7">   7:</span> shapePen.DashStyle = </pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum8">   8:</span>         <span style="color: #0000ff">new</span> DashStyle(<span style="color: #0000ff">this</span>.StrokeDashArray, <span style="color: #0000ff">this</span>.StrokeDashOffset);</pre>
<p><!--CRLF--></div>
</div>
<p>Now comes a tricky part.</p>
<p>&#160;</p>
<p>We need to construct our opacity mask. Opacity mask is a Brush and it gets applied to the whole drawing area of the element. The size of that area depends not only on the geometry of our shape but on the size of it&#8217;s stroke, it&#8217;s miter, etc. For example if you have a line from point (0, 0) to (0, 100) and the StrokeThickness is set to 100 you&#8217;d get a line that (at the very least) occupies space from -50 to 50 on the Y-axis and it could be more dependent on the caps of that line and other settings. So, in order to get the final bounds of our shape before we actually draw it we create a temporary drawing using our actual pen settings and use it&#8217;s bounds as a rectangle area for our mask:</p>
<div id="codeSnippetWrapper">
<div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum1">   1:</span> GeometryDrawing maskBoundsDrawing = </pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum2">   2:</span>     <span style="color: #0000ff">new</span> GeometryDrawing(Brushes.Black, shapePen, <span style="color: #0000ff">this</span>.Data);</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum3">   3:</span> Rect bounds = maskBoundsDrawing.Bounds;</pre>
<p><!--CRLF--></div>
</div>
<p>Then we get the geometries for our bullet holes (see the source code for details) and exclude them from our rectangular area. This way we get a geometry which is a rectangle with a holes in it.</p>
<div id="codeSnippetWrapper">
<div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum1">   1:</span> RectangleGeometry maskRect = <span style="color: #0000ff">new</span> RectangleGeometry(bounds);</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum2">   2:</span> Geometry maskGeometry = </pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum3">   3:</span>     Geometry.Combine(maskRect, holes, GeometryCombineMode.Exclude, <span style="color: #0000ff">null</span>);</pre>
<p><!--CRLF--></div>
</div>
<p>Now we need to create a brush for our opacity mask from this geometry. </p>
<p>We create a GeometryDrawing using any opaque brush for it&#8217;s fill (Brushes.Black for example) and create a DrawingBrush from this drawing. It&#8217;s important to set brush&#8217;s Stretch property to None so it&#8217;s not distorted in any way.</p>
<div id="codeSnippetWrapper">
<div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum1">   1:</span> GeometryDrawing maskDrawing = </pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum2">   2:</span>     <span style="color: #0000ff">new</span> GeometryDrawing(Brushes.Black, <span style="color: #0000ff">null</span>, maskGeometry);</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum3">   3:</span> DrawingBrush maskBrush = <span style="color: #0000ff">new</span> DrawingBrush(maskDrawing);</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum4">   4:</span> maskBrush.Stretch = Stretch.None;</pre>
<p><!--CRLF--></div>
</div>
<p>And now all that&#8217;s left is to push our opacity mask on a DrawingContext, draw our shape (opacity mask will make sure that there are holes on the junction points), pop the mask and draw the bullets:</p>
<div id="codeSnippetWrapper">
<div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum1">   1:</span> <span style="color: #008000">// apply opacity mask</span></pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum2">   2:</span> drawingContext.PushOpacityMask(maskBrush);</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum3">   3:</span> <span style="color: #008000">// draw main shape</span></pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum4">   4:</span> drawingContext.DrawGeometry(<span style="color: #0000ff">this</span>.Fill, shapePen, <span style="color: #0000ff">this</span>.Data);</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum5">   5:</span> drawingContext.Pop();</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum6">   6:</span> <span style="color: #008000">// draw bullets</span></pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum7">   7:</span> RenderBullets(drawingContext);</pre>
<p><!--CRLF--></div>
</div>
<p>And that&#8217;s it.</p>
<p>&#160;</p>
<p>I&#8217;ve omitted implementations of the other reasonably trivial tasks like drawing the bullets from the article but you can always take a look at the implementation by downloading the source code of BulletedPath control.</p>
<p>&#160;</p>
<p>You can download the binary control, C# source code and class reference from <u><a href="http://devblog.ailon.org/devblog/page/Downloads.aspx" rel="nofollow">download section of my blog</a></u>. It&#8217;s released under the <u><a href="http://www.opensource.org/licenses/bsd-license.php">BSD license</a></u> so feel free to use and improve it.</p>
<p>&#160;</p>
<p><i>About the author: Alan Mendelevich is a software developer from Vilnius, Lithuania. He has more than 10 years of professional software development experience for both Web and Windows. Currently he works as a lead developer on </i><u><a href="http://wpf.amcharts.com/"><i>amCharts for WPF</i></a></u><i> project – a charting control suite for WPF platform and </i><u><a href="http://spaweditor.com/"><i>SPAW Editor</i></a></u><i> – open source web based WYSIWYG HTML editor control.</i></p>

<p><a href="http://feedads.g.doubleclick.net/~a/ecLx_K78Pe4Lk0HyHYgU_ghUVV0/0/da"><img src="http://feedads.g.doubleclick.net/~a/ecLx_K78Pe4Lk0HyHYgU_ghUVV0/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/ecLx_K78Pe4Lk0HyHYgU_ghUVV0/1/da"><img src="http://feedads.g.doubleclick.net/~a/ecLx_K78Pe4Lk0HyHYgU_ghUVV0/1/di" border="0" ismap="true"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/Dev102feed?a=qr1x-HU0Isk:0rGq2Ttz6lU:NT3aGUK8eJ0"><img src="http://feeds.feedburner.com/~ff/Dev102feed?d=NT3aGUK8eJ0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Dev102feed?a=qr1x-HU0Isk:0rGq2Ttz6lU:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/Dev102feed?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Dev102feed?a=qr1x-HU0Isk:0rGq2Ttz6lU:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/Dev102feed?i=qr1x-HU0Isk:0rGq2Ttz6lU:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Dev102feed?a=qr1x-HU0Isk:0rGq2Ttz6lU:dnMXMwOfBR0"><img src="http://feeds.feedburner.com/~ff/Dev102feed?d=dnMXMwOfBR0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Dev102feed?a=qr1x-HU0Isk:0rGq2Ttz6lU:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/Dev102feed?i=qr1x-HU0Isk:0rGq2Ttz6lU:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Dev102feed?a=qr1x-HU0Isk:0rGq2Ttz6lU:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/Dev102feed?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Dev102feed?a=qr1x-HU0Isk:0rGq2Ttz6lU:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/Dev102feed?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Dev102feed?a=qr1x-HU0Isk:0rGq2Ttz6lU:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/Dev102feed?i=qr1x-HU0Isk:0rGq2Ttz6lU:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Dev102feed?a=qr1x-HU0Isk:0rGq2Ttz6lU:TzevzKxY174"><img src="http://feeds.feedburner.com/~ff/Dev102feed?d=TzevzKxY174" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/Dev102feed/~4/qr1x-HU0Isk" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.dev102.com/2009/05/25/creating-gapped-and-bulleted-shapes-in-wpfsilverlight/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.dev102.com/2009/05/25/creating-gapped-and-bulleted-shapes-in-wpfsilverlight/</feedburner:origLink></item>
		<item>
		<title>Parameter count mismatch Error</title>
		<link>http://feedproxy.google.com/~r/Dev102feed/~3/u-ykFWvcZJw/</link>
		<comments>http://www.dev102.com/2009/05/19/parameter-count-mismatch-error/#comments</comments>
		<pubDate>Tue, 19 May 2009 10:34:59 +0000</pubDate>
		<dc:creator>Shahar Y</dc:creator>
		
		<category><![CDATA[.Net]]></category>

		<category><![CDATA[C#]]></category>

		<category><![CDATA[BeginInvoke]]></category>

		<category><![CDATA[Error]]></category>

		<category><![CDATA[exception]]></category>

		<category><![CDATA[Invoke]]></category>

		<category><![CDATA[mismatch]]></category>

		<category><![CDATA[parameters]]></category>

		<category><![CDATA[UI]]></category>

		<category><![CDATA[WinForms]]></category>

		<guid isPermaLink="false">http://www.dev102.com/?p=1239</guid>
		<description><![CDATA[<p>Let me share you with one of the weirdest errors I ever encountered. Recently, I have been working on a distributed application which is built from a server and some clients. The clients are Windows Forms applications. Yesterday, I spent a whole day chasing a very weird and strange error - I was getting an exception at the main method (<a href="http://www.dev102.com/2008/04/14/unhandled-exceptions-handle-them/">unhandled exception</a>) of the client application. Here is what I got:</p> <p><a href="http://dev102.com/Dev102/wp-content/uploads/2009/05/image.png" align="center"><img style="border-right-width: 0px; margin: 10px 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="image" src="http://dev102.com/Dev102/wp-content/uploads/2009/05/image-thumb.png" width="577" height="274"></a> </p> <p>The error description was:</p>]]></description>
			<content:encoded><![CDATA[<p>Let me share you with one of the weirdest errors I ever encountered. Recently, I have been working on a distributed application which is built from a server and some clients. The clients are Windows Forms applications. Yesterday, I spent a whole day chasing a very weird and strange error - I was getting an exception at the main method (<a href="http://www.dev102.com/2008/04/14/unhandled-exceptions-handle-them/">unhandled exception</a>) of the client application. Here is what I got:</p>
<p><a href="http://dev102.com/Dev102/wp-content/uploads/2009/05/image.png" align="center"><img style="border-right-width: 0px; margin: 10px 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="image" src="http://dev102.com/Dev102/wp-content/uploads/2009/05/image-thumb.png" width="577" height="274"></a> </p>
<p>The error description was: &#8220;<strong>Parameters count mismatch</strong>&#8220;. Well, it didn&#8217;t help me a lot, but I thought that looking at the stack trace might be a good idea. So, here it is:</p>
<p><a href="http://dev102.com/Dev102/wp-content/uploads/2009/05/image1.png"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="image" src="http://dev102.com/Dev102/wp-content/uploads/2009/05/image-thumb1.png" width="577" height="230"></a> </p>
<p>As you can see, there is nothing helpful here because the stack trace is full of .Net Framework methods, none of those methods are mine. Well after a whole day, trying to understand what happened, I figured out what was wrong. Take a look at the very simplified version of my code:</p>
<div>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, 'Courier New', courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #0000ff">delegate</span> <span style="color: #0000ff">void</span> ChangeColorEventHandler(<span style="color: #0000ff">object</span> sender, Color color);

<span style="color: #0000ff">private</span> <span style="color: #0000ff">void</span> ChangeColor(<span style="color: #0000ff">object</span> sender, Color newColor)
{
    <span style="color: #0000ff">if</span>(InvokeRequired)
    {
        BeginInvoke(<span style="color: #0000ff">new</span> ChangeColorEventHandler(ChangeColor), newColor);
        <span style="color: #0000ff">return</span>;
    }
    BackColor = newColor;
}</pre>
</div>
<p>The ChangeColor method is changing the form back color on the UI thread. This method was called due to a server request, not because of a user action. Do you see what is wrong here? I didn&#8217;t set the sender as a parameter to the BeginInvoke method. That is it! It turns out that if you get this strange error, you probably called a BeginInvoke or Invoke methods with a wrong set of parameters. After changing my code to: </p>
<div>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, 'Courier New', courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #0000ff">private</span> <span style="color: #0000ff">void</span> ChangeColor(<span style="color: #0000ff">object</span> sender, Color newColor)
{
    <span style="color: #0000ff">if</span>(InvokeRequired)
    {
        BeginInvoke(<span style="color: #0000ff">new</span> ChangeColorEventHandler(ChangeColor), sender, newColor);
        <span style="color: #0000ff">return</span>;
    }
    BackColor = newColor;
}</pre>
</div>
<p>Everything was fine. Hope it would be helpful for some of you one day&#8230;</p>

<p><a href="http://feedads.g.doubleclick.net/~a/Yf0mCIA8APNt3sNv7E2gb7XLmQg/0/da"><img src="http://feedads.g.doubleclick.net/~a/Yf0mCIA8APNt3sNv7E2gb7XLmQg/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/Yf0mCIA8APNt3sNv7E2gb7XLmQg/1/da"><img src="http://feedads.g.doubleclick.net/~a/Yf0mCIA8APNt3sNv7E2gb7XLmQg/1/di" border="0" ismap="true"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/Dev102feed?a=u-ykFWvcZJw:KK9CfmORMW8:NT3aGUK8eJ0"><img src="http://feeds.feedburner.com/~ff/Dev102feed?d=NT3aGUK8eJ0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Dev102feed?a=u-ykFWvcZJw:KK9CfmORMW8:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/Dev102feed?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Dev102feed?a=u-ykFWvcZJw:KK9CfmORMW8:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/Dev102feed?i=u-ykFWvcZJw:KK9CfmORMW8:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Dev102feed?a=u-ykFWvcZJw:KK9CfmORMW8:dnMXMwOfBR0"><img src="http://feeds.feedburner.com/~ff/Dev102feed?d=dnMXMwOfBR0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Dev102feed?a=u-ykFWvcZJw:KK9CfmORMW8:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/Dev102feed?i=u-ykFWvcZJw:KK9CfmORMW8:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Dev102feed?a=u-ykFWvcZJw:KK9CfmORMW8:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/Dev102feed?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Dev102feed?a=u-ykFWvcZJw:KK9CfmORMW8:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/Dev102feed?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Dev102feed?a=u-ykFWvcZJw:KK9CfmORMW8:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/Dev102feed?i=u-ykFWvcZJw:KK9CfmORMW8:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Dev102feed?a=u-ykFWvcZJw:KK9CfmORMW8:TzevzKxY174"><img src="http://feeds.feedburner.com/~ff/Dev102feed?d=TzevzKxY174" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/Dev102feed/~4/u-ykFWvcZJw" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.dev102.com/2009/05/19/parameter-count-mismatch-error/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.dev102.com/2009/05/19/parameter-count-mismatch-error/</feedburner:origLink></item>
		<item>
		<title>4 Great Tips for Custom WPF Controls Developers</title>
		<link>http://feedproxy.google.com/~r/Dev102feed/~3/20gxHnyJ31c/</link>
		<comments>http://www.dev102.com/2009/05/04/4-grea-tips-for-custom-wpf-controls-developers/#comments</comments>
		<pubDate>Mon, 04 May 2009 14:57:39 +0000</pubDate>
		<dc:creator>Amit</dc:creator>
		
		<category><![CDATA[.Net]]></category>

		<category><![CDATA[WPF]]></category>

		<category><![CDATA[Attribute]]></category>

		<category><![CDATA[Blend]]></category>

		<category><![CDATA[Custom Controls]]></category>

		<category><![CDATA[design]]></category>

		<category><![CDATA[MetaData]]></category>

		<category><![CDATA[ToolBox]]></category>

		<category><![CDATA[Visual Studio]]></category>

		<guid isPermaLink="false">http://www.dev102.com/?p=1227</guid>
		<description><![CDATA[<p><em>This article was written by Alan Mendelevich</em> </p>

<p><em></em>&#160; </p>

<p>Hi </p>

<p>&#160; </p>

<p>Recently I've been working on a set of <a href="http://wpf.amcharts.com/">custom WPF controls</a>. </p>

<p>There are numerous good books and <a href="http://devblog.ailon.org/devblog/post/2009/04/Book-Review-Pro-WPF-in-C-2008-Windows-Presentation-Foundation-with-NET-352c-Second-Edition-by-Matthew-MacDonald.aspx">articles</a> about WPF in general and some basic information on custom control development but I have yet to find a good article (or book) with in-depth coverage of custom control development in general and design-time related issues in particular. </p>

<p>&#160; </p>]]></description>
			<content:encoded><![CDATA[<p><em>This article was written by Alan Mendelevich</em></p>
<p><em></em> </p>
<p>Hi</p>
<p> </p>
<p>Recently I&#8217;ve been working on a set of <a href="http://wpf.amcharts.com/">custom WPF controls</a>.</p>
<p>There are numerous good books and <a href="http://devblog.ailon.org/devblog/post/2009/04/Book-Review-Pro-WPF-in-C-2008-Windows-Presentation-Foundation-with-NET-352c-Second-Edition-by-Matthew-MacDonald.aspx">articles</a> about WPF in general and some basic information on custom control development but I have yet to find a good article (or book) with in-depth coverage of custom control development in general and design-time related issues in particular.</p>
<p> </p>
<p>I&#8217;ve done my share of custom ASP.NET control development (see ASP.NET Controls for amCharts <a href="http://www.amcharts.com/aspnet">http://www.amcharts.com/aspnet</a>, or SPAW Editor ASP.NET Edition <a href="http://spaweditor.com">http://spaweditor.com</a>), and actually the basic principles are not that different. However some things should be implemented in a totally different manner and it wasn&#8217;t really obvious to me where those differences start and what to do about them. I&#8217;ve spent quite some time figuring these things out, so I decided to share my findings here hoping that it would save someone some time which could be better spent implementing new features.</p>
<p> </p>
<p>This article covers several areas related to <a href="http://www.dev102.com/2008/05/09/6-useful-visual-studio-tweaks-you-need-to-know/">WPF Designer </a>related features/issues which are implemented using different means than you would use while building ASP.NET/WinForms controls.</p>
<p> </p>
<h3><span style="text-decoration: underline;">Metadata Store and Separate Metadata Assembly</span></h3>
<p>Some design-time related attributes like CategoryAttribute (which specifies grouping category in property grid) could be set on a property the “old-fashioned” way, but general approach has switched toward the <a href="http://msdn.microsoft.com/en-us/library/bb546923.aspx">Metadata Store</a>. Metadata store is a mechanism used by WPF Designer to decouple design-time metadata from implementation.</p>
<p> </p>
<p>Design-time metadata is deployed in separate specialized assemblies which should follow specific naming conventions in order for design tools to find and use them. You create an assembly with “.Design” appended to the main assembly name for general design-time metadata.</p>
<p> </p>
<p>For example if you have an implementation assembly called MyLibrary.dll then design-time metadata should reside in MyLibrary.Design.dll. Specialized <a href="http://www.dev102.com/2008/04/29/a-great-visual-studio-add-on-you-must-have/">Visual Studio </a>or Expression Blend metadata could be placed in additional MyLibrary.VisualStudio.Design.dll and MyLibrary.Expression.Design.dll.</p>
<p>In addition to general good design principles, separation of design-time metadata into specialized assemblies has one very practical implication, most of the new attribute classes are defined in the Microsoft.Windows.Design.dll. If you add a reference to this DLL to your implementation project users of your control will most likely get an exception like “Unable to install or run the application. The application requires that the assembly Microsoft.Windows.Design Version 3.5.0.0 be installed in the Global Assembly Cache (GAC) first. Since it&#8217;s not a part of normal .NET deployment runtime.</p>
<p>To create a metadata store, you create a new project, add a reference to Microsoft.Windows.Design.dll to it and create a class that implements IRegisterMetadata interface like this:</p>
<div id="codeSnippetWrapper">
<div id="codeSnippet" style="font-size: 8pt; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; font-family: 'Courier New', courier, monospace; background-color: #f4f4f4; text-align: left; border-style: none; padding: 0px;">
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; font-family: 'Courier New', courier, monospace; background-color: #f4f4f4; text-align: left; border-style: none; padding: 0px;"><span id="lnum1" style="color: #606060">   1:</span> <span style="color: #0000ff">namespace</span>MyLibrary.Design</pre>
<p><!--CRLF--></p>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; font-family: 'Courier New', courier, monospace; background-color: #f4f4f4; text-align: left; border-style: none; padding: 0px;"><span id="lnum2" style="color: #606060">   2:</span> {</pre>
<p><!--CRLF--></p>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; font-family: 'Courier New', courier, monospace; background-color: #f4f4f4; text-align: left; border-style: none; padding: 0px;"><span id="lnum3" style="color: #606060">   3:</span>     <span style="color: #0000ff">internal</span> <span style="color: #0000ff">class</span>MyLibraryMetadata : IRegisterMetadata</pre>
<p><!--CRLF--></p>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; font-family: 'Courier New', courier, monospace; background-color: #f4f4f4; text-align: left; border-style: none; padding: 0px;"><span id="lnum4" style="color: #606060">   4:</span>     {</pre>
<p><!--CRLF--></p>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; font-family: 'Courier New', courier, monospace; background-color: #f4f4f4; text-align: left; border-style: none; padding: 0px;"><span id="lnum5" style="color: #606060">   5:</span>         <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> Register()</pre>
<p><!--CRLF--></p>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; font-family: 'Courier New', courier, monospace; background-color: #f4f4f4; text-align: left; border-style: none; padding: 0px;"><span id="lnum6" style="color: #606060">   6:</span>         {</pre>
<p><!--CRLF--></p>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; font-family: 'Courier New', courier, monospace; background-color: #f4f4f4; text-align: left; border-style: none; padding: 0px;"><span id="lnum7" style="color: #606060">   7:</span>AttributeTableBuilder builder = <span style="color: #0000ff">new</span>AttributeTableBuilder();</pre>
<p><!--CRLF--></p>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; font-family: 'Courier New', courier, monospace; background-color: #f4f4f4; text-align: left; border-style: none; padding: 0px;"><span id="lnum8" style="color: #606060">   8:</span>builder.AddCustomAttributes(<span style="color: #0000ff">typeof</span>(MyClass)</pre>
<p><!--CRLF--></p>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; font-family: 'Courier New', courier, monospace; background-color: #f4f4f4; text-align: left; border-style: none; padding: 0px;"><span id="lnum9" style="color: #606060">   9:</span>                                       ,<span style="color: #0000ff">new</span>ToolboxBrowsableAttribute(<span style="color: #0000ff">false</span>));</pre>
<p><!--CRLF--></p>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; font-family: 'Courier New', courier, monospace; background-color: #f4f4f4; text-align: left; border-style: none; padding: 0px;"><span id="lnum10" style="color: #606060">  10:</span>MetadataStore.AddAttributeTable(builder.CreateTable());</pre>
<p><!--CRLF--></p>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; font-family: 'Courier New', courier, monospace; background-color: #f4f4f4; text-align: left; border-style: none; padding: 0px;"><span id="lnum11" style="color: #606060">  11:</span>         }</pre>
<p><!--CRLF--></p>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; font-family: 'Courier New', courier, monospace; background-color: #f4f4f4; text-align: left; border-style: none; padding: 0px;"><span id="lnum12" style="color: #606060">  12:</span>     }</pre>
<p><!--CRLF--></p>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; font-family: 'Courier New', courier, monospace; background-color: #f4f4f4; text-align: left; border-style: none; padding: 0px;"><span id="lnum13" style="color: #606060">  13:</span> }</pre>
<p><!--CRLF--></p>
</div>
</div>
<p>The IRegisterMetadata interface requires you to implement only one method – Register(). In this method you create an instance of AttributeTableBuilder and add attributes to your classes, properties, methods, etc. one-by-one using AddCustomAttributes() method. Then you add this table to the MetadataStore.</p>
<p> </p>
<h3><span style="text-decoration: underline;">Toolbox visibility</span></h3>
<p>When you create a control library you will most likely create some classes deriving from Control class (or one of it&#8217;s derivatives), you don&#8217;t want then to show up in the Visual Studio toolbox along your main controls. In ASP.NET/WinForms you would use the ToolboxItem(false) attribute to achieve that. However the WPF designer pays no attention to this attribute. For the WPF designer you should use <a href="://msdn.microsoft.com/en-us/library/microsoft.windows.design.toolboxbrowsableattribute.aspx">ToolboxBrowsableAttribute</a>from the Microsoft.Windows.Design namespace. You attach it to your classes like this:</p>
<p> </p>
<div id="codeSnippetWrapper">
<div id="codeSnippet" style="font-size: 8pt; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; font-family: 'Courier New', courier, monospace; background-color: #f4f4f4; text-align: left; border-style: none; padding: 0px;">
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; font-family: 'Courier New', courier, monospace; background-color: #f4f4f4; text-align: left; border-style: none; padding: 0px;"><span id="lnum1" style="color: #606060">   1:</span>builder.AddCustomAttributes(<span style="color: #0000ff">typeof</span>(MyClass)</pre>
<p><!--CRLF--></p>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; font-family: 'Courier New', courier, monospace; background-color: #f4f4f4; text-align: left; border-style: none; padding: 0px;"><span id="lnum2" style="color: #606060">   2:</span>         , <span style="color: #0000ff">new</span>ToolboxBrowsableAttribute(<span style="color: #0000ff">false</span>));</pre>
<p><!--CRLF--></p>
</div>
</div>
<h4> </h4>
<h3><span style="text-decoration: underline;">Toolbox icon</span></h3>
<p>You can add toolbox icon for your controls using <a href="http://msdn.microsoft.com/en-us/library/microsoft.windows.design.thumbnailattribute.aspx">ThumbnailAttribute class</a>. However this attribute was only added in .NET 3.5 Service Pack 1. So, you have to make a choice here, supporting .NET 3.5 without SP1 and earlier versions of the .NET Framework, or specifying different thumbnails for Visual Studio and Expression Blend.</p>
<p>A simple and version agnostic method is to add images named according to the specific naming convention of your project. The convention is to name an image in a form of ClassName.Icon.ext. So, if you have a class named MyControl, then your icon should be named MyControl.Icon.png (for example).</p>
<p> </p>
<h3><span style="text-decoration: underline;">Collection editors</span></h3>
<p>In previous .NET designer technologies you had to create a class derived from System.ComponentModel.Design.CollectionEditor if you wanted to allow users to add objects of more than one type to collections through the collection editor in Visual Studio. The approach is demonstrated in this <a href="http://www.codeproject.com/KB/cs/dzcollectioneditor.aspx#CollectionEditor">CodeProject article</a>.</p>
<p> </p>
<p>In WPF this no longer works.</p>
<p> </p>
<p>But fortunately you can achieve the same result just by setting <a href="http://msdn.microsoft.com/en-us/library/microsoft.windows.design.propertyediting.newitemtypesattribute.aspx">NewItemTypesAttribute</a> on your property. This is how it&#8217;s done. Suppose you have a property defined as a collection of brushes like this:</p>
<div id="codeSnippetWrapper">
<div id="codeSnippet" style="font-size: 8pt; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; font-family: 'Courier New', courier, monospace; background-color: #f4f4f4; text-align: left; border-style: none; padding: 0px;">
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; font-family: 'Courier New', courier, monospace; background-color: #f4f4f4; text-align: left; border-style: none; padding: 0px;"><span id="lnum1" style="color: #606060">   1:</span>List&lt;Brush&gt; MyBrushes;</pre>
<p><!--CRLF--></p>
</div>
</div>
<p>And you want users to be able to add SolidColorBrush and LinearGradientBrush objects to this collection via collection editor in Visual Studio. You do this by attaching NewItemTypesAttribute attribute in Register method of your metadata class like this:</p>
<div id="codeSnippetWrapper">
<div id="codeSnippet" style="font-size: 8pt; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; font-family: 'Courier New', courier, monospace; background-color: #f4f4f4; text-align: left; border-style: none; padding: 0px;">
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; font-family: 'Courier New', courier, monospace; background-color: #f4f4f4; text-align: left; border-style: none; padding: 0px;"><span id="lnum1" style="color: #606060">   1:</span>builder.AddCustomAttributes(<span style="color: #0000ff">typeof</span>(MyClass), <span style="color: #006080">"MyBrushes"</span>,</pre>
<p><!--CRLF--></p>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; font-family: 'Courier New', courier, monospace; background-color: #f4f4f4; text-align: left; border-style: none; padding: 0px;"><span id="lnum2" style="color: #606060">   2:</span>     <span style="color: #0000ff">new</span>NewItemTypesAttribute(<span style="color: #0000ff">typeof</span>(System.Windows.Media.SolidColorBrush),</pre>
<p><!--CRLF--></p>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; font-family: 'Courier New', courier, monospace; background-color: #f4f4f4; text-align: left; border-style: none; padding: 0px;"><span id="lnum3" style="color: #606060">   3:</span>     <span style="color: #0000ff">typeof</span>(System.Windows.Media.LinearGradientBrush)));</pre>
<p><!--CRLF--></p>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; font-family: 'Courier New', courier, monospace; background-color: #f4f4f4; text-align: left; border-style: none; padding: 0px;"><span id="lnum4" style="color: #606060">   4:</span> </pre>
<p><!--CRLF--></p>
</div>
</div>
<p> </p>
<h3><span style="text-decoration: underline;">Conclusion</span></h3>
<p>This article touched only some of the issues which developers new to WPF control development may encounter. As WPF gains more and more popularity eventually someone will write a good book and/or tutorial on the subject. Maybe someone already did and I just wasn&#8217;t lucky to find it. If so, please, let me know by commenting.</p>
<p>However there&#8217;s pretty detailed coverage of WPF designer extensibility in this <a href="http://msdn.microsoft.com/en-us/library/bb546938.aspx">MSDN library section</a>  even though it&#8217;s is not written in a very narrative tutorial-like style.</p>
<p> </p>
<p>Alan.</p>
<p><em></em></p>
<p><em>As a bonus to this article Alan has included a 50% discount coupon for the WPF charting controls (</em><a href="http://wpf.amcharts.com/"><em>http://wpf.amcharts.com</em></a><em>) he has been working on lately. All you have to do is enter “dev102” (without quotes) when ordering it.</em></p>

<p><a href="http://feedads.g.doubleclick.net/~a/pg2FL1zbI5jLytCyX0P8vSHfs_4/0/da"><img src="http://feedads.g.doubleclick.net/~a/pg2FL1zbI5jLytCyX0P8vSHfs_4/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/pg2FL1zbI5jLytCyX0P8vSHfs_4/1/da"><img src="http://feedads.g.doubleclick.net/~a/pg2FL1zbI5jLytCyX0P8vSHfs_4/1/di" border="0" ismap="true"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/Dev102feed?a=20gxHnyJ31c:g-fixkXRdhg:NT3aGUK8eJ0"><img src="http://feeds.feedburner.com/~ff/Dev102feed?d=NT3aGUK8eJ0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Dev102feed?a=20gxHnyJ31c:g-fixkXRdhg:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/Dev102feed?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Dev102feed?a=20gxHnyJ31c:g-fixkXRdhg:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/Dev102feed?i=20gxHnyJ31c:g-fixkXRdhg:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Dev102feed?a=20gxHnyJ31c:g-fixkXRdhg:dnMXMwOfBR0"><img src="http://feeds.feedburner.com/~ff/Dev102feed?d=dnMXMwOfBR0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Dev102feed?a=20gxHnyJ31c:g-fixkXRdhg:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/Dev102feed?i=20gxHnyJ31c:g-fixkXRdhg:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Dev102feed?a=20gxHnyJ31c:g-fixkXRdhg:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/Dev102feed?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Dev102feed?a=20gxHnyJ31c:g-fixkXRdhg:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/Dev102feed?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Dev102feed?a=20gxHnyJ31c:g-fixkXRdhg:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/Dev102feed?i=20gxHnyJ31c:g-fixkXRdhg:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Dev102feed?a=20gxHnyJ31c:g-fixkXRdhg:TzevzKxY174"><img src="http://feeds.feedburner.com/~ff/Dev102feed?d=TzevzKxY174" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/Dev102feed/~4/20gxHnyJ31c" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.dev102.com/2009/05/04/4-grea-tips-for-custom-wpf-controls-developers/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.dev102.com/2009/05/04/4-grea-tips-for-custom-wpf-controls-developers/</feedburner:origLink></item>
		<item>
		<title>How to Create A JQuery Plugin</title>
		<link>http://feedproxy.google.com/~r/Dev102feed/~3/zvmZDSJ7hhc/</link>
		<comments>http://www.dev102.com/2009/04/28/how-to-create-a-jquery-plugin/#comments</comments>
		<pubDate>Tue, 28 Apr 2009 08:12:37 +0000</pubDate>
		<dc:creator>Justin</dc:creator>
		
		<category><![CDATA[Web Development]]></category>

		<category><![CDATA[ASP.NET MVC]]></category>

		<category><![CDATA[JavaScript]]></category>

		<category><![CDATA[jQuery]]></category>

		<category><![CDATA[plugin]]></category>

		<guid isPermaLink="false">http://www.dev102.com/?p=1207</guid>
		<description><![CDATA[JQuery has simplified a lot of my day to day coding. I think it is an amazing little framework and apparently a lot of people do too. Even Microsoft is bundling it with its ASP.NET MVC framework which , as far as I know, a first for open source software. Beyond even handling all the all of the cross browse mess, my favorite part of jQuery is the ability to easily extend the framework through plug-in. That brings us to the topic for this post. We are going to look at how easy it is to create a plug-in for jQuery.
<h3><span style="text-decoration: underline;">What Will Our Plugin Do?</span></h3>
<strong></strong><strong></strong>For this post I want to pick something that is fairly simple yet demonstrates the power of plugins. For this post I am going to show you how to create a plug-in that will highlight keywords in a given block of text. Many websites use something similar when performing searches.
]]></description>
			<content:encoded><![CDATA[<p>JQuery has simplified a lot of my day to day coding. I think it is an amazing little framework and apparently a lot of people do too. Even Microsoft is bundling it with its <a href="http://www.dev102.com/2008/11/13/working-with-aspnet-mvc-part-1/">ASP.NET MVC framework </a>which , as far as I know, a first for open source software. Beyond even handling all the all of the cross browse mess, my favorite part of jQuery is the ability to easily extend the framework through plug-in. That brings us to the topic for this post. We are going to look at how easy it is to create a plug-in for jQuery.</p>
<h3><span style="text-decoration: underline;">What Will Our Plugin Do?</span></h3>
<p><strong></strong><strong></strong>For this post I want to pick something that is fairly simple yet demonstrates the power of plugins. For this post I am going to show you how to create a plug-in that will highlight keywords in a given block of text. Many websites use something similar when performing searches.</p>
<p> </p>
<h3><span style="text-decoration: underline;"><strong>The Anatomy Of A Plugin</strong> </span></h3>
<p><strong></strong><strong></strong>A good guideline to follow when creating the file for your plug-in is use the following convention: jquery.pluginName.js. Keeping this in mind lets create a file called jquery.hightlight.js. Now in our main HTML file we should have something like the following.</p>
<div id="codeSnippetWrapper">
<div id="codeSnippet" style="font-size: 8pt; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; font-family: 'Courier New', courier, monospace; background-color: #f4f4f4; text-align: left; border-style: none; padding: 0px;">
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; font-family: 'Courier New', courier, monospace; background-color: #f4f4f4; text-align: left; border-style: none; padding: 0px;"><span id="lnum1" style="color: #606060">   1:</span> <span style="color: #0000ff">&lt;</span><span style="color: #800000">html</span><span style="color: #0000ff">&gt;</span></pre>
<p><!--CRLF--></p>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; font-family: 'Courier New', courier, monospace; background-color: #f4f4f4; text-align: left; border-style: none; padding: 0px;"><span id="lnum2" style="color: #606060">   2:</span> <span style="color: #0000ff">&lt;</span><span style="color: #800000">head</span><span style="color: #0000ff">&gt;</span></pre>
<p><!--CRLF--></p>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; font-family: 'Courier New', courier, monospace; background-color: #f4f4f4; text-align: left; border-style: none; padding: 0px;"><span id="lnum3" style="color: #606060">   3:</span>     <span style="color: #0000ff">&lt;</span><span style="color: #800000">title</span><span style="color: #0000ff">&gt;</span>My jQuery Plugin<span style="color: #0000ff">&lt;/</span><span style="color: #800000">title</span><span style="color: #0000ff">&gt;</span></pre>
<p><!--CRLF--></p>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; font-family: 'Courier New', courier, monospace; background-color: #f4f4f4; text-align: left; border-style: none; padding: 0px;"><span id="lnum4" style="color: #606060">   4:</span> <span style="color: #0000ff">&lt;/</span><span style="color: #800000">head</span><span style="color: #0000ff">&gt;</span></pre>
<p><!--CRLF--></p>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; font-family: 'Courier New', courier, monospace; background-color: #f4f4f4; text-align: left; border-style: none; padding: 0px;"><span id="lnum5" style="color: #606060">   5:</span> <span style="color: #0000ff">&lt;</span><span style="color: #800000">body</span><span style="color: #0000ff">&gt;</span></pre>
<p><!--CRLF--></p>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; font-family: 'Courier New', courier, monospace; background-color: #f4f4f4; text-align: left; border-style: none; padding: 0px;"><span id="lnum6" style="color: #606060">   6:</span>     <span style="color: #0000ff">&lt;</span><span style="color: #800000">div</span> <span style="color: #ff0000">class</span><span style="color: #0000ff">="mytext"</span><span style="color: #0000ff">&gt;</span></pre>
<p><!--CRLF--></p>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; font-family: 'Courier New', courier, monospace; background-color: #f4f4f4; text-align: left; border-style: none; padding: 0px;"><span id="lnum7" style="color: #606060">   7:</span>         This is some text that contains some words that I want to</pre>
<p><!--CRLF--></p>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; font-family: 'Courier New', courier, monospace; background-color: #f4f4f4; text-align: left; border-style: none; padding: 0px;"><span id="lnum8" style="color: #606060">   8:</span>         highlight using my jQuery plug-in. This plug-in will highlight</pre>
<p><!--CRLF--></p>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; font-family: 'Courier New', courier, monospace; background-color: #f4f4f4; text-align: left; border-style: none; padding: 0px;"><span id="lnum9" style="color: #606060">   9:</span>         all instances of the one or more words it is</pre>
<p><!--CRLF--></p>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; font-family: 'Courier New', courier, monospace; background-color: #f4f4f4; text-align: left; border-style: none; padding: 0px;"><span id="lnum10" style="color: #606060">  10:</span>         given.</pre>
<p><!--CRLF--></p>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; font-family: 'Courier New', courier, monospace; background-color: #f4f4f4; text-align: left; border-style: none; padding: 0px;"><span id="lnum11" style="color: #606060">  11:</span>     <span style="color: #0000ff">&lt;/</span><span style="color: #800000">div</span><span style="color: #0000ff">&gt;</span></pre>
<p><!--CRLF--></p>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; font-family: 'Courier New', courier, monospace; background-color: #f4f4f4; text-align: left; border-style: none; padding: 0px;"><span id="lnum12" style="color: #606060">  12:</span>     <span style="color: #0000ff">&lt;</span><span style="color: #800000">script</span> <span style="color: #ff0000">type</span><span style="color: #0000ff">="text/javascript"</span> <span style="color: #ff0000">src</span><span style="color: #0000ff">="jquery-1.3.2.js"</span><span style="color: #0000ff">&gt;&lt;/</span><span style="color: #800000">script</span><span style="color: #0000ff">&gt;</span><!--CRLF--><!--CRLF-->
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; font-family: 'Courier New', courier, monospace; background-color: white; text-align: left; border-style: none; padding: 0px;"><span id="lnum3" style="color: #606060">   3:</span>     &lt;script type=<span style="color: #006080">"text/javascript"</span> src=<span style="color: #006080">"jquery.plugin.js"</span>&gt;&lt;/script&gt;</pre>
<p><!--CRLF--><!--CRLF--><!--CRLF--></p>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; font-family: 'Courier New', courier, monospace; background-color: white; text-align: left; border-style: none; padding: 0px;"><span id="lnum3" style="color: #606060">   3:</span>     &lt;script type=<span style="color: #006080">"text/javascript"</span>&gt;<span style="color: #0000ff">&lt;/</span><span style="color: #800000">script</span><span style="color: #0000ff">&gt;</span></pre>
<p><!--CRLF--></pre>
<p><!--CRLF--></p>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; font-family: 'Courier New', courier, monospace; background-color: #f4f4f4; text-align: left; border-style: none; padding: 0px;"><span id="lnum13" style="color: #606060">  13:</span> <span style="color: #0000ff">&lt;/</span><span style="color: #800000">body</span><span style="color: #0000ff">&gt;</span></pre>
<p><!--CRLF--></p>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; font-family: 'Courier New', courier, monospace; background-color: #f4f4f4; text-align: left; border-style: none; padding: 0px;"><span id="lnum14" style="color: #606060">  14:</span> <span style="color: #0000ff">&lt;/</span><span style="color: #800000">html</span><span style="color: #0000ff">&gt;</span></pre>
<p><!--CRLF--></p>
</div>
</div>
<p>In jquery.highlight.js we will create the shell of our plug-in.</p>
<div id="codeSnippetWrapper">
<div id="codeSnippet" style="font-size: 8pt; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; font-family: 'Courier New', courier, monospace; background-color: #f4f4f4; text-align: left; border-style: none; padding: 0px;">
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; font-family: 'Courier New', courier, monospace; background-color: #f4f4f4; text-align: left; border-style: none; padding: 0px;"><span id="lnum1" style="color: #606060">   1:</span> (<span style="color: #0000ff">function</span>($)</pre>
<p><!--CRLF--></p>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; font-family: 'Courier New', courier, monospace; background-color: #f4f4f4; text-align: left; border-style: none; padding: 0px;"><span id="lnum2" style="color: #606060">   2:</span> {</pre>
<p><!--CRLF--></p>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; font-family: 'Courier New', courier, monospace; background-color: #f4f4f4; text-align: left; border-style: none; padding: 0px;"><span id="lnum3" style="color: #606060">   3:</span>     $.fn.highlight = <span style="color: #0000ff">function</span>(words, options)</pre>
<p><!--CRLF--></p>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; font-family: 'Courier New', courier, monospace; background-color: #f4f4f4; text-align: left; border-style: none; padding: 0px;"><span id="lnum4" style="color: #606060">   4:</span>     {</pre>
<p><!--CRLF--></p>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; font-family: 'Courier New', courier, monospace; background-color: #f4f4f4; text-align: left; border-style: none; padding: 0px;"><span id="lnum5" style="color: #606060">   5:</span>         <span style="color: #0000ff">var</span> defaults = { };</pre>
<p><!--CRLF--></p>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; font-family: 'Courier New', courier, monospace; background-color: #f4f4f4; text-align: left; border-style: none; padding: 0px;"><span id="lnum6" style="color: #606060">   6:</span>         <span style="color: #0000ff">var</span> options = $.extend(defaults, options);</pre>
<p><!--CRLF--></p>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; font-family: 'Courier New', courier, monospace; background-color: #f4f4f4; text-align: left; border-style: none; padding: 0px;"><span id="lnum7" style="color: #606060">   7:</span>         <span style="color: #0000ff">if</span>(<span style="color: #0000ff">typeof</span> words == <span style="color: #006080">'string'</span>)</pre>
<p><!--CRLF--></p>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; font-family: 'Courier New', courier, monospace; background-color: #f4f4f4; text-align: left; border-style: none; padding: 0px;"><span id="lnum8" style="color: #606060">   8:</span>         {</pre>
<p><!--CRLF--></p>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; font-family: 'Courier New', courier, monospace; background-color: #f4f4f4; text-align: left; border-style: none; padding: 0px;"><span id="lnum9" style="color: #606060">   9:</span>             words = [ words ];</pre>
<p><!--CRLF--></p>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; font-family: 'Courier New', courier, monospace; background-color: #f4f4f4; text-align: left; border-style: none; padding: 0px;"><span id="lnum10" style="color: #606060">  10:</span>         }</pre>
<p><!--CRLF--></p>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; font-family: 'Courier New', courier, monospace; background-color: #f4f4f4; text-align: left; border-style: none; padding: 0px;"><span id="lnum11" style="color: #606060">  11:</span>         <span style="color: #0000ff">return</span> <span style="color: #0000ff">this</span>.each(<span style="color: #0000ff">function</span>() { });</pre>
<p><!--CRLF--></p>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; font-family: 'Courier New', courier, monospace; background-color: #f4f4f4; text-align: left; border-style: none; padding: 0px;"><span id="lnum12" style="color: #606060">  12:</span>     };</pre>
<p><!--CRLF--></p>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; font-family: 'Courier New', courier, monospace; background-color: #f4f4f4; text-align: left; border-style: none; padding: 0px;"><span id="lnum13" style="color: #606060">  13:</span> })(jQuery);</pre>
<p><!--CRLF--></p>
</div>
</div>
<p>In the above code we are passing the jQuery object into our plug-in so we can extend it. It is recommend that you <a href="http://www.dev102.com/2009/03/23/creating-an-ajax-login-form-with-jquery/">use jQuery </a>instead of $ to avoid conflicts with other libraries.</p>
<p> </p>
<p>Plugins always extend the fn object of jQuery as you can see where we created $.fn.highlight. Next we created a defaults object which we will fill out later on and then merge the defaults with the passed in options. On the next line we check to see of the words object is a string. If it is we turn it into an array. This way the plug-in will accept a single word as a string or an array of words to be highlighted. Finally, we return the this object which contains all the elements that jQuery found that met the selector we used. Before the plug-in returns it loops over each of the found elements so we can do our highlighting on them.</p>
<p> </p>
<h3><span style="text-decoration: underline;">Completing Our Plugin</span></h3>
<p><strong></strong><strong></strong>Using the shell we created above we can create the code that does the highlighting. First lets define our default values in case there aren&#8217;t any options passed into the plug-in.</p>
<div id="codeSnippetWrapper">
<div id="codeSnippet" style="font-size: 8pt; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; font-family: 'Courier New', courier, monospace; background-color: #f4f4f4; text-align: left; border-style: none; padding: 0px;">
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; font-family: 'Courier New', courier, monospace; background-color: #f4f4f4; text-align: left; border-style: none; padding: 0px;"><span id="lnum1" style="color: #606060">   1:</span> <span style="color: #0000ff">var</span> defaults = { backcolor: <span style="color: #006080">'yellow'</span>, forecolor: <span style="color: #006080">'black'</span> };</pre>
<p><!--CRLF--></p>
</div>
</div>
<p>Now let&#8217;s highlight our words.</p>
<div id="codeSnippetWrapper">
<div id="codeSnippet" style="font-size: 8pt; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; font-family: 'Courier New', courier, monospace; background-color: #f4f4f4; text-align: left; border-style: none; padding: 0px;">
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; font-family: 'Courier New', courier, monospace; background-color: #f4f4f4; text-align: left; border-style: none; padding: 0px;"><span id="lnum1" style="color: #606060">   1:</span> <span style="color: #0000ff">return</span> <span style="color: #0000ff">this</span>.each(<span style="color: #0000ff">function</span>()</pre>
<p><!--CRLF--></p>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; font-family: 'Courier New', courier, monospace; background-color: #f4f4f4; text-align: left; border-style: none; padding: 0px;"><span id="lnum2" style="color: #606060">   2:</span> {</pre>
<p><!--CRLF--></p>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; font-family: 'Courier New', courier, monospace; background-color: #f4f4f4; text-align: left; border-style: none; padding: 0px;"><span id="lnum3" style="color: #606060">   3:</span>     <span style="color: #0000ff">for</span>(<span style="color: #0000ff">var</span> i=0;i&lt;words.length;i++)</pre>
<p><!--CRLF--></p>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; font-family: 'Courier New', courier, monospace; background-color: #f4f4f4; text-align: left; border-style: none; padding: 0px;"><span id="lnum4" style="color: #606060">   4:</span>     {</pre>
<p><!--CRLF--></p>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; font-family: 'Courier New', courier, monospace; background-color: #f4f4f4; text-align: left; border-style: none; padding: 0px;"><span id="lnum5" style="color: #606060">   5:</span>         <span style="color: #0000ff">var</span> span = <span style="color: #006080">''</span> + words[i] + <span style="color: #006080">''</span>;</pre>
<p><!--CRLF--></p>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; font-family: 'Courier New', courier, monospace; background-color: #f4f4f4; text-align: left; border-style: none; padding: 0px;"><span id="lnum6" style="color: #606060">   6:</span>         <span style="color: #0000ff">this</span>.innerHTML = <span style="color: #0000ff">this</span>.innerHTML.replace(</pre>
<p><!--CRLF--></p>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; font-family: 'Courier New', courier, monospace; background-color: #f4f4f4; text-align: left; border-style: none; padding: 0px;"><span id="lnum7" style="color: #606060">   7:</span>             <span style="color: #0000ff">new</span> RegExp(words[i], <span style="color: #006080">'gi'</span>), span);</pre>
<p><!--CRLF--></p>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; font-family: 'Courier New', courier, monospace; background-color: #f4f4f4; text-align: left; border-style: none; padding: 0px;"><span id="lnum8" style="color: #606060">   8:</span>     }</pre>
<p><!--CRLF--></p>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; font-family: 'Courier New', courier, monospace; background-color: #f4f4f4; text-align: left; border-style: none; padding: 0px;"><span id="lnum9" style="color: #606060">   9:</span> });</pre>
<p><!--CRLF--></p>
</div>
</div>
<p>This is pretty simple. We are looping through each of our words. We are wrapping the words in a span tag that uses <a href="http://www.dev102.com/2008/10/27/spice-up-your-navigation-with-css-drop-down-menus/">CSS </a>to define a background and foreground color. Then we simply do a find and replace on the elements innerHTML. It is that easy. You can see a demo of this plug-in our <a href="http://www.dev102.com/freebies/">freebies page</a>. Stay tuned for more great posts from Dev102.com by grabbing the <a href="http://feeds.feedburner.com/Dev102feed">RSS feed</a>. You can also see more posts I have written on <a href="http://www.geekdaily.net">my blog</a> or grab my <a href="http://feeds.feedburner.com/GeekDaily">RSS feed</a>.</p>

<p><a href="http://feedads.g.doubleclick.net/~a/BMYbBchQtduIyU-GinMnVGO-m5s/0/da"><img src="http://feedads.g.doubleclick.net/~a/BMYbBchQtduIyU-GinMnVGO-m5s/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/BMYbBchQtduIyU-GinMnVGO-m5s/1/da"><img src="http://feedads.g.doubleclick.net/~a/BMYbBchQtduIyU-GinMnVGO-m5s/1/di" border="0" ismap="true"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/Dev102feed?a=zvmZDSJ7hhc:9BuoJe8t8S0:NT3aGUK8eJ0"><img src="http://feeds.feedburner.com/~ff/Dev102feed?d=NT3aGUK8eJ0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Dev102feed?a=zvmZDSJ7hhc:9BuoJe8t8S0:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/Dev102feed?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Dev102feed?a=zvmZDSJ7hhc:9BuoJe8t8S0:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/Dev102feed?i=zvmZDSJ7hhc:9BuoJe8t8S0:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Dev102feed?a=zvmZDSJ7hhc:9BuoJe8t8S0:dnMXMwOfBR0"><img src="http://feeds.feedburner.com/~ff/Dev102feed?d=dnMXMwOfBR0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Dev102feed?a=zvmZDSJ7hhc:9BuoJe8t8S0:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/Dev102feed?i=zvmZDSJ7hhc:9BuoJe8t8S0:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Dev102feed?a=zvmZDSJ7hhc:9BuoJe8t8S0:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/Dev102feed?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Dev102feed?a=zvmZDSJ7hhc:9BuoJe8t8S0:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/Dev102feed?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Dev102feed?a=zvmZDSJ7hhc:9BuoJe8t8S0:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/Dev102feed?i=zvmZDSJ7hhc:9BuoJe8t8S0:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Dev102feed?a=zvmZDSJ7hhc:9BuoJe8t8S0:TzevzKxY174"><img src="http://feeds.feedburner.com/~ff/Dev102feed?d=TzevzKxY174" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/Dev102feed/~4/zvmZDSJ7hhc" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.dev102.com/2009/04/28/how-to-create-a-jquery-plugin/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.dev102.com/2009/04/28/how-to-create-a-jquery-plugin/</feedburner:origLink></item>
		<item>
		<title>Another List of 5 Great and Useful Visual Studio Shortcuts</title>
		<link>http://feedproxy.google.com/~r/Dev102feed/~3/hwmqHXQiDH4/</link>
		<comments>http://www.dev102.com/2009/04/22/another-list-of-5-great-and-useful-visual-studio-shortcuts/#comments</comments>
		<pubDate>Wed, 22 Apr 2009 04:39:06 +0000</pubDate>
		<dc:creator>Amit</dc:creator>
		
		<category><![CDATA[Visual Studio]]></category>

		<category><![CDATA[ALT]]></category>

		<category><![CDATA[CTRL]]></category>

		<category><![CDATA[SHIFT]]></category>

		<category><![CDATA[Shortcuts]]></category>

		<category><![CDATA[Visual Studio Shortcuts]]></category>

		<guid isPermaLink="false">http://www.dev102.com/?p=1204</guid>
		<description><![CDATA[<p>Hey all, </p>

<p>&#160;</p>

<p>a while back we had 2 great posts and one page about visual studio shortcuts. The first one had a list of <a href="http://www.dev102.com/2008/04/17/10-visual-studio-shortcuts-you-must-know/">10 Visual Studio Shortcuts</a> and the second one had <a href="http://www.dev102.com/2008/05/06/11-more-visual-studio-shortcuts-you-should-know/">11 Visual Studio Shortcuts</a>. We also have a Visual Studio CheatSheet with all the <a href="http://www.dev102.com/vs-cheatsheet/">Keyboard shortcuts Visual Studio</a> has.</p>

<p>&#160;</p>

<p>Here is another list of 5 Shortcuts I have picked up along the way.</p>

<p>&#160;</p>]]></description>
			<content:encoded><![CDATA[<p>Hey all,</p>
<p> </p>
<p>a while back we had 2 great posts and one page about visual studio shortcuts. The first one had a list of <a href="http://www.dev102.com/2008/04/17/10-visual-studio-shortcuts-you-must-know/">10 Visual Studio Shortcuts</a> and the second one had <a href="http://www.dev102.com/2008/05/06/11-more-visual-studio-shortcuts-you-should-know/">11 Visual Studio Shortcuts</a>. We also have a Visual Studio CheatSheet with all the <a href="http://www.dev102.com/vs-cheatsheet/">Keyboard shortcuts Visual Studio</a> has.</p>
<p> </p>
<p>Here is another list of 5 Shortcuts I have picked up along the way.</p>
<p> </p>
<ol>
<li><strong><span style="text-decoration: underline;">CTRL + SHIFT + 8/7:</span></strong> In case you haven&#8217;t knew there is a “Go to Definitions Stack” and every time you click F12 it stores where you went inside that stack. Hitting CTRL +  SHIFT + 8 goes “Back” in the stack and CTRL +  SHIFT + 7 goes forward.</li>
<li><strong><span style="text-decoration: underline;">F8:</span></strong> I hope all of you are using the CTRL + “-“ to go back to the location you were (after hitting F12 for example). F8 is the opposite to that action it will take you forward. It is the same as CTRL + SHIFT + “-“.</li>
<li><strong><span style="text-decoration: underline;">SHIFT + F12:</span></strong> Having the marker on top of anything and clicking SHIFT + F12 will search the entire solution for that object and open up the find symbol window:<br />
<a href="http://dev102.com/Dev102/wp-content/uploads/2009/04/shiftf12.png"><img style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" title="SHIFT   F12" src="http://dev102.com/Dev102/wp-content/uploads/2009/04/shiftf12-thumb.png" border="0" alt="SHIFT   F12" width="534" height="315" /></a></li>
<li><strong><span style="text-decoration: underline;">CTRL + ALT + Down Arrow:</span></strong> This is my favorite. You all know the  CTRL + TAB feature of Visual studio:<br />
<a href="http://dev102.com/Dev102/wp-content/uploads/2009/04/ctrltab.png"><img style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" title="CTRL   TAB" src="http://dev102.com/Dev102/wp-content/uploads/2009/04/ctrltab-thumb.png" border="0" alt="CTRL   TAB" width="528" height="286" /></a><br />
We have all used it to switch between open files, the problem is that there is no order in the files, although sometime it looks alphabetical it isn’t Clicking CTRL + ALT + Down Arrow is like clicking the little arrow on the upper right corner of the text editor so the result is this:<br />
 <a href="http://dev102.com/Dev102/wp-content/uploads/2009/04/ctrlaltdownarrow.png"><img style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" title="CTRL   ALT   Down Arrow" src="http://dev102.com/Dev102/wp-content/uploads/2009/04/ctrlaltdownarrow-thumb.png" border="0" alt="CTRL   ALT   Down Arrow" width="538" height="291" /></a><br />
And the best this is that it is ordered the same as the tabs on top of the text editor.</li>
<li><strong><span style="text-decoration: underline;">CTRL + K + X:</span></strong> This is also a useful one, Hitting CTRL + K + X will open up the insert snippet window and allow you to select the snippets you want to use:<br />
<a href="http://dev102.com/Dev102/wp-content/uploads/2009/04/ctrlkx.png"><img style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" title="CTRL   K   X" src="http://dev102.com/Dev102/wp-content/uploads/2009/04/ctrlkx-thumb.png" border="0" alt="CTRL   K   X" width="537" height="237" /></a> </li>
</ol>
<p>That’s all for now, on my next post I will show some CodeRush Express Shortcuts.</p>
<p> </p>
<p>Amit</p>

<p><a href="http://feedads.g.doubleclick.net/~a/_36zMRnxB8pdHItUKGHCxp1gSrU/0/da"><img src="http://feedads.g.doubleclick.net/~a/_36zMRnxB8pdHItUKGHCxp1gSrU/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/_36zMRnxB8pdHItUKGHCxp1gSrU/1/da"><img src="http://feedads.g.doubleclick.net/~a/_36zMRnxB8pdHItUKGHCxp1gSrU/1/di" border="0" ismap="true"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/Dev102feed?a=hwmqHXQiDH4:Gnf9CTkQmKY:NT3aGUK8eJ0"><img src="http://feeds.feedburner.com/~ff/Dev102feed?d=NT3aGUK8eJ0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Dev102feed?a=hwmqHXQiDH4:Gnf9CTkQmKY:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/Dev102feed?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Dev102feed?a=hwmqHXQiDH4:Gnf9CTkQmKY:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/Dev102feed?i=hwmqHXQiDH4:Gnf9CTkQmKY:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Dev102feed?a=hwmqHXQiDH4:Gnf9CTkQmKY:dnMXMwOfBR0"><img src="http://feeds.feedburner.com/~ff/Dev102feed?d=dnMXMwOfBR0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Dev102feed?a=hwmqHXQiDH4:Gnf9CTkQmKY:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/Dev102feed?i=hwmqHXQiDH4:Gnf9CTkQmKY:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Dev102feed?a=hwmqHXQiDH4:Gnf9CTkQmKY:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/Dev102feed?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Dev102feed?a=hwmqHXQiDH4:Gnf9CTkQmKY:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/Dev102feed?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Dev102feed?a=hwmqHXQiDH4:Gnf9CTkQmKY:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/Dev102feed?i=hwmqHXQiDH4:Gnf9CTkQmKY:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Dev102feed?a=hwmqHXQiDH4:Gnf9CTkQmKY:TzevzKxY174"><img src="http://feeds.feedburner.com/~ff/Dev102feed?d=TzevzKxY174" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/Dev102feed/~4/hwmqHXQiDH4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.dev102.com/2009/04/22/another-list-of-5-great-and-useful-visual-studio-shortcuts/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.dev102.com/2009/04/22/another-list-of-5-great-and-useful-visual-studio-shortcuts/</feedburner:origLink></item>
		<item>
		<title>Dev102.com March 2009 Roundup</title>
		<link>http://feedproxy.google.com/~r/Dev102feed/~3/yxkhiJU1_WI/</link>
		<comments>http://www.dev102.com/2009/04/17/dev102com-march-2009-roundup/#comments</comments>
		<pubDate>Fri, 17 Apr 2009 09:19:59 +0000</pubDate>
		<dc:creator>Amit</dc:creator>
		
		<category><![CDATA[Misc.]]></category>

		<category><![CDATA[Technology & Internet]]></category>

		<category><![CDATA[create]]></category>

		<category><![CDATA[NUnit]]></category>

		<category><![CDATA[Shortcuts]]></category>

		<category><![CDATA[stats]]></category>

		<category><![CDATA[Studio]]></category>

		<category><![CDATA[Traffic]]></category>

		<category><![CDATA[United]]></category>

		<category><![CDATA[visits]]></category>

		<category><![CDATA[Visual]]></category>

		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://www.dev102.com/?p=1157</guid>
		<description><![CDATA[<p>Hey all.</p>

<p>&#160;</p>

<p>Nothing new for this month so apart from reminding you that if you want to make a quick 30$ all you have to do is to drop us an good unique article (you can get more information on our <a href="http://www.dev102.com/make-money/">Make Money Writing Articles</a> Page). I will move on to the stats.</p>

<p>&#160;</p>

<p>Here are March’s Stats:</p>]]></description>
			<content:encoded><![CDATA[<p>Hey all.</p>
<p> </p>
<p>Nothing new for this month so apart from reminding you that if you want to make a quick 30$ all you have to do is to drop us a good unique article (you can get more information on our <a href="http://www.dev102.com/make-money/">Make Money Writing Articles</a> Page). I will move on to the stats.</p>
<p> </p>
<p>Here are March’s Stats:</p>
<p> </p>
<h3><span style="text-decoration: underline;">Traffic Stats</span></h3>
<ul>
<li>Visits: 37,663 (31,456)</li>
<li>Page Views: 49,908 (43,187)</li>
<li>Rss Readers: 1025 (994)</li>
<li>Twiter Followers: 55 (35)</li>
<li>Alexa Rank: 200,253 (225,471)
<ol>
<li>12,627 Israel</li>
<li>28,631 Sweden</li>
<li>47,156 Bulgaria</li>
<li>61,470 India</li>
<li>90,953 Turkey</li>
<li>120,277 United Kingdom</li>
<li>120,797 Italy</li>
<li>152,304 United States</li>
<li>156,169 Canada</li>
<li>157,090 China</li>
<li>168,691 Poland</li>
<li>189,156 Russia</li>
<li>282,951 Spain</li>
<li>368,151 Germany </li>
</ol>
</li>
</ul>
<h3><span style="text-decoration: underline;">Top 5 Traffic Sources</span></h3>
<ol>
<li><a href="http://www.google.com">Google</a> : 28,402 (23,550) Visits.</li>
<li><a href="http://www.dev102.com">Direct</a> : 3,184 (2,705) Visits.</li>
<li><a href="http://www.dotnetkicks.com/search?q=dev102&amp;user=False&amp;page=1">DotNetKicks</a> : 1,612 (1,052) Visits.</li>
<li><a href="http://www.stumbleupon.com/search?q=dev102">StumbleUpon</a> : 656 (550) Visits.</li>
<li><a href="http://www.yahoo.com/">Yahoo</a>: 523 (558) Visits.</li>
</ol>
<h3><span style="text-decoration: underline;">Top 10 KeyWords</span> </h3>
<ol>
<li><a href="http://www.dev102.com/2008/04/25/linq-to-xml-in-3-easy-steps/">linq to xml</a> : 402 (321) Visits.</li>
<li><a href="http://www.dev102.com/2008/05/06/11-more-visual-studio-shortcuts-you-should-know/">visual studio shortcuts</a> : 289 (340) Visits.</li>
<li><a href="http://www.dev102.com/2008/03/22/3-ways-to-run-nunit-from-visual-studio/">nunit visual studio 2008</a>  : 217 (135) Visits.</li>
<li><a href="http://www.dev102.com/2008/06/20/how-to-create-a-wpf-custom-context-menu/">wpf context menu</a> : 175 (148) Visits.</li>
<li><a href="http://www.dev102.com/2008/09/19/a-better-wpf-custom-context-menu/">wpf contextmenu</a> :142 (119) Visits.</li>
<li><a href="http://www.dev102.com/2008/05/16/why-pluggable-applications-fails-in-nunit/">nunit visual studio</a> : 125 (125) Visits.</li>
<li><a href="http://www.dev102.com/2008/11/14/play-quake-online-with-quakelight-silverlight-quake/">quake online</a> : 119 (175) Visits.</li>
<li><a href="http://www.dev102.com/2008/07/02/why-sortedlistkeyval-is-useless/">sortedlist</a> : 98 (77) Visits.</li>
<li><a href="http://www.dev102.com/2008/04/17/10-visual-studio-shortcuts-you-must-know/">visual studio 2008 shortcuts</a> : 96 (81) Visits.</li>
<li><a href="http://www.dev102.com/2008/09/25/wpf-binding-converter-best-practices-continued/">wpf binding converter</a> : 87 (79) Visits.</li>
</ol>
<h3><span style="text-decoration: underline;">Top 10 Articles</span></h3>
<ol>
<li><a href="              http://www.dev102.com/2008/04/17/10-visual-studio-shortcuts-you-must-know/">10 Visual Studio Shortcuts You Must Know </a>: 2,099 (2,048) Visits.</li>
<li><a href="              http://www.dev102.com/2008/03/22/3-ways-to-run-nunit-from-visual-studio/">3 Ways to Run NUnit From Visual Studio </a>:  1,451 (1,263) Visits.</li>
<li><a href="              http://www.dev102.com/2009/03/23/creating-an-ajax-login-form-with-jquery/">Creating an Ajax Login Form With jQuery </a>: 1,366 (New) Visits.</li>
<li><a href="              http://www.dev102.com/2008/06/20/how-to-create-a-wpf-custom-context-menu/">How To Create a WPF Custom Context Menu </a>: 1,333 (1133) Visits.</li>
<li><a href="http://www.dev102.com/2008/04/25/linq-to-xml-in-3-easy-steps/">LINQ to XML in 3 Easy Steps</a> :  1289 (1,040) Visits.</li>
<li><a href="              http://www.dev102.com/2008/05/06/11-more-visual-studio-shortcuts-you-should-know/">11 More Visual Studio Shortcuts You Should Know </a>: 1,093 (976) Visits.</li>
<li><a href="              http://www.dev102.com/2008/10/09/measure-string-size-in-pixels-c/">Measure String Size In Pixels (C#) </a>: 1061 (831) Visits.</li>
<li><a href="              http://www.dev102.com/2008/06/03/when-a-company-logo-doesnt-come-out-so-good/">When a Company Logo Doesn’t Come Out So Good </a>: 970 (758) Visits.</li>
<li><a href="              http://www.dev102.com/2008/05/21/create-interactive-form-validation-using-ajax/">How to Create Interactive Form Validation Using Ajax </a>: 913 (743) Visits.</li>
<li><a href="              http://www.dev102.com/2008/03/22/how-to-reset-identity-increment-value-in-ms-sql/">How to reset Identity Increment value in MS SQL</a> : 911 (834) Visits.</li>
</ol>
<p>That&#8217;s it.</p>
<p>If you are interested in Knowing anything else, Just ask</p>
<p>Amit</p>

<p><a href="http://feedads.g.doubleclick.net/~a/tnquLGK8DKyAarUJu-Qg_434URI/0/da"><img src="http://feedads.g.doubleclick.net/~a/tnquLGK8DKyAarUJu-Qg_434URI/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/tnquLGK8DKyAarUJu-Qg_434URI/1/da"><img src="http://feedads.g.doubleclick.net/~a/tnquLGK8DKyAarUJu-Qg_434URI/1/di" border="0" ismap="true"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/Dev102feed?a=yxkhiJU1_WI:4kPy6dvVst0:NT3aGUK8eJ0"><img src="http://feeds.feedburner.com/~ff/Dev102feed?d=NT3aGUK8eJ0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Dev102feed?a=yxkhiJU1_WI:4kPy6dvVst0:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/Dev102feed?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Dev102feed?a=yxkhiJU1_WI:4kPy6dvVst0:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/Dev102feed?i=yxkhiJU1_WI:4kPy6dvVst0:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Dev102feed?a=yxkhiJU1_WI:4kPy6dvVst0:dnMXMwOfBR0"><img src="http://feeds.feedburner.com/~ff/Dev102feed?d=dnMXMwOfBR0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Dev102feed?a=yxkhiJU1_WI:4kPy6dvVst0:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/Dev102feed?i=yxkhiJU1_WI:4kPy6dvVst0:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Dev102feed?a=yxkhiJU1_WI:4kPy6dvVst0:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/Dev102feed?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Dev102feed?a=yxkhiJU1_WI:4kPy6dvVst0:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/Dev102feed?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Dev102feed?a=yxkhiJU1_WI:4kPy6dvVst0:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/Dev102feed?i=yxkhiJU1_WI:4kPy6dvVst0:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Dev102feed?a=yxkhiJU1_WI:4kPy6dvVst0:TzevzKxY174"><img src="http://feeds.feedburner.com/~ff/Dev102feed?d=TzevzKxY174" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/Dev102feed/~4/yxkhiJU1_WI" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.dev102.com/2009/04/17/dev102com-march-2009-roundup/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.dev102.com/2009/04/17/dev102com-march-2009-roundup/</feedburner:origLink></item>
		<item>
		<title>Creating A Tabbed Menu Control For ASP.NET MVC</title>
		<link>http://feedproxy.google.com/~r/Dev102feed/~3/fIhPHEoeubI/</link>
		<comments>http://www.dev102.com/2009/04/14/creating-a-tabbed-menu-control-for-aspnet-mvc/#comments</comments>
		<pubDate>Tue, 14 Apr 2009 07:02:16 +0000</pubDate>
		<dc:creator>Justin</dc:creator>
		
		<category><![CDATA[ASP.Net]]></category>

		<category><![CDATA[C#]]></category>

		<category><![CDATA[Web Development]]></category>

		<category><![CDATA[action]]></category>

		<category><![CDATA[ASP.NET MVC]]></category>

		<category><![CDATA[Class]]></category>

		<category><![CDATA[Controller]]></category>

		<category><![CDATA[create]]></category>

		<category><![CDATA[menu]]></category>

		<category><![CDATA[MenuTab]]></category>

		<category><![CDATA[method]]></category>

		<category><![CDATA[string]]></category>

		<category><![CDATA[Tab]]></category>

		<category><![CDATA[text]]></category>

		<guid isPermaLink="false">http://www.dev102.com/?p=1167</guid>
		<description><![CDATA[<p>Tab menus are a fairly common thing that I use in a lot of my applications. I like tabs because they help break up large chunks of, usually, related information.</p>

<p>&#160;</p>

<p>At work we use RadControls for Telerik and they have a pretty nice tab menu control that is easy to use and looks good too. The only problem with these controls is that they only work in <a href="http://www.dev102.com/2008/08/19/jquery-and-the-aspnet-mvc-framework/">WebForms</a> like even the default ASP.NET controls. So when I started playing with <a href="http://www.dev102.com/2009/03/12/working-with-aspnet-mvc-part-5-views/">MVC</a> I quickly realized I would need to spend some time building some of these controls myself.</p>
]]></description>
			<content:encoded><![CDATA[<p>Tab menus are a fairly common thing that I use in a lot of my applications. I like tabs because they help break up large chunks of, usually, related information.</p>
<p> </p>
<p>At work we use RadControls for Telerik and they have a pretty nice tab menu control that is easy to use and looks good too. The only problem with these controls is that they only work in <a href="http://www.dev102.com/2008/08/19/jquery-and-the-aspnet-mvc-framework/">WebForms</a> like even the default ASP.NET controls. So when I started playing with <a href="http://www.dev102.com/2009/03/12/working-with-aspnet-mvc-part-5-views/">MVC</a> I quickly realized I would need to spend some time building some of these controls myself.</p>
<p>Based on that realization, the idea for this post was formed and I set to work creating a fair simple control. This control is not meant to be compared with the control from Telerik. Mine is very basic and has very few features.</p>
<p> </p>
<p>Again, I will be using the default MVC template project as my starting point. I did make a few minor changes to the <a href="http://www.dev102.com/2008/03/17/find-controls-in-an-aspnet-page-with-a-masterpage/">MasterPage</a> but I will include the finished Visual Studio project with this post so you can take a look for yourself.</p>
<p>The first step is to create the HtmlHelper extension method that will generate our control. This method will do most of the work we need.</p>
<div>
<div style="font-size: 8pt; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; border-style: none; padding: 0px;">
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; border-style: none; padding: 0px;"><span style="color: #606060">   1:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">static</span> <span style="color: #0000ff">class</span> MyHtmlHelper</pre>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; border-style: none; padding: 0px;"><span style="color: #606060">   2:</span> {</pre>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; border-style: none; padding: 0px;"><span style="color: #606060">   3:</span>     <span style="color: #0000ff">public</span> <span style="color: #0000ff">static</span> <span style="color: #0000ff">string</span> TabbedMenu(<span style="color: #0000ff">this</span> HtmlHelper helper, IEnumerable&lt;MenuTab&gt; tabs)</pre>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; border-style: none; padding: 0px;"><span style="color: #606060">   4:</span>     {</pre>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; border-style: none; padding: 0px;"><span style="color: #606060">   5:</span>         var route = helper.ViewContext.RequestContext.RouteData;</pre>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; border-style: none; padding: 0px;"><span style="color: #606060">   6:</span>         var controller = route.GetRequiredString(<span style="color: #006080">"controller"</span>);</pre>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; border-style: none; padding: 0px;"><span style="color: #606060">   7:</span>         var action = route.GetRequiredString(<span style="color: #006080">"action"</span>);</pre>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; border-style: none; padding: 0px;"><span style="color: #606060">   8:</span>         var menu = <span style="color: #006080">"\n\n&lt;ul id=\"menu\"&gt;"</span>;</pre>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; border-style: none; padding: 0px;"><span style="color: #606060">   9:</span> </pre>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; border-style: none; padding: 0px;"><span style="color: #606060">  10:</span>         <span style="color: #0000ff">foreach</span> (var tab <span style="color: #0000ff">in</span> tabs)</pre>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; border-style: none; padding: 0px;"><span style="color: #606060">  11:</span>         {</pre>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; border-style: none; padding: 0px;"><span style="color: #606060">  12:</span>             <span style="color: #0000ff">if</span> (controller == tab.Controller &amp;&amp; action == tab.Action)</pre>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; border-style: none; padding: 0px;"><span style="color: #606060">  13:</span>                 menu += <span style="color: #006080">"\n\t&lt;li&gt;"</span> + helper.ActionLink(tab.Text, tab.Action,</pre>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; border-style: none; padding: 0px;"><span style="color: #606060">  14:</span>                 tab.Controller, <span style="color: #0000ff">new</span> { @<span style="color: #0000ff">class</span> = <span style="color: #006080">"selected"</span> }) + <span style="color: #006080">"&lt;/li&gt;"</span>;</pre>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; border-style: none; padding: 0px;"><span style="color: #606060">  15:</span>             <span style="color: #0000ff">else</span></pre>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; border-style: none; padding: 0px;"><span style="color: #606060">  16:</span>                 menu += <span style="color: #006080">"\n\t&lt;li&gt;"</span> + helper.ActionLink(tab.Text,</pre>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; border-style: none; padding: 0px;"><span style="color: #606060">  17:</span>                 tab.Action, tab.Controller) + <span style="color: #006080">"&lt;/li&gt;"</span>;</pre>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; border-style: none; padding: 0px;"><span style="color: #606060">  18:</span>         }</pre>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; border-style: none; padding: 0px;"><span style="color: #606060">  19:</span>         menu += <span style="color: #006080">"\n&lt;/ul&gt;\n\n"</span>;</pre>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; border-style: none; padding: 0px;"><span style="color: #606060">  20:</span>         <span style="color: #0000ff">return</span> menu;</pre>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; border-style: none; padding: 0px;"><span style="color: #606060">  21:</span>     }</pre>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; border-style: none; padding: 0px;"><span style="color: #606060">  22:</span> }</pre>
</div>
</div>
<p>So what this method does is it accepts an IEnumberable collection of MenuTab. We&#8217;ll look at the MenuTab class in just a bit. Next the method gets the names of both the current controller and action. These will be used to determine which tab is currently selected. Then the method uses a foreach to loop through the collection and build out the HTML unordered list. Notice that during the loop we are checking to see if the MenuTab instance&#8217;s controller and action match the current controller and action. If they make we apply the selected CSS class to the anchor. Pretty simple stuff.</p>
<p>Note: All this method does is produce the required HTML markup. CSS is used to achieve the tab look.</p>
<p>Now let&#8217;s look at the MenuTab class.</p>
<div>
<div style="font-size: 8pt; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; border-style: none; padding: 0px;">
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; border-style: none; padding: 0px;"><span style="color: #606060">   1:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">class</span> MenuTab</pre>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; border-style: none; padding: 0px;"><span style="color: #606060">   2:</span> {</pre>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; border-style: none; padding: 0px;"><span style="color: #606060">   3:</span>     <span style="color: #0000ff">private</span> MenuTab(<span style="color: #0000ff">string</span> text, <span style="color: #0000ff">string</span> action, <span style="color: #0000ff">string</span> controller)</pre>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; border-style: none; padding: 0px;"><span style="color: #606060">   4:</span>     {</pre>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; border-style: none; padding: 0px;"><span style="color: #606060">   5:</span>         Text = text;</pre>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; border-style: none; padding: 0px;"><span style="color: #606060">   6:</span>         Action = action;</pre>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; border-style: none; padding: 0px;"><span style="color: #606060">   7:</span>         Controller = controller;</pre>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; border-style: none; padding: 0px;"><span style="color: #606060">   8:</span>     }</pre>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; border-style: none; padding: 0px;"><span style="color: #606060">   9:</span> </pre>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; border-style: none; padding: 0px;"><span style="color: #606060">  10:</span>     <span style="color: #0000ff">public</span> <span style="color: #0000ff">static</span> MenuTab Create(<span style="color: #0000ff">string</span> text, <span style="color: #0000ff">string</span> action, <span style="color: #0000ff">string</span> controller)</pre>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; border-style: none; padding: 0px;"><span style="color: #606060">  11:</span>     {</pre>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; border-style: none; padding: 0px;"><span style="color: #606060">  12:</span>         <span style="color: #0000ff">return</span> <span style="color: #0000ff">new</span> MenuTab(text, action, controller);</pre>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; border-style: none; padding: 0px;"><span style="color: #606060">  13:</span>     }</pre>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; border-style: none; padding: 0px;"><span style="color: #606060">  14:</span> </pre>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; border-style: none; padding: 0px;"><span style="color: #606060">  15:</span>     <span style="color: #0000ff">public</span> <span style="color: #0000ff">string</span> Text { get; <span style="color: #0000ff">private</span> set; }</pre>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; border-style: none; padding: 0px;"><span style="color: #606060">  16:</span>     <span style="color: #0000ff">public</span> <span style="color: #0000ff">string</span> Action { get; <span style="color: #0000ff">private</span> set; }</pre>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; border-style: none; padding: 0px;"><span style="color: #606060">  17:</span>     <span style="color: #0000ff">public</span> <span style="color: #0000ff">string</span> Controller { get; <span style="color: #0000ff">private</span> set; }</pre>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; border-style: none; padding: 0px;"><span style="color: #606060">  18:</span> }</pre>
</div>
</div>
<p>This class is very simple. It just stores the information we will need to build the links in our menu.</p>
<p>That covers off the extension method and any related code. As you can see I wasn&#8217;t kidding when I said it doesn&#8217;t have many features. This only meant to should how to get started.</p>
<p>In order to make the menu look like tabs a made a few minor tweaks to the existing Site.css file and added the below class definition to indicate which tab is selected.</p>
<div>
<div style="font-size: 8pt; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; border-style: none; padding: 0px;">
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; border-style: none; padding: 0px;"><span style="color: #606060">   1:</span> <span style="color: #0000ff">ul</span>#<span style="color: #0000ff">menu</span> <span style="color: #0000ff">li</span> a<span style="color: #cc6633">.selected</span> {</pre>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; border-style: none; padding: 0px;"><span style="color: #606060">   2:</span> <span style="color: #0000ff">background-color</span>: <span style="color: #006080">#fff;</span></pre>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; border-style: none; padding: 0px;"><span style="color: #606060">   3:</span> <span style="color: #0000ff">color</span>: <span style="color: #006080">#000;</span></pre>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; border-style: none; padding: 0px;"><span style="color: #606060">   4:</span> }</pre>
</div>
</div>
<p>Now all that is left is to insert our menu into the Site.Master file of our application.</p>
<div>
<div style="font-size: 8pt; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; border-style: none; padding: 0px;">
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; border-style: none; padding: 0px;"><span style="color: #606060">   1:</span> &lt;%= Html.TabbedMenu(<span style="color: #0000ff">new</span> List&lt;MenuTab&gt; {</pre>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; border-style: none; padding: 0px;"><span style="color: #606060">   2:</span> MenuTab.Create(<span style="color: #006080">"Home"</span>, <span style="color: #006080">"Index"</span>, <span style="color: #006080">"Home"</span>),</pre>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; border-style: none; padding: 0px;"><span style="color: #606060">   3:</span> MenuTab.Create(<span style="color: #006080">"About"</span>, <span style="color: #006080">"About"</span>, <span style="color: #006080">"Home"</span>),</pre>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; border-style: none; padding: 0px;"><span style="color: #606060">   4:</span> MenuTab.Create(<span style="color: #006080">"Services"</span>, <span style="color: #006080">"Services"</span>, <span style="color: #006080">"Home"</span>),</pre>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; border-style: none; padding: 0px;"><span style="color: #606060">   5:</span> MenuTab.Create(<span style="color: #006080">"Pricing"</span>, <span style="color: #006080">"Pricing"</span>, <span style="color: #006080">"Home"</span>),</pre>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; border-style: none; padding: 0px;"><span style="color: #606060">   6:</span> MenuTab.Create(<span style="color: #006080">"Contact"</span>, <span style="color: #006080">"Contact"</span>, <span style="color: #006080">"Home"</span>)</pre>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; border-style: none; padding: 0px;"><span style="color: #606060">   7:</span> }) %&gt;</pre>
</div>
</div>
<p>I replaced the menu code that was already in the demo with the above code that defines the links in our menu.</p>
<p>So as you can see it was pretty simple to build an <a href="http://www.dev102.com/2009/01/05/filtering-list-items-the-yield-return-solution/">extension</a> method to add our own helper method for building a tab like menu. By encapsulating this into a helper method we can now easily reuse it in any application.</p>
<p>You can download a sample project from our <a href="http://www.dev102.com/freebies/" target="_self">Freebies Page</a></p>
<p>Stay tuned for more great posts from Dev102.com by grabbing the <a href="http://feeds.feedburner.com/Dev102feed">RSS feed</a>. You can also see more posts I have written on <a href="http://www.geekdaily.net">my blog</a> or grab my <a href="http://feeds.feedburner.com/GeekDaily">RSS feed</a>.</p>

<p><a href="http://feedads.g.doubleclick.net/~a/St4S-ZR2_NkaW5rqlGCss4-LSyI/0/da"><img src="http://feedads.g.doubleclick.net/~a/St4S-ZR2_NkaW5rqlGCss4-LSyI/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/St4S-ZR2_NkaW5rqlGCss4-LSyI/1/da"><img src="http://feedads.g.doubleclick.net/~a/St4S-ZR2_NkaW5rqlGCss4-LSyI/1/di" border="0" ismap="true"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/Dev102feed?a=fIhPHEoeubI:JnztMFoYNVU:NT3aGUK8eJ0"><img src="http://feeds.feedburner.com/~ff/Dev102feed?d=NT3aGUK8eJ0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Dev102feed?a=fIhPHEoeubI:JnztMFoYNVU:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/Dev102feed?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Dev102feed?a=fIhPHEoeubI:JnztMFoYNVU:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/Dev102feed?i=fIhPHEoeubI:JnztMFoYNVU:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Dev102feed?a=fIhPHEoeubI:JnztMFoYNVU:dnMXMwOfBR0"><img src="http://feeds.feedburner.com/~ff/Dev102feed?d=dnMXMwOfBR0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Dev102feed?a=fIhPHEoeubI:JnztMFoYNVU:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/Dev102feed?i=fIhPHEoeubI:JnztMFoYNVU:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Dev102feed?a=fIhPHEoeubI:JnztMFoYNVU:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/Dev102feed?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Dev102feed?a=fIhPHEoeubI:JnztMFoYNVU:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/Dev102feed?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Dev102feed?a=fIhPHEoeubI:JnztMFoYNVU:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/Dev102feed?i=fIhPHEoeubI:JnztMFoYNVU:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Dev102feed?a=fIhPHEoeubI:JnztMFoYNVU:TzevzKxY174"><img src="http://feeds.feedburner.com/~ff/Dev102feed?d=TzevzKxY174" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/Dev102feed/~4/fIhPHEoeubI" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.dev102.com/2009/04/14/creating-a-tabbed-menu-control-for-aspnet-mvc/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.dev102.com/2009/04/14/creating-a-tabbed-menu-control-for-aspnet-mvc/</feedburner:origLink></item>
		<item>
		<title>DebuggerDisplay and DebuggerBrowsable – Two Debugger Attributes you should know</title>
		<link>http://feedproxy.google.com/~r/Dev102feed/~3/59zB-1vwy4k/</link>
		<comments>http://www.dev102.com/2009/04/09/debuggerdisplay-and-debuggerbrowsable-two-debugger-attributes-you-should-know/#comments</comments>
		<pubDate>Thu, 09 Apr 2009 07:30:05 +0000</pubDate>
		<dc:creator>Amit</dc:creator>
		
		<category><![CDATA[.Net]]></category>

		<category><![CDATA[C#]]></category>

		<category><![CDATA[Visual Studio]]></category>

		<category><![CDATA[Attribute]]></category>

		<category><![CDATA[Collapsed]]></category>

		<category><![CDATA[DebuggerBrowsable]]></category>

		<category><![CDATA[DebuggerBrowsableState]]></category>

		<category><![CDATA[DebuggerDisplay]]></category>

		<category><![CDATA[Never]]></category>

		<category><![CDATA[RootHidden]]></category>

		<guid isPermaLink="false">http://www.dev102.com/?p=1182</guid>
		<description><![CDATA[<p>Hi</p>

<p>&#160;</p>

<p>I wanted to show the usage of these two very useful debugger attributes. If you don't know them keep on reading, they are very useful.</p>

<p>&#160;</p>

<h3><u>DebuggerDisplay</u></h3>

<p>This attribute allows you to customize the way an object is displayed. lets look at the following example:</p>]]></description>
			<content:encoded><![CDATA[<p>Hi</p>
<p>&#160;</p>
<p>I wanted to show the usage of these two very useful debugger <a href="http://www.dev102.com/2008/06/13/why-should-you-use-the-xkey-attribute-in-wpf-datatemplates/">attributes</a>. If you don&#8217;t know them keep on reading, they are very useful.</p>
<p>&#160;</p>
<h3><u>DebuggerDisplay</u></h3>
<p>This attribute allows you to customize the way an object is displayed. lets look at the following example:</p>
<div>
<div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   1:</span> <span style="color: #0000ff">class</span> Program</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   2:</span> {</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   3:</span>     <span style="color: #0000ff">static</span> <span style="color: #0000ff">void</span> Main(<span style="color: #0000ff">string</span>[] args)</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   4:</span>     {</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   5:</span>         Client c = <span style="color: #0000ff">new</span> Client() </pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   6:</span>         { </pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   7:</span>             Name = <span style="color: #006080">&quot;John&quot;</span>, </pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   8:</span>             HomeNumber = <span style="color: #006080">&quot;555-0094&quot;</span>, </pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   9:</span>             AccountBalance = -5000 </pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  10:</span>         };</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  11:</span>     }</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  12:</span> }</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  13:</span>&#160; </pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  14:</span> <span style="color: #0000ff">class</span> Client</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  15:</span> {</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  16:</span>     <span style="color: #0000ff">public</span> <span style="color: #0000ff">string</span> Name { get; set; }</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  17:</span>     <span style="color: #0000ff">public</span> <span style="color: #0000ff">string</span> HomeNumber { get; set; }</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  18:</span>     <span style="color: #0000ff">public</span> <span style="color: #0000ff">double</span> AccountBalance { get; set; }</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  19:</span> }</pre>
</p></div>
</div>
<p>When we hover above the object c we get the following:</p>
<p align="center"><a href="http://dev102.com/Dev102/wp-content/uploads/2009/04/nodebuggerattribute.jpg"><img title="No Debugger Attribute" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="172" alt="No Debugger Attribute" src="http://dev102.com/Dev102/wp-content/uploads/2009/04/nodebuggerattribute-thumb.jpg" width="338" border="0" /></a></p>
<p>We can make this much more “appealing” by using the DebuggerDisplay attribute. By using the DebuggerDisplay you can create a string that will replace what <a href="http://www.dev102.com/2008/03/22/3-ways-to-run-nunit-from-visual-studio/">Visual Studio</a> shows by default. For example you can add the following attribute:</p>
<div>
<div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   1:</span> [DebuggerDisplay(<span style="color: #006080">&quot; This is a client Named {Name}, His Home Phone Number&quot;</span> +</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   2:</span>         <span style="color: #006080">&quot;is {HomeNumber} and his Account Balance is {AccountBalance}&quot;</span>)]</pre>
</p></div>
</div>
<p>Now once we hover above the object c we get the following:</p>
<p align="center"><a href="http://dev102.com/Dev102/wp-content/uploads/2009/04/debuggerdisplayattribute.png"><img title="DebuggerDisplay Attribute" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="129" alt="DebuggerDisplay Attribute" src="http://dev102.com/Dev102/wp-content/uploads/2009/04/debuggerdisplayattribute-thumb.png" width="580" border="0" /></a></p>
<p>Pretty neat no?</p>
<p>You can customize the view in almost any way you want and you can even call method that belong to the class inside the marked {}.</p>
<p>&#160;</p>
<h3><u>DebuggerBrowsable</u></h3>
<p>Lets add to the client class a list of strings that will represent SubAccounts he might have. Using DebuggerBrowsable we have 3 options to mark that list and one of them is extremely useful:</p>
<ol>
<li>DebuggerBrowsableState.Collapsed: This is the default value and keeps the view exactly the way you know.
<p><a href="http://dev102.com/Dev102/wp-content/uploads/2009/04/debbugerbrowsablecollapsed.jpg"><img title="DebbugerBrowsable.Collapsed" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="102" alt="DebbugerBrowsable.Collapsed" src="http://dev102.com/Dev102/wp-content/uploads/2009/04/debbugerbrowsablecollapsed-thumb.jpg" width="529" border="0" /></a> </li>
<li>DebuggerBrowsableState.RootHidden: This makes the root of the <a href="http://www.dev102.com/2008/12/24/filtering-list-items-the-old-the-new-and-the-slick/">List</a> hidden and expands the list, so a 3 items list will look like this:
<p><a href="http://dev102.com/Dev102/wp-content/uploads/2009/04/debuggerbrowsableroothidden.png"><img title="DebuggerBrowsable.RootHidden" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="158" alt="DebuggerBrowsable.RootHidden" src="http://dev102.com/Dev102/wp-content/uploads/2009/04/debuggerbrowsableroothidden-thumb.png" width="532" border="0" /></a> </p>
<p>As you can see the list is all expanded and the List Data is under the Raw View. If you ask me I don&#8217;t really see a real life use for this. </p>
</li>
<li>DebuggerBrowsableState.Never: This makes the list go away! you cant see it in debug. I find this useful for people who write infrastructures in their company. Sometimes you don’t want to other users to see that list. This is your way of hiding it:
<p><a href="http://dev102.com/Dev102/wp-content/uploads/2009/04/debuggerbrowsablenever.jpg"><img title="DebuggerBrowsable.Never" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="108" alt="DebuggerBrowsable.Never" src="http://dev102.com/Dev102/wp-content/uploads/2009/04/debuggerbrowsablenever-thumb.jpg" width="535" border="0" /></a>&#160; <br />How about that, No List! </li>
</ol>
<p>More on other <a href="http://www.dev102.com/2008/05/09/6-useful-visual-studio-tweaks-you-need-to-know/">Debugger</a> Attributes soon</p>
<p>&#160;</p>
<p>Enjoy.</p>
<p>&#160;</p>
<p>Amit</p>

<p><a href="http://feedads.g.doubleclick.net/~a/N9NV5-HkPCmKZ1BUT7WhZNsJDIw/0/da"><img src="http://feedads.g.doubleclick.net/~a/N9NV5-HkPCmKZ1BUT7WhZNsJDIw/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/N9NV5-HkPCmKZ1BUT7WhZNsJDIw/1/da"><img src="http://feedads.g.doubleclick.net/~a/N9NV5-HkPCmKZ1BUT7WhZNsJDIw/1/di" border="0" ismap="true"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/Dev102feed?a=59zB-1vwy4k:PFWS0a6nVts:NT3aGUK8eJ0"><img src="http://feeds.feedburner.com/~ff/Dev102feed?d=NT3aGUK8eJ0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Dev102feed?a=59zB-1vwy4k:PFWS0a6nVts:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/Dev102feed?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Dev102feed?a=59zB-1vwy4k:PFWS0a6nVts:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/Dev102feed?i=59zB-1vwy4k:PFWS0a6nVts:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Dev102feed?a=59zB-1vwy4k:PFWS0a6nVts:dnMXMwOfBR0"><img src="http://feeds.feedburner.com/~ff/Dev102feed?d=dnMXMwOfBR0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Dev102feed?a=59zB-1vwy4k:PFWS0a6nVts:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/Dev102feed?i=59zB-1vwy4k:PFWS0a6nVts:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Dev102feed?a=59zB-1vwy4k:PFWS0a6nVts:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/Dev102feed?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Dev102feed?a=59zB-1vwy4k:PFWS0a6nVts:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/Dev102feed?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Dev102feed?a=59zB-1vwy4k:PFWS0a6nVts:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/Dev102feed?i=59zB-1vwy4k:PFWS0a6nVts:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Dev102feed?a=59zB-1vwy4k:PFWS0a6nVts:TzevzKxY174"><img src="http://feeds.feedburner.com/~ff/Dev102feed?d=TzevzKxY174" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/Dev102feed/~4/59zB-1vwy4k" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.dev102.com/2009/04/09/debuggerdisplay-and-debuggerbrowsable-two-debugger-attributes-you-should-know/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.dev102.com/2009/04/09/debuggerdisplay-and-debuggerbrowsable-two-debugger-attributes-you-should-know/</feedburner:origLink></item>
		<item>
		<title>Don’t Use a WPF Control in Windows.Resource</title>
		<link>http://feedproxy.google.com/~r/Dev102feed/~3/rhd9lh3U9H4/</link>
		<comments>http://www.dev102.com/2009/04/02/dont-use-a-wpf-control-in-windowsresource/#comments</comments>
		<pubDate>Thu, 02 Apr 2009 16:52:04 +0000</pubDate>
		<dc:creator>Amit</dc:creator>
		
		<category><![CDATA[.Net]]></category>

		<category><![CDATA[WPF]]></category>

		<category><![CDATA[DataTemplate]]></category>

		<category><![CDATA[image]]></category>

		<category><![CDATA[ItemsControl]]></category>

		<category><![CDATA[ItemsControl.ItemTemplate]]></category>

		<category><![CDATA[ItemTemplate]]></category>

		<category><![CDATA[List]]></category>

		<category><![CDATA[resources]]></category>

		<category><![CDATA[Source]]></category>

		<category><![CDATA[Window]]></category>

		<category><![CDATA[Window.Resources]]></category>

		<guid isPermaLink="false">http://www.dev102.com/?p=1164</guid>
		<description><![CDATA[<p>Hi</p>

<p>&#160;</p>

<p>Here is a problem that one of my colleagues who is just starting to use WPF got himself into. He was working on an application that displays items using an ItemsControl and uses a DataTemplate. Inside the DataTemplate he used an Image. Here is the Xaml code:</p>

<p>&#160;</p>

<div>
  <div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
    <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   1:</span> <span style="color: #0000ff">&#60;</span><span style="color: #800000">Window.Resources</span><span style="color: #0000ff">&#62;</span></pre>

    <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   2:</span>         <span style="color: #0000ff">&#60;</span><span style="color: #800000">Image</span> <span style="color: #ff0000">Source</span><span style="color: #0000ff">=&#34;Creek.jpg&#34;</span> <span style="color: #ff0000">x:Key</span><span style="color: #0000ff">=&#34;IMG&#34;</span><span style="color: #0000ff">&#62;&#60;/</span><span style="color: #800000">Image</span><span style="color: #0000ff">&#62;</span></pre>

    <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   3:</span>     <span style="color: #0000ff">&#60;/</span><span style="color: #800000">Window.Resources</span><span style="color: #0000ff">&#62;</span></pre>

    <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   4:</span>     <span style="color: #0000ff">&#60;</span><span style="color: #800000">Grid</span><span style="color: #0000ff">&#62;</span></pre>

    <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   5:</span>         <span style="color: #0000ff">&#60;</span><span style="color: #800000">ItemsControl</span> <span style="color: #ff0000">ItemsSource</span><span style="color: #0000ff">=&#34;{Binding}&#34;</span><span style="color: #0000ff">&#62;</span></pre>

    <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   6:</span>             <span style="color: #0000ff">&#60;</span><span style="color: #800000">ItemsControl.ItemTemplate</span><span style="color: #0000ff">&#62;</span></pre>

    <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   7:</span>                 <span style="color: #0000ff">&#60;</span><span style="color: #800000">DataTemplate</span><span style="color: #0000ff">&#62;</span></pre>

    <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   8:</span>                     <span style="color: #0000ff">&#60;</span><span style="color: #800000">Border</span> <span style="color: #ff0000">BorderThickness</span><span style="color: #0000ff">=&#34;2&#34;</span> <span style="color: #ff0000">BorderBrush</span><span style="color: #0000ff">=&#34;Black&#34;</span> </pre>

    <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   9:</span>                             <span style="color: #ff0000">CornerRadius</span><span style="color: #0000ff">=&#34;3&#34;</span> <span style="color: #ff0000">MinHeight</span><span style="color: #0000ff">=&#34;10&#34;</span><span style="color: #0000ff">&#62;</span></pre>

    <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  10:</span>                         <span style="color: #0000ff">&#60;</span><span style="color: #800000">ContentControl</span> <span style="color: #ff0000">Content</span><span style="color: #0000ff">=&#34;{StaticResource IMG}&#34;</span><span style="color: #0000ff">/&#62;</span></pre>

    <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  11:</span>                     <span style="color: #0000ff">&#60;/</span><span style="color: #800000">Border</span><span style="color: #0000ff">&#62;</span></pre>

    <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  12:</span>                 <span style="color: #0000ff">&#60;/</span><span style="color: #800000">DataTemplate</span><span style="color: #0000ff">&#62;</span></pre>

    <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  13:</span>             <span style="color: #0000ff">&#60;/</span><span style="color: #800000">ItemsControl.ItemTemplate</span><span style="color: #0000ff">&#62;</span></pre>

    <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  14:</span>         <span style="color: #0000ff">&#60;/</span><span style="color: #800000">ItemsControl</span><span style="color: #0000ff">&#62;</span></pre>

    <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  15:</span>     <span style="color: #0000ff">&#60;/</span><span style="color: #800000">Grid</span><span style="color: #0000ff">&#62;</span></pre>
  </div>
</div>

<p>This is a much simpler example, but the principal is the same.</p>

<p>&#160;</p>

<p>Can you see what was he doing wrong? </p>]]></description>
			<content:encoded><![CDATA[<p>Hi</p>
<p>&#160;</p>
<p>Here is a problem that one of my colleagues who is just starting to use WPF got himself into. He was working on an application that displays items using an <a href="http://www.dev102.com/2009/02/09/why-the-itemscontrol-scrollviewer-attached-property-does-not-work/">ItemsControl</a> and uses a DataTemplate. Inside the DataTemplate he used an Image. Here is the Xaml code:</p>
<p>&#160;</p>
<div>
<div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   1:</span> <span style="color: #0000ff">&lt;</span><span style="color: #800000">Window.Resources</span><span style="color: #0000ff">&gt;</span></pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   2:</span>         <span style="color: #0000ff">&lt;</span><span style="color: #800000">Image</span> <span style="color: #ff0000">Source</span><span style="color: #0000ff">=&quot;Creek.jpg&quot;</span> <span style="color: #ff0000">x:Key</span><span style="color: #0000ff">=&quot;IMG&quot;</span><span style="color: #0000ff">&gt;&lt;/</span><span style="color: #800000">Image</span><span style="color: #0000ff">&gt;</span></pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   3:</span>     <span style="color: #0000ff">&lt;/</span><span style="color: #800000">Window.Resources</span><span style="color: #0000ff">&gt;</span></pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   4:</span>     <span style="color: #0000ff">&lt;</span><span style="color: #800000">Grid</span><span style="color: #0000ff">&gt;</span></pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   5:</span>         <span style="color: #0000ff">&lt;</span><span style="color: #800000">ItemsControl</span> <span style="color: #ff0000">ItemsSource</span><span style="color: #0000ff">=&quot;{Binding}&quot;</span><span style="color: #0000ff">&gt;</span></pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   6:</span>             <span style="color: #0000ff">&lt;</span><span style="color: #800000">ItemsControl.ItemTemplate</span><span style="color: #0000ff">&gt;</span></pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   7:</span>                 <span style="color: #0000ff">&lt;</span><span style="color: #800000">DataTemplate</span><span style="color: #0000ff">&gt;</span></pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   8:</span>                     <span style="color: #0000ff">&lt;</span><span style="color: #800000">Border</span> <span style="color: #ff0000">BorderThickness</span><span style="color: #0000ff">=&quot;2&quot;</span> <span style="color: #ff0000">BorderBrush</span><span style="color: #0000ff">=&quot;Black&quot;</span> </pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   9:</span>                             <span style="color: #ff0000">CornerRadius</span><span style="color: #0000ff">=&quot;3&quot;</span> <span style="color: #ff0000">MinHeight</span><span style="color: #0000ff">=&quot;10&quot;</span><span style="color: #0000ff">&gt;</span></pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  10:</span>                         <span style="color: #0000ff">&lt;</span><span style="color: #800000">ContentControl</span> <span style="color: #ff0000">Content</span><span style="color: #0000ff">=&quot;{StaticResource IMG}&quot;</span><span style="color: #0000ff">/&gt;</span></pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  11:</span>                     <span style="color: #0000ff">&lt;/</span><span style="color: #800000">Border</span><span style="color: #0000ff">&gt;</span></pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  12:</span>                 <span style="color: #0000ff">&lt;/</span><span style="color: #800000">DataTemplate</span><span style="color: #0000ff">&gt;</span></pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  13:</span>             <span style="color: #0000ff">&lt;/</span><span style="color: #800000">ItemsControl.ItemTemplate</span><span style="color: #0000ff">&gt;</span></pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  14:</span>         <span style="color: #0000ff">&lt;/</span><span style="color: #800000">ItemsControl</span><span style="color: #0000ff">&gt;</span></pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  15:</span>     <span style="color: #0000ff">&lt;/</span><span style="color: #800000">Grid</span><span style="color: #0000ff">&gt;</span></pre>
</p></div>
</div>
<p>This is a much simpler example, but the principal is the same.</p>
<p>&#160;</p>
<p>Can you see what was he doing wrong? </p>
<p>&#160;</p>
<p>In the code behind I will create a list and use it as the <a href="http://www.dev102.com/2008/05/27/how-to-create-a-wpf-two-level-master-detail-application-with-comboboxes/">DataContext</a>:</p>
<div>
<div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   1:</span> <span style="color: #0000ff">public</span> Window1()</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   2:</span> {</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   3:</span>    InitializeComponent();</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   4:</span>    List&lt;<span style="color: #0000ff">int</span>&gt; data = <span style="color: #0000ff">new</span> List&lt;<span style="color: #0000ff">int</span>&gt; { 1, 2, 3, 4 };</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   5:</span>    <span style="color: #0000ff">this</span>.DataContext = data;</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   6:</span> }</pre>
</p></div>
</div>
<p>You will expect to see a window with 4 Images, but this is what you get:</p>
<p align="center"><a href="http://dev102.com/Dev102/wp-content/uploads/2009/04/badresourceusage.jpg"><img title="Bad Resource Usage" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="483" alt="Bad Resource Usage" src="http://dev102.com/Dev102/wp-content/uploads/2009/04/badresourceusage-thumb.jpg" width="449" border="0" /></a></p>
<p>Only one image shows up and all the other templates are empty. </p>
<p>&#160;</p>
<p>Can you see the problem now? </p>
<p>&#160;</p>
<p>It took me some time to see it because the code was much more complex, but then I noticed that he used the <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.image.aspx">Image</a> class as a resource for the Image. </p>
<p>&#160;</p>
<p>Image is a <a href="http://www.dev102.com/2008/08/07/how-to-access-a-wpf-control-which-is-located-in-a-datatemplate/">WPF Control</a> and can only have one parent! This is why it only displayed at the last item of the list. This is similar to doing the following:</p>
<div>
<div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   1:</span> Image m = <span style="color: #0000ff">new</span> Image();</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   2:</span> Border b1 = <span style="color: #0000ff">new</span> Border();</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   3:</span> Border b2 = <span style="color: #0000ff">new</span> Border();</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   4:</span> b1.Child = m;</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   5:</span> b2.Child = m;</pre>
</p></div>
</div>
<p>What would happen here? The following:</p>
<p><a href="http://dev102.com/Dev102/wp-content/uploads/2009/04/illegalchildexception.jpg"><img title="Illegal child exception" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="443" alt="Illegal child exception" src="http://dev102.com/Dev102/wp-content/uploads/2009/04/illegalchildexception-thumb.jpg" width="591" border="0" /></a> </p>
<p>I was actually surprised that my friend did not get an <a href="http://www.dev102.com/2008/04/14/unhandled-exceptions-handle-them/">Exception</a>, I will definitely have to check why no exception was thrown.</p>
<p>To correct the problem all you have to do is to use Bitmap Image which is a C# Class and not a WPF Control. You should use an Image in the template and use the BitmapImage as its source:</p>
<div>
<div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   1:</span> <span style="color: #0000ff">&lt;</span><span style="color: #800000">Window.Resources</span><span style="color: #0000ff">&gt;</span></pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   2:</span>    <span style="color: #008000">&lt;!--&lt;Image Source=&quot;Creek.jpg&quot; x:Key=&quot;IMG&quot;&gt;&lt;/Image&gt;--&gt;</span></pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   3:</span>    <span style="color: #0000ff">&lt;</span><span style="color: #800000">BitmapImage</span> <span style="color: #ff0000">UriSource</span><span style="color: #0000ff">=&quot;Creek.jpg&quot;</span> <span style="color: #ff0000">x:Key</span><span style="color: #0000ff">=&quot;BMP&quot;</span><span style="color: #0000ff">&gt;&lt;/</span><span style="color: #800000">BitmapImage</span><span style="color: #0000ff">&gt;</span></pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   4:</span> <span style="color: #0000ff">&lt;/</span><span style="color: #800000">Window.Resources</span><span style="color: #0000ff">&gt;</span>    </pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   5:</span> <span style="color: #0000ff">&lt;</span><span style="color: #800000">Grid</span><span style="color: #0000ff">&gt;</span></pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   6:</span>    <span style="color: #0000ff">&lt;</span><span style="color: #800000">ItemsControl</span> <span style="color: #ff0000">ItemsSource</span><span style="color: #0000ff">=&quot;{Binding}&quot;</span><span style="color: #0000ff">&gt;</span></pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   7:</span>        <span style="color: #0000ff">&lt;</span><span style="color: #800000">ItemsControl.ItemTemplate</span><span style="color: #0000ff">&gt;</span></pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   8:</span>            <span style="color: #0000ff">&lt;</span><span style="color: #800000">DataTemplate</span><span style="color: #0000ff">&gt;</span></pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   9:</span>                <span style="color: #0000ff">&lt;</span><span style="color: #800000">Border</span> <span style="color: #ff0000">BorderThickness</span><span style="color: #0000ff">=&quot;2&quot;</span> <span style="color: #ff0000">BorderBrush</span><span style="color: #0000ff">=&quot;Black&quot;</span> </pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  10:</span>                        <span style="color: #ff0000">CornerRadius</span><span style="color: #0000ff">=&quot;3&quot;</span> <span style="color: #ff0000">MinHeight</span><span style="color: #0000ff">=&quot;10&quot;</span><span style="color: #0000ff">&gt;</span></pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  11:</span>                    <span style="color: #008000">&lt;!--&lt;ContentControl Content=&quot;{StaticResource IMG}&quot;/&gt;--&gt;</span></pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  12:</span>                    <span style="color: #0000ff">&lt;</span><span style="color: #800000">Image</span> <span style="color: #ff0000">Source</span><span style="color: #0000ff">=&quot;{StaticResource BMP}&quot;</span><span style="color: #0000ff">&gt;&lt;/</span><span style="color: #800000">Image</span><span style="color: #0000ff">&gt;</span></pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  13:</span>                <span style="color: #0000ff">&lt;/</span><span style="color: #800000">Border</span><span style="color: #0000ff">&gt;</span></pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  14:</span>            <span style="color: #0000ff">&lt;/</span><span style="color: #800000">DataTemplate</span><span style="color: #0000ff">&gt;</span></pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  15:</span>        <span style="color: #0000ff">&lt;/</span><span style="color: #800000">ItemsControl.ItemTemplate</span><span style="color: #0000ff">&gt;</span></pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  16:</span>    <span style="color: #0000ff">&lt;/</span><span style="color: #800000">ItemsControl</span><span style="color: #0000ff">&gt;</span></pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  17:</span> <span style="color: #0000ff">&lt;/</span><span style="color: #800000">Grid</span><span style="color: #0000ff">&gt;</span></pre>
</p></div>
</div>
<p>The result:</p>
<p align="center"><a href="http://dev102.com/Dev102/wp-content/uploads/2009/04/goodresourceusage.jpg"><img title="Good Resource Usage" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="612" alt="Good Resource Usage" src="http://dev102.com/Dev102/wp-content/uploads/2009/04/goodresourceusage-thumb.jpg" width="209" border="0" /></a></p>
<p>&#160;</p>
<p>Exactly what we wanted.</p>
<p>&#160;</p>
<p>If any of you have an idea as to why we did not get an exception I will be happy to hear it.</p>
<p>&#160;</p>
<p>Amit</p>

<p><a href="http://feedads.g.doubleclick.net/~a/JPTeWrjGGVLy7unWIQTNUzYmq_w/0/da"><img src="http://feedads.g.doubleclick.net/~a/JPTeWrjGGVLy7unWIQTNUzYmq_w/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/JPTeWrjGGVLy7unWIQTNUzYmq_w/1/da"><img src="http://feedads.g.doubleclick.net/~a/JPTeWrjGGVLy7unWIQTNUzYmq_w/1/di" border="0" ismap="true"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/Dev102feed?a=rhd9lh3U9H4:YKQlmsygtlQ:NT3aGUK8eJ0"><img src="http://feeds.feedburner.com/~ff/Dev102feed?d=NT3aGUK8eJ0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Dev102feed?a=rhd9lh3U9H4:YKQlmsygtlQ:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/Dev102feed?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Dev102feed?a=rhd9lh3U9H4:YKQlmsygtlQ:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/Dev102feed?i=rhd9lh3U9H4:YKQlmsygtlQ:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Dev102feed?a=rhd9lh3U9H4:YKQlmsygtlQ:dnMXMwOfBR0"><img src="http://feeds.feedburner.com/~ff/Dev102feed?d=dnMXMwOfBR0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Dev102feed?a=rhd9lh3U9H4:YKQlmsygtlQ:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/Dev102feed?i=rhd9lh3U9H4:YKQlmsygtlQ:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Dev102feed?a=rhd9lh3U9H4:YKQlmsygtlQ:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/Dev102feed?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Dev102feed?a=rhd9lh3U9H4:YKQlmsygtlQ:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/Dev102feed?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Dev102feed?a=rhd9lh3U9H4:YKQlmsygtlQ:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/Dev102feed?i=rhd9lh3U9H4:YKQlmsygtlQ:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Dev102feed?a=rhd9lh3U9H4:YKQlmsygtlQ:TzevzKxY174"><img src="http://feeds.feedburner.com/~ff/Dev102feed?d=TzevzKxY174" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/Dev102feed/~4/rhd9lh3U9H4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.dev102.com/2009/04/02/dont-use-a-wpf-control-in-windowsresource/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.dev102.com/2009/04/02/dont-use-a-wpf-control-in-windowsresource/</feedburner:origLink></item>
	</channel>
</rss><!-- Dynamic page generated in 0.992 seconds. --><!-- Cached page generated by WP-Super-Cache on 2009-07-06 00:19:22 -->
