<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Elegant Code</title>
	<atom:link href="http://elegantcode.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://elegantcode.com</link>
	<description></description>
	<lastBuildDate>Sun, 14 Mar 2010 00:13:19 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Asp.Net MVC 2 Areas</title>
		<link>http://elegantcode.com/2010/03/13/asp-net-mvc-2-areas/</link>
		<comments>http://elegantcode.com/2010/03/13/asp-net-mvc-2-areas/#comments</comments>
		<pubDate>Sun, 14 Mar 2010 00:13:19 +0000</pubDate>
		<dc:creator>Chris Brandsma</dc:creator>
				<category><![CDATA[Asp.Net MVC]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2010/03/13/asp-net-mvc-2-areas/</guid>
		<description><![CDATA[I’m looking into the new stuff in Asp.Net MVC 2, trying to figure out what is cool and what is just there.&#160; Areas look like a nice addition.&#160; Areas allow you to separate your Asp.Net MVC application into more distinct partitions.&#160; So all of the Controllers, Models, Views, and even routes belong to one directory [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://elegantcode.com/wp-content/uploads/2010/03/image13.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; margin-left: 0px; border-top: 0px; margin-right: 0px; border-right: 0px" title="image" border="0" alt="image" align="right" src="http://elegantcode.com/wp-content/uploads/2010/03/image_thumb13.png" width="119" height="244" /></a>I’m looking into the new stuff in Asp.Net MVC 2, trying to figure out what is cool and what is just there.&#160; Areas look like a nice addition.&#160; Areas allow you to separate your Asp.Net MVC application into more distinct partitions.&#160; So all of the Controllers, Models, Views, and even routes belong to one directory structure.&#160; It is like having a sub-project inside of you MVC project. </p>
<p>Here is the problem, as I see it:&#160; as an MVC project gets large, keeping all of the necessary pieces and parts for a set of controller actions straight can get a bit daunting.&#160; I’ve ended up with duplicate folder structures in views and models, which can make navigation a pain.</p>
<p>To make a new Area, simply right-click anywhere in you MVC project, Add-&gt;Area.&#160; As I said, you can do this from anywhere in the project structure, but the Areas are created in a new “Areas” folder.&#160; When you name the Area, a new folder is created with the Areas name as well.</p>
<p>Once created you should see all the familiar Controllers, Models, and Views folders (all blank).&#160; In addition to that, you will see an &lt;name&gt;AreaRegistration.cs file.&#160; This inherits from AreaRegistration, and this is where any new Routes go.&#160; In the file is a prebuilt route that should look similar to this:</p>
<div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" 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: white; 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> context.MapRoute(</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: #006080">&quot;test1_default&quot;</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: white; 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: #006080">&quot;test1/{controller}/{action}/{id}&quot;</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>     <span style="color: #0000ff">new</span> { action = <span style="color: #006080">&quot;Index&quot;</span>, id = UrlParameter.Optional }</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: white; 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> );</pre>
<p><!--CRLF--></div>
</div>
<p>So a url to the area would include /test1/ (name of my Area) in the path.&#160; That would be good if you had multiple controllers with the same name, but if you don’t, just take out the “test1” and you won’t need it in the path.</p>
<p>Also, if you leave Area name in the route, you will have a little more work to, here is what one of mine looked like:&#160; &lt;%=Html.ActionLink(&quot;test&quot;, &quot;Index&quot;, &quot;test1/TestArea&quot;) %&gt;.&#160; But it turns out this is more correct: </p>
<p>&lt;%=Html.ActionLink(&quot;test&quot;, &quot;Index&quot;, &quot;TestArea&quot;, new { area=&quot;Test1&quot;}, new {}) %&gt; </p>
<p>This also mean that any controller actions you want to link to outside if Area needs to include a blank area in the link, like this:</p>
<p>&lt;%=Html.ActionLink(&quot;Home&quot;, &quot;Index&quot;, &quot;Home&quot;, new { area=&quot;&quot;}, new {}) %&gt; </p>
</p>
<p>In case you are wondering, the first object in the area is for route values, the second is for html attributes.</p>
<p>So the downside of using Areas is that you could complicate your routing in a hurry.&#160; Plus it does not look like the Html helpers are there to lend you a hand either.&#160; It is very doable, just annoying.&#160; Of course, the easy fix is to remove the Area name from the route and move on.&#160; That should be ok so long as you do not have two controllers with the same name.</p>
<p>So are Areas a compelling feature? I think so.&#160; Plus, the larger the site, the more compelling Areas can become.&#160; For smaller sites, probably not.&#160; But I would not say no either.</p>
]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2010/03/13/asp-net-mvc-2-areas/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MvcFutures</title>
		<link>http://elegantcode.com/2010/03/13/mvcfutures/</link>
		<comments>http://elegantcode.com/2010/03/13/mvcfutures/#comments</comments>
		<pubDate>Sat, 13 Mar 2010 17:49:42 +0000</pubDate>
		<dc:creator>Tony Rasa</dc:creator>
				<category><![CDATA[Asp.Net MVC]]></category>
		<category><![CDATA[ExpressionHelper]]></category>
		<category><![CDATA[MvcFutures]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2010/03/13/mvcfutures/</guid>
		<description><![CDATA[ASP.NET MVC 2 has been released (yay).&#160; One of the pieces I like about it is in the MvcFutures assembly.&#160; MvcFutures is where the MVC team puts code for features that may or may not make it into a future version of the MVC framework – undocumented, somewhat risky, but hey you get all the [...]]]></description>
			<content:encoded><![CDATA[<p>ASP.NET MVC 2 has been released (yay).&#160; One of the pieces I like about it is in the MvcFutures assembly.&#160; MvcFutures is where the MVC team puts code for features that may or may not make it into a future version of the MVC framework – undocumented, somewhat risky, but hey you get all the source code if you find yourself painted into a corner.</p>
<p>One of the long-standing MVC practices has been ‘Shun Magic Strings.’&#160; For example, rather than specifying Controller/Action names in an ActionLink by string, we’ve always used an Expression&lt;Action&lt;TController&gt;&gt; instead to define the Controller class and Action method “in code.”&#160; If the action changes in the future, this gives you somewhat better abilities to discover the problem sooner vs. later.&#160; </p>
<p>MvcFutures includes a version of this idea, taken to the next level:&#160; you provide the expression with the arguments you want passed to the action included – you don’t provide a 2nd anonymous type defining the arguments.&#160; This gets rid of the somewhat confusing “null” arguments inside the expression, and just looks better overall.&#160; Plus, if the arguments to the action change, you’ll get better warning of that as well.</p>
<div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper">
<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" id="codeSnippet">&lt;asp:Content ID=<span style="color: #006080">&quot;Content2&quot;</span> ContentPlaceHolderID=<span style="color: #006080">&quot;MainContent&quot;</span> runat=<span style="color: #006080">&quot;server&quot;</span>&gt;    &lt;h2&gt;Magic Strings are Evil&lt;/h2&gt;    &lt;p&gt;        &lt;%= Html.ActionLink&lt;HomeController&gt;(c =&gt; c.FavoriteNumber(16), <span style="color: #006080">&quot;A Number&quot;</span>) %&gt;        &lt;%= Html.ActionLink&lt;HomeController&gt;(c =&gt; c.FavoriteNumber(32), <span style="color: #006080">&quot;Another Number&quot;</span>) %&gt;        &lt;%= Html.ActionLink&lt;HomeController&gt;(c =&gt; c.FavoriteNumber(42), <span style="color: #006080">&quot;Yet Another Number&quot;</span>) %&gt;            &lt;/p&gt;&lt;/asp:Content&gt;</pre>
<p></div>
<p>I like this method MUCH better.&#160; </p>
<p>The implementation that makes this happen is in Microsoft.Web.Mvc.Internal.ExpressionHelper.&#160; Which even though it’s in an “Internal” namespace, is neither marked Internal, Sealed, or otherwise made unavailable (hallelujah).&#160; So you can use this trick for all sorts of things.</p>
<p>There is also a System.Web.Mvc.ExpressionHelper in the official MVC assembly, which is used to implement the smart Html.TextBoxFor(m =&gt; m.Property) functionality.&#160; This class is also NOT internal, not sealed, not obfuscated and hidden away.&#160; We’ve used it to extend the Html.[control]For() abilities to some other control types.&#160; Very useful stuff.&#160; Plus its just interesting code to read.</p>
<p><strong>One potentially big caveat:</strong>&#160; I’m told that the Html.ActionLink&lt;TController&gt;() methods don’t work if you’re using Areas in your MVC application.&#160; I haven’t tried this myself, we aren’t using Areas in any of our MVC 2 applications yet.&#160; That might be why this functionality is hidden in MvcFutures and not out with the rest of the smart expression code.</p>
]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2010/03/13/mvcfutures/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Silverlight 4: Implicit Themes and a Sneak Peek</title>
		<link>http://elegantcode.com/2010/03/12/silverlight-4-implicit-themes-and-a-sneak-peek/</link>
		<comments>http://elegantcode.com/2010/03/12/silverlight-4-implicit-themes-and-a-sneak-peek/#comments</comments>
		<pubDate>Sat, 13 Mar 2010 01:26:34 +0000</pubDate>
		<dc:creator>Brian Lagunas</dc:creator>
				<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[implicit themes]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2010/03/12/silverlight-4-implicit-themes-and-a-sneak-peek/</guid>
		<description><![CDATA[One of my major gripes with Silverlight 3 is the inability to theme your application.&#160; Currently if you want to style a button for your application you will have to define a style similar to this:


&#60;UserControl.Resources&#62;
    &#60;Style x:Key=&#34;myButtonStyle&#34; TargetType=&#34;Button&#34;&#62;
        &#60;Setter Property=&#34;Background&#34; Value=&#34;Blue&#34; /&#62;
   [...]]]></description>
			<content:encoded><![CDATA[<p>One of my major gripes with Silverlight 3 is the inability to theme your application.&#160; Currently if you want to style a button for your application you will have to define a style similar to this:</p>
<div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" 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: white; 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: #0000ff">&lt;</span><span style="color: #800000">UserControl.Resources</span><span style="color: #0000ff">&gt;</span></pre>
<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: #0000ff">&lt;</span><span style="color: #800000">Style</span> <span style="color: #ff0000">x:Key</span><span style="color: #0000ff">=&quot;myButtonStyle&quot;</span> <span style="color: #ff0000">TargetType</span><span style="color: #0000ff">=&quot;Button&quot;</span><span style="color: #0000ff">&gt;</span></pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; 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: #0000ff">&lt;</span><span style="color: #800000">Setter</span> <span style="color: #ff0000">Property</span><span style="color: #0000ff">=&quot;Background&quot;</span> <span style="color: #ff0000">Value</span><span style="color: #0000ff">=&quot;Blue&quot;</span> <span style="color: #0000ff">/&gt;</span></pre>
<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: #0000ff">&lt;</span><span style="color: #800000">Setter</span> <span style="color: #ff0000">Property</span><span style="color: #0000ff">=&quot;Foreground&quot;</span> <span style="color: #ff0000">Value</span><span style="color: #0000ff">=&quot;Green&quot;</span> <span style="color: #0000ff">/&gt;</span></pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; 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: #0000ff">&lt;</span><span style="color: #800000">Setter</span> <span style="color: #ff0000">Property</span><span style="color: #0000ff">=&quot;FontSize&quot;</span> <span style="color: #ff0000">Value</span><span style="color: #0000ff">=&quot;24&quot;</span> <span style="color: #0000ff">/&gt;</span></pre>
<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: #0000ff">&lt;/</span><span style="color: #800000">Style</span><span style="color: #0000ff">&gt;</span></pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; 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: #0000ff">&lt;/</span><span style="color: #800000">UserControl.Resources</span><span style="color: #0000ff">&gt;</span></pre>
</p></div>
</div>
<p>Then, you have to set the Style property on the Button control you want to apply the style to:</p>
<div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" 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: white; 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: #0000ff">&lt;</span><span style="color: #800000">Button</span> <span style="color: #ff0000">Content</span><span style="color: #0000ff">=&quot;Button 1&quot;</span> <span style="color: #ff0000">Style</span><span style="color: #0000ff">=&quot;{StaticResource myButtonStyle}&quot;</span> <span style="color: #0000ff">/&gt;</span></pre>
</p></div>
</div>
<p>Now, what if I want to apply that same style to every button in my application?&#160; Well I would have to go and find every single button in my application and set the Style property accordingly.</p>
<div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" 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: white; 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: #0000ff">&lt;</span><span style="color: #800000">Button</span> <span style="color: #ff0000">Content</span><span style="color: #0000ff">=&quot;Button 1&quot;</span> <span style="color: #ff0000">Style</span><span style="color: #0000ff">=&quot;{StaticResource myButtonStyle}&quot;</span> <span style="color: #0000ff">/&gt;</span></pre>
<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: #0000ff">&lt;</span><span style="color: #800000">Button</span> <span style="color: #ff0000">Content</span><span style="color: #0000ff">=&quot;Button 2&quot;</span> <span style="color: #ff0000">Style</span><span style="color: #0000ff">=&quot;{StaticResource myButtonStyle}&quot;</span> <span style="color: #0000ff">/&gt;</span></pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; 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: #0000ff">&lt;</span><span style="color: #800000">Button</span> <span style="color: #ff0000">Content</span><span style="color: #0000ff">=&quot;Button 3&quot;</span> <span style="color: #ff0000">Style</span><span style="color: #0000ff">=&quot;{StaticResource myButtonStyle}&quot;</span> <span style="color: #0000ff">/&gt;</span></pre>
</p></div>
</div>
<p>How many buttons are in your application?&#160; What a pain in the you know what.&#160; Well not anymore.&#160; New in Silverlight 4 will be the ability to set your styles implicitly.&#160; What does this mean?&#160; It means that you can now declare your style, give it a TargetType, and exclude the x:Key; then it will apply that style to any instance of the TargetType control type.</p>
<div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" 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: white; 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: #0000ff">&lt;</span><span style="color: #800000">UserControl.Resources</span><span style="color: #0000ff">&gt;</span></pre>
<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: #0000ff">&lt;</span><span style="color: #800000">Style</span> <span style="color: #ff0000">TargetType</span><span style="color: #0000ff">=&quot;Button&quot;</span><span style="color: #0000ff">&gt;</span></pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; 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: #0000ff">&lt;</span><span style="color: #800000">Setter</span> <span style="color: #ff0000">Property</span><span style="color: #0000ff">=&quot;Background&quot;</span> <span style="color: #ff0000">Value</span><span style="color: #0000ff">=&quot;Blue&quot;</span> <span style="color: #0000ff">/&gt;</span></pre>
<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: #0000ff">&lt;</span><span style="color: #800000">Setter</span> <span style="color: #ff0000">Property</span><span style="color: #0000ff">=&quot;Foreground&quot;</span> <span style="color: #ff0000">Value</span><span style="color: #0000ff">=&quot;Green&quot;</span> <span style="color: #0000ff">/&gt;</span></pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; 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: #0000ff">&lt;</span><span style="color: #800000">Setter</span> <span style="color: #ff0000">Property</span><span style="color: #0000ff">=&quot;FontSize&quot;</span> <span style="color: #ff0000">Value</span><span style="color: #0000ff">=&quot;24&quot;</span> <span style="color: #0000ff">/&gt;</span></pre>
<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: #0000ff">&lt;/</span><span style="color: #800000">Style</span><span style="color: #0000ff">&gt;</span></pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; 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: #0000ff">&lt;/</span><span style="color: #800000">UserControl.Resources</span><span style="color: #0000ff">&gt;</span></pre>
<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">&#160;</pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; 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: #0000ff">&lt;</span><span style="color: #800000">Grid</span> <span style="color: #ff0000">x:Name</span><span style="color: #0000ff">=&quot;LayoutRoot&quot;</span><span style="color: #0000ff">&gt;</span></pre>
<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: #0000ff">&lt;</span><span style="color: #800000">StackPanel</span><span style="color: #0000ff">&gt;</span></pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; 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: #0000ff">&lt;</span><span style="color: #800000">Button</span> <span style="color: #ff0000">Content</span><span style="color: #0000ff">=&quot;Button 1&quot;</span> <span style="color: #0000ff">/&gt;</span></pre>
<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: #0000ff">&lt;</span><span style="color: #800000">Button</span> <span style="color: #ff0000">Content</span><span style="color: #0000ff">=&quot;Button 2&quot;</span> <span style="color: #0000ff">/&gt;</span></pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; 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: #0000ff">&lt;</span><span style="color: #800000">Button</span> <span style="color: #ff0000">Content</span><span style="color: #0000ff">=&quot;Button 3&quot;</span> <span style="color: #0000ff">/&gt;</span></pre>
<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: #0000ff">&lt;/</span><span style="color: #800000">StackPanel</span><span style="color: #0000ff">&gt;</span></pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; 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: #0000ff">&lt;/</span><span style="color: #800000">Grid</span><span style="color: #0000ff">&gt;</span></pre>
</p></div>
</div>
<p>Notice that I don’t need to set the Style property on my button controls individually anymore.</p>
<p><a href="http://elegantcode.com/wp-content/uploads/2010/03/image11.png" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="implicit theming" border="0" alt="implicit theming" src="http://elegantcode.com/wp-content/uploads/2010/03/image_thumb11.png" width="248" height="72" /></a> </p>
<p>Well what if I have a style that I want to implicitly use, but I have this one special button that I want to give a different style?&#160; Well in that case, just create a new Style and give it a x:Key, then set the Style property on your control.</p>
<div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" 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: white; 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: #0000ff">&lt;</span><span style="color: #800000">Style</span> <span style="color: #ff0000">x:Key</span><span style="color: #0000ff">=&quot;myOtherButtonStyle&quot;</span> <span style="color: #ff0000">TargetType</span><span style="color: #0000ff">=&quot;Button&quot;</span><span style="color: #0000ff">&gt;</span></pre>
<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: #0000ff">&lt;</span><span style="color: #800000">Setter</span> <span style="color: #ff0000">Property</span><span style="color: #0000ff">=&quot;Background&quot;</span> <span style="color: #ff0000">Value</span><span style="color: #0000ff">=&quot;Orange&quot;</span> <span style="color: #0000ff">/&gt;</span></pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; 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: #0000ff">&lt;</span><span style="color: #800000">Setter</span> <span style="color: #ff0000">Property</span><span style="color: #0000ff">=&quot;Foreground&quot;</span> <span style="color: #ff0000">Value</span><span style="color: #0000ff">=&quot;Red&quot;</span> <span style="color: #0000ff">/&gt;</span></pre>
<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: #0000ff">&lt;</span><span style="color: #800000">Setter</span> <span style="color: #ff0000">Property</span><span style="color: #0000ff">=&quot;FontSize&quot;</span> <span style="color: #ff0000">Value</span><span style="color: #0000ff">=&quot;12&quot;</span> <span style="color: #0000ff">/&gt;</span></pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; 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: #0000ff">&lt;/</span><span style="color: #800000">Style</span><span style="color: #0000ff">&gt;</span></pre>
<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">&#160;</pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; 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: #0000ff">&lt;</span><span style="color: #800000">Button</span> <span style="color: #ff0000">Content</span><span style="color: #0000ff">=&quot;Button 1&quot;</span> <span style="color: #0000ff">/&gt;</span></pre>
<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: #0000ff">&lt;</span><span style="color: #800000">Button</span> <span style="color: #ff0000">Content</span><span style="color: #0000ff">=&quot;Button 2&quot;</span> <span style="color: #ff0000">Style</span><span style="color: #0000ff">=&quot;{StaticResource myOtherButtonStyle}&quot;</span> <span style="color: #0000ff">/&gt;</span></pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; 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: #0000ff">&lt;</span><span style="color: #800000">Button</span> <span style="color: #ff0000">Content</span><span style="color: #0000ff">=&quot;Button 3&quot;</span> <span style="color: #0000ff">/&gt;</span></pre>
</p></div>
</div>
<p><a href="http://elegantcode.com/wp-content/uploads/2010/03/image12.png" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="special style" border="0" alt="special style" src="http://elegantcode.com/wp-content/uploads/2010/03/image_thumb12.png" width="248" height="63" /></a> </p>
<p>Now, your special button will use your new style, and all others will remain themed.</p>
<h2>Sneak Peek: Silverlight Application Themes</h2>
<p><a href="http://timheuer.com/blog/archive/2010/03/11/silverlight-application-theme-preview-sneak-peek-template.aspx" target="_blank">Tim Heuer</a> has recently given us a preview of three new theme packs coming to Silverlight.</p>
<h4>“GrayScale”</h4>
<p><a href="http://elegantcode.com/wp-content/uploads/2010/03/grayscalesampleapp.jpg" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="GrayScale Theme" border="0" alt="GrayScale Theme" src="http://elegantcode.com/wp-content/uploads/2010/03/grayscalesampleapp_thumb.jpg" width="248" height="152" /></a> </p>
<h4>“Windows Theme”</h4>
<p><a href="http://elegantcode.com/wp-content/uploads/2010/03/winthemesampleapp.jpg" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Windows Theme" border="0" alt="Windows Theme" src="http://elegantcode.com/wp-content/uploads/2010/03/winthemesampleapp_thumb.jpg" width="248" height="168" /></a> </p>
<h4>“Metro”</h4>
<p><a href="http://elegantcode.com/wp-content/uploads/2010/03/whitesampleapp.jpg" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Metro Theme" border="0" alt="Metro Theme" src="http://elegantcode.com/wp-content/uploads/2010/03/whitesampleapp_thumb.jpg" width="248" height="159" /></a></p>
<p>Thanks Tim!</p>
]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2010/03/12/silverlight-4-implicit-themes-and-a-sneak-peek/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Silverlight DataGrid &#8211; Populate Dynamic Columns from a Child Collection</title>
		<link>http://elegantcode.com/2010/03/08/silverlight-datagrid-populate-dynamic-columns-from-a-child-collection/</link>
		<comments>http://elegantcode.com/2010/03/08/silverlight-datagrid-populate-dynamic-columns-from-a-child-collection/#comments</comments>
		<pubDate>Tue, 09 Mar 2010 01:56:03 +0000</pubDate>
		<dc:creator>Brian Lagunas</dc:creator>
				<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[dynamic columns]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2010/03/08/silverlight-datagrid-populate-dynamic-columns-from-a-child-collection/</guid>
		<description><![CDATA[Lets face it, any one building LOB (line of business) applications know that their users love Microsoft Excel.&#160; If the users had their way, they would do everything in Excel.&#160; Due to this known fact, when building Silverlight LOB applications, there is often a need to flatten out an object for editing in a grid.&#160; [...]]]></description>
			<content:encoded><![CDATA[<p>Lets face it, any one building LOB (line of business) applications know that their users love Microsoft Excel.&#160; If the users had their way, they would do everything in Excel.&#160; Due to this known fact, when building Silverlight LOB applications, there is often a need to flatten out an object for editing in a grid.&#160; For example; you may have an object that has an<em> n</em>-level number of properties or attributes that aren’t known until runtime, but you want to edit the object in a single row in a grid. You don’t want to add a bunch of properties on your object like Prop1, Prop2, Prop3, etc.., just so you can bind it to your grid.&#160; You want to dynamically add columns to your grid and bind those columns to the correct object in the child collection at run time.</p>
<p>Well, this is much easier than you may think and I will show you how to accomplish this with just a few simple helper methods, and you can use any grid of your choice.&#160; For this example, I will be using the DataGrid that comes with the <a href="http://www.codeplex.com/Silverlight" target="_blank">Silverlight Toolkit</a>. Make sure you download and install it, because I am not including the System.Windows.Controls.Data assembly required for the DataGrid.</p>
<p>It will be located at c:\Program Files\Microsoft SDKs\Silverlight\v3.0\Libraries\Client\System.Windows.Controls.Data.dll</p>
<p>In my scenario I am building a staffing application and I have a “StaffMember” object that has a collection of “Period” objects as a child property.&#160; My objects look something like this:</p>
<div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" 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: white; 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: #0000ff">public</span> <span style="color: #0000ff">class</span> StaffMember</pre>
<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">{</pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; 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: #0000ff">public</span> <span style="color: #0000ff">string</span> Name { get; set; }</pre>
<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: #0000ff">public</span> <span style="color: #0000ff">string</span> Department { get; set; }</pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; 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: #0000ff">public</span> ObservableCollection&lt;Period&gt; Periods { get; set; }</pre>
<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">}</pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; 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">&#160;</pre>
<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: #0000ff">public</span> <span style="color: #0000ff">class</span> Period</pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; 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">{</pre>
<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: #0000ff">public</span> <span style="color: #0000ff">string</span> Title { get; set; }</pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; 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: #0000ff">public</span> <span style="color: #0000ff">int</span> Hours { get; set; }</pre>
<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">}</pre>
</p></div>
</div>
<p>Pretty simple!&#160; now, lets create our DataGrid that will show our data for editing.</p>
<div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" 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: white; 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: #0000ff">&lt;</span><span style="color: #800000">UserControl</span> <span style="color: #ff0000">x:Class</span><span style="color: #0000ff">=&quot;SilverlightApplication1.MainPage&quot;</span></pre>
<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: #ff0000">xmlns</span><span style="color: #0000ff">=&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;</span> </pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; 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: #ff0000">xmlns:x</span><span style="color: #0000ff">=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;</span></pre>
<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: #ff0000">xmlns:grid</span><span style="color: #0000ff">=&quot;clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data&quot;</span></pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; 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: #ff0000">xmlns:d</span><span style="color: #0000ff">=&quot;http://schemas.microsoft.com/expression/blend/2008&quot;</span> </pre>
<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: #ff0000">xmlns:mc</span><span style="color: #0000ff">=&quot;http://schemas.openxmlformats.org/markup-compatibility/2006&quot;</span> </pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; 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: #ff0000">mc:Ignorable</span><span style="color: #0000ff">=&quot;d&quot;</span> <span style="color: #ff0000">d:DesignWidth</span><span style="color: #0000ff">=&quot;640&quot;</span> <span style="color: #ff0000">d:DesignHeight</span><span style="color: #0000ff">=&quot;480&quot;</span><span style="color: #0000ff">&gt;</span></pre>
<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: #0000ff">&lt;</span><span style="color: #800000">Grid</span> <span style="color: #ff0000">x:Name</span><span style="color: #0000ff">=&quot;LayoutRoot&quot;</span><span style="color: #0000ff">&gt;</span></pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; 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: #0000ff">&lt;</span><span style="color: #800000">grid:DataGrid</span> <span style="color: #ff0000">x:Name</span><span style="color: #0000ff">=&quot;dataGrid&quot;</span><span style="color: #0000ff">/&gt;</span></pre>
<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: #0000ff">&lt;/</span><span style="color: #800000">Grid</span><span style="color: #0000ff">&gt;</span></pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; 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: #0000ff">&lt;/</span><span style="color: #800000">UserControl</span><span style="color: #0000ff">&gt;</span></pre>
</p></div>
</div>
<p>Okay, now I don’t know how many Periods my StaffMember will have until I get the data back from the database at run time.&#160; For demonstration purposes, I just created a method on my StaffMember class that would create my objects by iterating through a loop.</p>
<div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" 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: white; 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: #0000ff">public</span> <span style="color: #0000ff">static</span> List&lt;StaffMember&gt; GetData()</pre>
<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">{</pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; 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">    List&lt;StaffMember&gt; dataList = <span style="color: #0000ff">new</span> List&lt;StaffMember&gt;();</pre>
<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: #0000ff">for</span> (<span style="color: #0000ff">int</span> i = 0; i &lt; 3; i++)</pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; 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">    {</pre>
<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">        StaffMember member = <span style="color: #0000ff">new</span> StaffMember { Name = String.Format(<span style="color: #006080">&quot;Name#{0}&quot;</span>, i), Department = String.Format(<span style="color: #006080">&quot;Department#{0}&quot;</span>, i) };</pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; 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">        ObservableCollection&lt;Period&gt; periods = <span style="color: #0000ff">new</span> ObservableCollection&lt;Period&gt;();</pre>
<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: #0000ff">for</span> (<span style="color: #0000ff">int</span> j = 0; j &lt; 5; j++)</pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; 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">            periods.Add(<span style="color: #0000ff">new</span> Period() { Title = String.Format(<span style="color: #006080">&quot;Period#{0}-{1}&quot;</span>, i, j), Hours = j });</pre>
<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">        member.Periods = periods;</pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; 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">        dataList.Add(member);</pre>
<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">    }</pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; 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: #0000ff">return</span> dataList;</pre>
<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">}</pre>
</p></div>
</div>
<p>Now, we need to set the datasource on the DataGrid.&#160; Since we are creating the columns at runtime make sure you set AutoGenerateColumns to false;</p>
<div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" 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: white; 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">List&lt;StaffMember&gt; dataList = StaffMember.GetData();</pre>
<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">dataGrid.AutoGenerateColumns = <span style="color: #0000ff">false</span>;</pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; 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">dataGrid.ItemsSource = dataList;</pre>
<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">dataGrid.Columns.Clear();</pre>
</p></div>
</div>
<p>Next, lets take care of creating the easy columns first.&#160; I created a method that its’ sole purpose is to give me new DataGridTextColumns.</p>
<div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" 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: white; 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: #0000ff">private</span> <span style="color: #0000ff">static</span> DataGridTextColumn CreateTextColumn(<span style="color: #0000ff">string</span> fieldName, <span style="color: #0000ff">string</span> title)</pre>
<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">{</pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; 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">    DataGridTextColumn column = <span style="color: #0000ff">new</span> DataGridTextColumn();</pre>
<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">    column.Header = title;</pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; 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">    column.Binding = <span style="color: #0000ff">new</span> System.Windows.Data.Binding(fieldName);</pre>
<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: #0000ff">return</span> column;</pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; 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">}</pre>
</p></div>
</div>
<p>Using this method we can create our first two columns.</p>
<div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" 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: white; 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">dataGrid.Columns.Add(CreateTextColumn(<span style="color: #006080">&quot;Name&quot;</span>, <span style="color: #006080">&quot;Staff Name&quot;</span>));</pre>
<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">dataGrid.Columns.Add(CreateTextColumn(<span style="color: #006080">&quot;Department&quot;</span>, <span style="color: #006080">&quot;Company Department&quot;</span>));</pre>
</p></div>
</div>
<p>Your DataGrid should now look something like this.</p>
<p><a href="http://elegantcode.com/wp-content/uploads/2010/03/image9.png" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="text columns added to grid" border="0" alt="text columns added to grid" src="http://elegantcode.com/wp-content/uploads/2010/03/image_thumb9.png" width="244" height="114" /></a> </p>
<p>Now we need to create our columns based off the Periods collection.&#160; To do this we will utilize a DataGridTemplateColumn.&#160; The first thing we need to do is create a method that will dynamically create a DataTemplate that the DataGridTemplateColumn will use as the CellTemplate.</p>
<div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" 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: white; 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: #0000ff">private</span> <span style="color: #0000ff">string</span> CreateColumnTemplate(<span style="color: #0000ff">int</span> index, <span style="color: #0000ff">string</span> propertyName)</pre>
<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">{</pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; 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">    StringBuilder CellTemp = <span style="color: #0000ff">new</span> StringBuilder();</pre>
<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">    CellTemp.Append(<span style="color: #006080">&quot;&lt;DataTemplate &quot;</span>);</pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; 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">    CellTemp.Append(<span style="color: #006080">&quot;xmlns='http://schemas.microsoft.com/winfx/&quot;</span>);</pre>
<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">    CellTemp.Append(<span style="color: #006080">&quot;2006/xaml/presentation' &quot;</span>);</pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; 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">    CellTemp.Append(<span style="color: #006080">&quot;xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'&gt;&quot;</span>);</pre>
<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">    CellTemp.Append(String.Format(<span style="color: #006080">&quot;&lt;TextBlock Text='{{Binding Periods[{0}].{1}}}'/&gt;&quot;</span>, index, propertyName));</pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; 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">    CellTemp.Append(<span style="color: #006080">&quot;&lt;/DataTemplate&gt;&quot;</span>);</pre>
<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: #0000ff">return</span> CellTemp.ToString();</pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; 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">}</pre>
</p></div>
</div>
<p>What I am doing here is using a StringBuilder to create a DataTemplate, represented by XAML.&#160; Pay special attention to the TextBlock’s binding.&#160; I am using String.Format to create my binding string base off the index the of the object in the collection and the name of the property on the child object I want to bind to.&#160; Now, lets create our template that will be used for editing.</p>
<div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" 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: white; 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: #0000ff">private</span> <span style="color: #0000ff">string</span> CreateColumnEditTemplate(<span style="color: #0000ff">int</span> index, <span style="color: #0000ff">string</span> propertyName)</pre>
<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">{</pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; 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">    StringBuilder CellTemp = <span style="color: #0000ff">new</span> StringBuilder();</pre>
<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">    CellTemp.Append(<span style="color: #006080">&quot;&lt;DataTemplate &quot;</span>);</pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; 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">    CellTemp.Append(<span style="color: #006080">&quot;xmlns='http://schemas.microsoft.com/winfx/&quot;</span>);</pre>
<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">    CellTemp.Append(<span style="color: #006080">&quot;2006/xaml/presentation' &quot;</span>);</pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; 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">    CellTemp.Append(<span style="color: #006080">&quot;xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'&gt;&quot;</span>);</pre>
<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">    CellTemp.Append(String.Format(<span style="color: #006080">&quot;&lt;TextBox Text='{{Binding Periods[{0}].{1}, Mode=TwoWay}}'/&gt;&quot;</span>, index, propertyName));</pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; 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">    CellTemp.Append(<span style="color: #006080">&quot;&lt;/DataTemplate&gt;&quot;</span>);</pre>
<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: #0000ff">return</span> CellTemp.ToString();</pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; 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">}</pre>
</p></div>
</div>
<p>This method is very similar to the previous one we wrote, but notice the subtle difference; I am using a TextBox instead of a TextBlock, and the Mode is set to TwoWay.&#160; This will allow us to edit the values in the DataGrid.&#160; Now we need a method that will actually create the TemplateColumns.</p>
<div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" 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: white; 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: #0000ff">private</span> DataGridTemplateColumn CreateTemplateColumn(<span style="color: #0000ff">int</span> i, <span style="color: #0000ff">string</span> propName)</pre>
<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">{</pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; 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">    DataGridTemplateColumn column = <span style="color: #0000ff">new</span> DataGridTemplateColumn();</pre>
<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">    column.Header = String.Format(<span style="color: #006080">&quot;Period#{0}.{1}&quot;</span>, i, propName);</pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; 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">    column.CellTemplate = (DataTemplate)XamlReader.Load(CreateColumnTemplate(i, propName)); <span style="color: #008000">//display template</span></pre>
<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">    column.CellEditingTemplate = (DataTemplate)XamlReader.Load(CreateColumnEditTemplate(i, propName)); <span style="color: #008000">//edit template</span></pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; 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: #0000ff">return</span> column;</pre>
<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">}</pre>
</p></div>
</div>
<p>Notice that we are setting the CellTemplate and CellEditTemplate by using the XamlReader to load our StringBuilder result and cast it as a legitimate DataTemplate the column can use.&#160; Now that we have the method that will create our TemplateColumns, lets go ahead and build our dynamic columns to the n-level.&#160; We do this by looping though the number of columns that need to be created and using our CreateTemplateColumn method to add the new columns to the DataGrid.</p>
<div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" 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: white; 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: #0000ff">int</span> periodCount = dataList[0].Periods.Count;</pre>
<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: #0000ff">for</span> (<span style="color: #0000ff">int</span> i = 0; i &lt; periodCount; i++)</pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; 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">{</pre>
<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">   dataGrid.Columns.Add(CreateTemplateColumn(i, <span style="color: #006080">&quot;Hours&quot;</span>));</pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; 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">}</pre>
</p></div>
</div>
<p>Now of course, in the real world you would not want to use the first index of the child collection to figure out how many columns to build.&#160; I would recommend some kind of definition object that will define what columns and how many columns to build.</p>
<p><a href="http://elegantcode.com/wp-content/uploads/2010/03/image10.png" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="completed DataGrid" border="0" alt="completed DataGrid" src="http://elegantcode.com/wp-content/uploads/2010/03/image_thumb10.png" width="244" height="101" /></a>&#160;</p>
<p>That is it.&#160; You have now successfully satisfied your customer’s addiction to Excel.&#160; Well, at least a little bit.</p>
</p>
<p><a href="http://brianlagunas.com/downloads/source/DynamicColumns.zip" target="_blank">Download Source</a></p>
]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2010/03/08/silverlight-datagrid-populate-dynamic-columns-from-a-child-collection/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Text-To-Speech in Silverlight Using WCF</title>
		<link>http://elegantcode.com/2010/03/07/text-to-speech-in-silverlight-using-wcf/</link>
		<comments>http://elegantcode.com/2010/03/07/text-to-speech-in-silverlight-using-wcf/#comments</comments>
		<pubDate>Sun, 07 Mar 2010 07:05:56 +0000</pubDate>
		<dc:creator>Brian Lagunas</dc:creator>
				<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[text to speech]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2010/03/07/text-to-speech-in-silverlight-using-wcf/</guid>
		<description><![CDATA[Back in February, I wrote a blog post showing you how to, using Silverlight 4 OOB (out of browser) with elevated trust, access system devices; including how to use the SAPI.SpVoice API through the new Silverlight 4 COM Interop feature to implement text to speech. The biggest problem to that approach is that it will [...]]]></description>
			<content:encoded><![CDATA[<p>Back in February, I wrote a <a href="http://elegantcode.com/2010/02/20/silverlight-4-com-interop-and-the-cool-stuff-you-can-do-with-it/" target="_blank">blog post</a> showing you how to, using Silverlight 4 OOB (out of browser) with elevated trust, access system devices; including how to use the <a href="http://msdn.microsoft.com/en-us/library/ms723602(VS.85).aspx" target="_blank">SAPI.SpVoice</a> API through the new Silverlight 4 COM Interop feature to implement text to speech. The biggest problem to that approach is that it will only work on the Windows platform. </p>
<p>So, I started thinking to myself, that the real purpose behind Text-To-Speech isn&#8217;t just the cool factor, but it is accessibility for impaired users.&#160; I have been doing web development for nearly a decade, and I have always been conscious about web users with impairments that may make viewing or navigating my websites more difficult.&#160; Text-To-Speech isn’t very helpful if it will only work in a fully trusted out of browser Silverlight 4 application on a Windows machine. So instead, lets create a Text-To-Speech solution that will work inside the browser, on any browser, on any machine.&#160; And heck, I want this to be in Silverlight 3.</p>
<p>Lets get started by creating a new Silverlight 3 application, and be sure to include a web project as well.</p>
<p><a href="http://elegantcode.com/wp-content/uploads/2010/03/image4.png" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="create new silverlight project" border="0" alt="create new silverlight project" src="http://elegantcode.com/wp-content/uploads/2010/03/image_thumb4.png" width="248" height="222" /></a> </p>
<p>Right click the web project and add a reference to the System.Speech.dll.</p>
<p><a href="http://elegantcode.com/wp-content/uploads/2010/03/image5.png" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="add reference to System.Speech" border="0" alt="add reference to System.Speech" src="http://elegantcode.com/wp-content/uploads/2010/03/image_thumb5.png" width="245" height="248" /></a> </p>
<p>Next, lets right click the web project and click Properties –&gt; Web and set the specific port number to your liking, I set mine to 1914. This will come in handy when we create our WCF service. </p>
<p><a href="http://elegantcode.com/wp-content/uploads/2010/03/image6.png" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="set port number" border="0" alt="set port number" src="http://elegantcode.com/wp-content/uploads/2010/03/image_thumb6.png" width="248" height="101" /></a> </p>
<p>Now we need to create the WCF service that will take our text and send it back as a WAV stream, so go ahead and right click the web project and select “Add New Item”.&#160; From this list add a new WCF service and name is SpeechService.&#160; <strong>Now this is important</strong>; when you have created your WCF service an endpoint is created for you in the Web.config file.&#160; You need to change the binding of the endpoint to <strong>basicHttpBinding</strong>.&#160; Silverlight only works using basicHttpBinding, and will not create the ServiceReferences.ClientConfig file properly if you do not do this.</p>
<p><a href="http://elegantcode.com/wp-content/uploads/2010/03/image7.png" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="change endpoint binding  to basicHttpBinding" border="0" alt="change endpoint binding  to basicHttpBinding" src="http://elegantcode.com/wp-content/uploads/2010/03/image_thumb7.png" width="248" height="50" /></a> </p>
<p>Now, lets add an OperationCOntract to your WCF services interface called Speak that returns a byte[], and takes a string parameter.</p>
<div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" 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: white; 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">[ServiceContract]</pre>
<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: #0000ff">public</span> <span style="color: #0000ff">interface</span> ISpeechService</pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; 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">{</pre>
<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">    [OperationContract]</pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; 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: #0000ff">byte</span>[] Speak(<span style="color: #0000ff">string</span> textToSay);</pre>
<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">}</pre>
</p></div>
</div>
<p>The implementation of this method will look like the following:</p>
<div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" 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: white; 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: #0000ff">public</span> <span style="color: #0000ff">byte</span>[] Speak(<span style="color: #0000ff">string</span> textToSay)</pre>
<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">{</pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; 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">    SpeechSynthesizer ss = <span style="color: #0000ff">new</span> SpeechSynthesizer();</pre>
<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">    MemoryStream ms = <span style="color: #0000ff">new</span> MemoryStream();</pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; 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">    ss.SetOutputToWaveStream(ms);</pre>
<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">    ss.Speak(textToSay);</pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; 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: #0000ff">return</span> ms.ToArray();</pre>
<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">}</pre>
</p></div>
</div>
<p>The next thing we need to do is create our UI in Silverlight.&#160; Here is what mine looks like.</p>
<div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" 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: white; 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: #0000ff">&lt;</span><span style="color: #800000">Grid</span> <span style="color: #ff0000">x:Name</span><span style="color: #0000ff">=&quot;LayoutRoot&quot;</span><span style="color: #0000ff">&gt;</span></pre>
<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: #0000ff">&lt;</span><span style="color: #800000">StackPanel</span><span style="color: #0000ff">&gt;</span></pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; 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: #0000ff">&lt;</span><span style="color: #800000">TextBox</span> <span style="color: #ff0000">x:Name</span><span style="color: #0000ff">=&quot;_txtTextToSay&quot;</span> <span style="color: #0000ff">/&gt;</span></pre>
<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: #0000ff">&lt;</span><span style="color: #800000">Button</span> <span style="color: #ff0000">Content</span><span style="color: #0000ff">=&quot;Speak To Me&quot;</span> <span style="color: #ff0000">Click</span><span style="color: #0000ff">=&quot;Button_Click&quot;</span> <span style="color: #0000ff">/&gt;</span></pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; 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: #0000ff">&lt;</span><span style="color: #800000">MediaElement</span> <span style="color: #ff0000">x:Name</span><span style="color: #0000ff">=&quot;_audioPlayer&quot;</span><span style="color: #0000ff">/&gt;</span></pre>
<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: #0000ff">&lt;/</span><span style="color: #800000">StackPanel</span><span style="color: #0000ff">&gt;</span></pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; 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: #0000ff">&lt;/</span><span style="color: #800000">Grid</span><span style="color: #0000ff">&gt;</span></pre>
</p></div>
</div>
<p>Create an event handler for your button.&#160; Next add a service reference to your SpeechService in your web project.</p>
<p><a href="http://elegantcode.com/wp-content/uploads/2010/03/image8.png" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="add service reference to your speechservice" border="0" alt="add service reference to your speechservice" src="http://elegantcode.com/wp-content/uploads/2010/03/image_thumb8.png" width="248" height="202" /></a> </p>
<p>The next part is somewhat complicated and time consuming.&#160; You have to write your own WAVV decoding class that takes the byte array that is return from the service and converts it to a <a href="http://msdn.microsoft.com/en-us/library/system.windows.media.mediastreamsource(VS.95).aspx" target="_blank">System.Windows.Media.MediaStreamSource</a>. Luckily for you, I already did this for you with the help of some resources on MSDN.&#160; In the button’s event handler add this code:</p>
<div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" 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: white; 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: #0000ff">private</span> <span style="color: #0000ff">void</span> Button_Click(<span style="color: #0000ff">object</span> sender, RoutedEventArgs e)</pre>
<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">{</pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; 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">    SpeechServiceClient client = <span style="color: #0000ff">new</span> SpeechServiceClient(<span style="color: #006080">&quot;BasicHttpBinding_ISpeechService&quot;</span>);</pre>
<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">    client.SpeakCompleted += (o, ea) =&gt;</pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; 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">        {</pre>
<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">            WavMediaStreamSource audioStream = <span style="color: #0000ff">new</span> WavMediaStreamSource(<span style="color: #0000ff">new</span> MemoryStream(ea.Result));</pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; 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">            _audioPlayer.SetSource(audioStream);</pre>
<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">        };</pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; 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">    client.SpeakAsync(_txtTextToSay.Text);</pre>
<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">}</pre>
</p></div>
</div>
<p>Basically what this does is uses the WavMediaStreamSource class I created that inherits from MediaStreamSource, takes the byte[] returned from the SpeechService and converts it back to a stream, then is passes it off to my WAV decoding classes, which is used as the source for the MediaElement responsible for playing the audio.</p>
<p>All that is next is to build your solution and start making your Silverlight applications more accessible.</p>
<p><a href="http://brianlagunas.com/downloads/source/SilverlightTextToSpeech.zip" target="_blank">Download the Source</a></p>
]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2010/03/07/text-to-speech-in-silverlight-using-wcf/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Creating a Custom Silverlight Pre-Loader</title>
		<link>http://elegantcode.com/2010/03/05/creating-a-custom-silverlight-pre-loader/</link>
		<comments>http://elegantcode.com/2010/03/05/creating-a-custom-silverlight-pre-loader/#comments</comments>
		<pubDate>Fri, 05 Mar 2010 23:49:47 +0000</pubDate>
		<dc:creator>Brian Lagunas</dc:creator>
				<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[pre-loader]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2010/03/05/creating-a-custom-silverlight-pre-loader/</guid>
		<description><![CDATA[I have been doing Silverlight development since it was released. One question I get asked a lot is how do to create a custom pre-loader for my application. What do I mean by pre-loader? Well, it can be called many things; it could be called a pre-loader, splash screen, or a loading screen. No matter [...]]]></description>
			<content:encoded><![CDATA[<p>I have been doing Silverlight development since it was released. One question I get asked a lot is how do to create a custom pre-loader for my application. What do I mean by pre-loader? Well, it can be called many things; it could be called a pre-loader, splash screen, or a loading screen. No matter what you want to call it, here is the one you get by default.</p>
<p><a href="http://elegantcode.com/wp-content/uploads/2010/03/image.png" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="default Silverlight pre-loader" border="0" alt="default Silverlight pre-loader" src="http://elegantcode.com/wp-content/uploads/2010/03/image_thumb.png" width="111" height="105" /></a> </p>
<p>I thought creating a custom pre-loader was common knowledge, but I guess I was wrong. So, what is a custom pre-loader really? Well, it is a small and lightweight Silverlight application that runs while your main Silverlight application is being downloaded to the client. Creating your own is really easy and only involves a few basic steps.</p>
<p>The first thing we need to do is add a Silverlight JavaScript&#160; page to the Web project of your Silverlight application. So just right click your Web project and click add new item, then select Silverlight JScript Page.</p>
<p><a href="http://elegantcode.com/wp-content/uploads/2010/03/image1.png" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="add new silverlight jscript page" border="0" alt="add new silverlight jscript page" src="http://elegantcode.com/wp-content/uploads/2010/03/image_thumb1.png" width="244" height="152" /></a> </p>
<p>You can name it whatever you want. I named my SplashScreen.xaml. When you click “Add” you will notice two files were created for you; a XAML file and a JavaScript file.</p>
<p><a href="http://elegantcode.com/wp-content/uploads/2010/03/image2.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://elegantcode.com/wp-content/uploads/2010/03/image_thumb2.png" width="238" height="111" /></a> </p>
<p>The XAML file is where you will create your pre-loader UI. So lets create a simple UI.</p>
<div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper">
<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" id="codeSnippet"><span style="color: #0000ff">&lt;</span><span style="color: #800000">Canvas</span>        <span style="color: #ff0000">xmlns</span><span style="color: #0000ff">=&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;</span>        <span style="color: #ff0000">xmlns:x</span><span style="color: #0000ff">=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;</span>        <span style="color: #ff0000">x:Name</span><span style="color: #0000ff">=&quot;parentCanvas&quot;</span>        <span style="color: #ff0000">Width</span><span style="color: #0000ff">=&quot;850&quot;</span>        <span style="color: #ff0000">Height</span><span style="color: #0000ff">=&quot;600&quot;</span>        <span style="color: #ff0000">Background</span><span style="color: #0000ff">=&quot;OldLace&quot;</span>        <span style="color: #0000ff">&gt;</span>  <span style="color: #0000ff">&lt;</span><span style="color: #800000">Canvas</span> <span style="color: #ff0000">Canvas</span>.<span style="color: #ff0000">Top</span><span style="color: #0000ff">=&quot;228.834&quot;</span> <span style="color: #ff0000">Canvas</span>.<span style="color: #ff0000">Left</span><span style="color: #0000ff">=&quot;246.329&quot;</span> <span style="color: #ff0000">Width</span><span style="color: #0000ff">=&quot;357&quot;</span> <span style="color: #ff0000">Height</span><span style="color: #0000ff">=&quot;31.379&quot;</span><span style="color: #0000ff">&gt;</span>    <span style="color: #0000ff">&lt;</span><span style="color: #800000">Rectangle</span> <span style="color: #ff0000">Width</span><span style="color: #0000ff">=&quot;27.545&quot;</span> <span style="color: #ff0000">Height</span><span style="color: #0000ff">=&quot;1&quot;</span> <span style="color: #ff0000">x:Name</span><span style="color: #0000ff">=&quot;uxProgress&quot;</span> <span style="color: #ff0000">Canvas</span>.<span style="color: #ff0000">Top</span><span style="color: #0000ff">=&quot;29.545&quot;</span> <span style="color: #ff0000">Canvas</span>.<span style="color: #ff0000">Left</span><span style="color: #0000ff">=&quot;1.4&quot;</span><span style="color: #0000ff">&gt;</span>      <span style="color: #0000ff">&lt;</span><span style="color: #800000">Rectangle.RenderTransform</span><span style="color: #0000ff">&gt;</span>        <span style="color: #0000ff">&lt;</span><span style="color: #800000">TransformGroup</span><span style="color: #0000ff">&gt;</span>          <span style="color: #0000ff">&lt;</span><span style="color: #800000">ScaleTransform</span> <span style="color: #ff0000">x:Name</span><span style="color: #0000ff">=&quot;uxProgressBar&quot;</span> <span style="color: #ff0000">ScaleX</span><span style="color: #0000ff">=&quot;1&quot;</span> <span style="color: #ff0000">ScaleY</span><span style="color: #0000ff">=&quot;0&quot;</span><span style="color: #0000ff">/&gt;</span>          <span style="color: #0000ff">&lt;</span><span style="color: #800000">SkewTransform</span> <span style="color: #ff0000">AngleX</span><span style="color: #0000ff">=&quot;0&quot;</span> <span style="color: #ff0000">AngleY</span><span style="color: #0000ff">=&quot;0&quot;</span><span style="color: #0000ff">/&gt;</span>          <span style="color: #0000ff">&lt;</span><span style="color: #800000">RotateTransform</span> <span style="color: #ff0000">Angle</span><span style="color: #0000ff">=&quot;270&quot;</span><span style="color: #0000ff">/&gt;</span>          <span style="color: #0000ff">&lt;</span><span style="color: #800000">TranslateTransform</span> <span style="color: #ff0000">X</span><span style="color: #0000ff">=&quot;0&quot;</span> <span style="color: #ff0000">Y</span><span style="color: #0000ff">=&quot;0&quot;</span><span style="color: #0000ff">/&gt;</span>        <span style="color: #0000ff">&lt;/</span><span style="color: #800000">TransformGroup</span><span style="color: #0000ff">&gt;</span>      <span style="color: #0000ff">&lt;/</span><span style="color: #800000">Rectangle.RenderTransform</span><span style="color: #0000ff">&gt;</span>      <span style="color: #0000ff">&lt;</span><span style="color: #800000">Rectangle.Fill</span><span style="color: #0000ff">&gt;</span>        <span style="color: #0000ff">&lt;</span><span style="color: #800000">LinearGradientBrush</span> <span style="color: #ff0000">EndPoint</span><span style="color: #0000ff">=&quot;1,0.5&quot;</span> <span style="color: #ff0000">StartPoint</span><span style="color: #0000ff">=&quot;0,0.5&quot;</span><span style="color: #0000ff">&gt;</span>          <span style="color: #0000ff">&lt;</span><span style="color: #800000">GradientStop</span> <span style="color: #ff0000">Color</span><span style="color: #0000ff">=&quot;#FFFFFFFF&quot;</span> <span style="color: #ff0000">Offset</span><span style="color: #0000ff">=&quot;1&quot;</span><span style="color: #0000ff">/&gt;</span>          <span style="color: #0000ff">&lt;</span><span style="color: #800000">GradientStop</span> <span style="color: #ff0000">Color</span><span style="color: #0000ff">=&quot;#FFFFFFFF&quot;</span> <span style="color: #ff0000">Offset</span><span style="color: #0000ff">=&quot;0&quot;</span><span style="color: #0000ff">/&gt;</span>          <span style="color: #0000ff">&lt;</span><span style="color: #800000">GradientStop</span> <span style="color: #ff0000">Color</span><span style="color: #0000ff">=&quot;#FF2975D0&quot;</span> <span style="color: #ff0000">Offset</span><span style="color: #0000ff">=&quot;0.28&quot;</span><span style="color: #0000ff">/&gt;</span>          <span style="color: #0000ff">&lt;</span><span style="color: #800000">GradientStop</span> <span style="color: #ff0000">Color</span><span style="color: #0000ff">=&quot;#FF2975D0&quot;</span> <span style="color: #ff0000">Offset</span><span style="color: #0000ff">=&quot;0.72&quot;</span><span style="color: #0000ff">/&gt;</span>        <span style="color: #0000ff">&lt;/</span><span style="color: #800000">LinearGradientBrush</span><span style="color: #0000ff">&gt;</span>      <span style="color: #0000ff">&lt;/</span><span style="color: #800000">Rectangle.Fill</span><span style="color: #0000ff">&gt;</span>    <span style="color: #0000ff">&lt;/</span><span style="color: #800000">Rectangle</span><span style="color: #0000ff">&gt;</span>

    <span style="color: #0000ff">&lt;</span><span style="color: #800000">TextBlock</span> <span style="color: #ff0000">x:Name</span><span style="color: #0000ff">=&quot;uxStatus&quot;</span> <span style="color: #ff0000">Height</span><span style="color: #0000ff">=&quot;25&quot;</span> <span style="color: #ff0000">Canvas</span>.<span style="color: #ff0000">Left</span><span style="color: #0000ff">=&quot;125&quot;</span> <span style="color: #ff0000">Text</span><span style="color: #0000ff">=&quot;Loading...&quot;</span> <span style="color: #ff0000">TextWrapping</span><span style="color: #0000ff">=&quot;Wrap&quot;</span> <span style="color: #ff0000">Canvas</span>.<span style="color: #ff0000">Top</span><span style="color: #0000ff">=&quot;4.16&quot;</span><span style="color: #0000ff">/&gt;</span>

    <span style="color: #0000ff">&lt;</span><span style="color: #800000">Path</span> <span style="color: #ff0000">Width</span><span style="color: #0000ff">=&quot;356.85&quot;</span> <span style="color: #ff0000">Height</span><span style="color: #0000ff">=&quot;1&quot;</span> <span style="color: #ff0000">Fill</span><span style="color: #0000ff">=&quot;#FF3A3A3A&quot;</span> <span style="color: #ff0000">Stretch</span><span style="color: #0000ff">=&quot;Fill&quot;</span> <span style="color: #ff0000">Stroke</span><span style="color: #0000ff">=&quot;#FF000000&quot;</span> <span style="color: #ff0000">Canvas</span>.<span style="color: #ff0000">Top</span><span style="color: #0000ff">=&quot;0&quot;</span> <span style="color: #ff0000">Data</span><span style="color: #0000ff">=&quot;M0,170.5 L356.84209,170.5&quot;</span> <span style="color: #ff0000">Opacity</span><span style="color: #0000ff">=&quot;0.35&quot;</span><span style="color: #0000ff">/&gt;</span>    <span style="color: #0000ff">&lt;</span><span style="color: #800000">Path</span> <span style="color: #ff0000">Width</span><span style="color: #0000ff">=&quot;1.662&quot;</span> <span style="color: #ff0000">Height</span><span style="color: #0000ff">=&quot;29.03&quot;</span> <span style="color: #ff0000">Fill</span><span style="color: #0000ff">=&quot;#FF3A3A3A&quot;</span> <span style="color: #ff0000">Stretch</span><span style="color: #0000ff">=&quot;Fill&quot;</span> <span style="color: #ff0000">Stroke</span><span style="color: #0000ff">=&quot;#FF000000&quot;</span> <span style="color: #ff0000">Canvas</span>.<span style="color: #ff0000">Top</span><span style="color: #0000ff">=&quot;0.48&quot;</span> <span style="color: #ff0000">Canvas</span>.<span style="color: #ff0000">Left</span><span style="color: #0000ff">=&quot;0.2&quot;</span> <span style="color: #ff0000">Data</span><span style="color: #0000ff">=&quot;M360,168 L360,0&quot;</span> <span style="color: #ff0000">Opacity</span><span style="color: #0000ff">=&quot;0.35&quot;</span> <span style="color: #0000ff">/&gt;</span>

    <span style="color: #0000ff">&lt;</span><span style="color: #800000">Path</span> <span style="color: #ff0000">Width</span><span style="color: #0000ff">=&quot;357.84&quot;</span> <span style="color: #ff0000">Height</span><span style="color: #0000ff">=&quot;1&quot;</span> <span style="color: #ff0000">Fill</span><span style="color: #0000ff">=&quot;#FF3A3A3A&quot;</span> <span style="color: #ff0000">Stretch</span><span style="color: #0000ff">=&quot;Fill&quot;</span> <span style="color: #ff0000">Stroke</span><span style="color: #0000ff">=&quot;#FF000000&quot;</span> <span style="color: #ff0000">Canvas</span>.<span style="color: #ff0000">Top</span><span style="color: #0000ff">=&quot;29&quot;</span> <span style="color: #ff0000">Data</span><span style="color: #0000ff">=&quot;M0,170.5 L356.84209,170.5&quot;</span> <span style="color: #ff0000">Opacity</span><span style="color: #0000ff">=&quot;0.35&quot;</span><span style="color: #0000ff">/&gt;</span>    <span style="color: #0000ff">&lt;</span><span style="color: #800000">Path</span> <span style="color: #ff0000">Width</span><span style="color: #0000ff">=&quot;358.85&quot;</span> <span style="color: #ff0000">Height</span><span style="color: #0000ff">=&quot;1&quot;</span> <span style="color: #ff0000">Fill</span><span style="color: #0000ff">=&quot;#FFA2A2A2&quot;</span> <span style="color: #ff0000">Stretch</span><span style="color: #0000ff">=&quot;Fill&quot;</span> <span style="color: #ff0000">Stroke</span><span style="color: #0000ff">=&quot;#FF000000&quot;</span> <span style="color: #ff0000">Canvas</span>.<span style="color: #ff0000">Top</span><span style="color: #0000ff">=&quot;30&quot;</span> <span style="color: #ff0000">Data</span><span style="color: #0000ff">=&quot;M0,170.5 L356.84209,170.5&quot;</span> <span style="color: #ff0000">Opacity</span><span style="color: #0000ff">=&quot;0.25&quot;</span><span style="color: #0000ff">/&gt;</span>    <span style="color: #0000ff">&lt;</span><span style="color: #800000">Path</span> <span style="color: #ff0000">Width</span><span style="color: #0000ff">=&quot;1.662&quot;</span> <span style="color: #ff0000">Height</span><span style="color: #0000ff">=&quot;30&quot;</span> <span style="color: #ff0000">Fill</span><span style="color: #0000ff">=&quot;#FF3A3A3A&quot;</span> <span style="color: #ff0000">Stretch</span><span style="color: #0000ff">=&quot;Fill&quot;</span> <span style="color: #ff0000">Stroke</span><span style="color: #0000ff">=&quot;#FF000000&quot;</span> <span style="color: #ff0000">Canvas</span>.<span style="color: #ff0000">Left</span><span style="color: #0000ff">=&quot;356.01&quot;</span> <span style="color: #ff0000">Data</span><span style="color: #0000ff">=&quot;M360,168 L360,0&quot;</span> <span style="color: #ff0000">Opacity</span><span style="color: #0000ff">=&quot;0.35&quot;</span> <span style="color: #ff0000">Canvas</span>.<span style="color: #ff0000">Top</span><span style="color: #0000ff">=&quot;-0.498&quot;</span><span style="color: #0000ff">/&gt;</span>    <span style="color: #0000ff">&lt;</span><span style="color: #800000">Path</span> <span style="color: #ff0000">Width</span><span style="color: #0000ff">=&quot;1&quot;</span> <span style="color: #ff0000">Height</span><span style="color: #0000ff">=&quot;31&quot;</span> <span style="color: #ff0000">Fill</span><span style="color: #0000ff">=&quot;#FFA2A2A2&quot;</span> <span style="color: #ff0000">Stretch</span><span style="color: #0000ff">=&quot;Fill&quot;</span> <span style="color: #ff0000">Stroke</span><span style="color: #0000ff">=&quot;#FF000000&quot;</span> <span style="color: #ff0000">Canvas</span>.<span style="color: #ff0000">Left</span><span style="color: #0000ff">=&quot;357.333&quot;</span> <span style="color: #ff0000">Data</span><span style="color: #0000ff">=&quot;M360,168 L360,0&quot;</span> <span style="color: #ff0000">Opacity</span><span style="color: #0000ff">=&quot;0.245&quot;</span> <span style="color: #ff0000">Canvas</span>.<span style="color: #ff0000">Top</span><span style="color: #0000ff">=&quot;-0.498&quot;</span> <span style="color: #0000ff">/&gt;</span>  <span style="color: #0000ff">&lt;/</span><span style="color: #800000">Canvas</span><span style="color: #0000ff">&gt;</span><span style="color: #0000ff">&lt;/</span><span style="color: #800000">Canvas</span><span style="color: #0000ff">&gt;</span></pre>
<p></div>
<p>I actually copied this XAML from MSDN because I was to lazy to write my own.</p>
<p>The JavaScript file is where you will interact with you pre-loader.&#160; To do this there are three properties that are exposed by the Silverlight plug-in:</p>
<ol>
<li>splashscreensource: The URI of a XAML page that displays while the primary package (source) is being downloaded. </li>
<li>onsourcedownloadprogresschanged: References a JavaScript event handler that will be invoked continuously while the source is being downloaded. </li>
<li>onsourcedownloadcomplete: References a JavaScript event handler that will be invoked once, when the source download is complete. </li>
</ol>
<p>Enter Params:</p>
<p>You will need to add two Object Params to your page hosting the Silverlight application.</p>
<div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper">
<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" id="codeSnippet"><span style="color: #0000ff">&lt;</span><span style="color: #800000">param</span> <span style="color: #ff0000">name</span><span style="color: #0000ff">=&quot;splashscreensource&quot;</span> <span style="color: #ff0000">value</span><span style="color: #0000ff">=&quot;SplashScreen.xaml&quot;</span><span style="color: #0000ff">/&gt;</span><span style="color: #0000ff">&lt;</span><span style="color: #800000">param</span> <span style="color: #ff0000">name</span><span style="color: #0000ff">=&quot;onSourceDownloadProgressChanged&quot;</span> <span style="color: #ff0000">value</span><span style="color: #0000ff">=&quot;onSourceDownloadProgressChanged&quot;</span> <span style="color: #0000ff">/&gt;</span></pre>
<p></div>
<p>The first one tells the host where to find the custom XAML file you created. The second one tells it which JavaScript function to execute when the sourceDownloadProgressChanged event fires.</p>
<p>So go ahead and open up your JavaScript file and delete all the code that is in there and replace it with this:</p>
<div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper">
<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" id="codeSnippet"><span style="color: #0000ff">function</span> onSourceDownloadProgressChanged(sender, eventArgs) {    sender.findName(<span style="color: #006080">&quot;uxStatus&quot;</span>).Text = <span style="color: #006080">&quot;Loading: &quot;</span> + Math.round((eventArgs.progress * 1000)) / 10 + <span style="color: #006080">&quot;%&quot;</span>;    sender.findName(<span style="color: #006080">&quot;uxProgressBar&quot;</span>).ScaleY = eventArgs.progress * 356;}</pre>
<p></div>
<p>The next step is very important. Make sure you add your JavaScript file into the head tag of your hosting page.</p>
<div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper">
<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" id="codeSnippet"><span style="color: #0000ff">&lt;</span><span style="color: #800000">script</span> <span style="color: #ff0000">type</span><span style="color: #0000ff">=&quot;text/javascript&quot;</span> <span style="color: #ff0000">src</span><span style="color: #0000ff">=&quot;splashscreen.js&quot;</span><span style="color: #0000ff">&gt;&lt;/</span><span style="color: #800000">script</span><span style="color: #0000ff">&gt;</span></pre>
<p></div>
<p>Now in order to test this thing, you need to add something very big to your main Silverlight application, set its Build Action to Content, and set Copy to Output Directory to Copy if newer.&#160; I added a video file that was about 100MB in size. Now run your application.</p>
<p><a href="http://elegantcode.com/wp-content/uploads/2010/03/image3.png" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="custom pre-loader" border="0" alt="custom pre-loader" src="http://elegantcode.com/wp-content/uploads/2010/03/image_thumb3.png" width="244" height="56" /></a> </p>
<p>And there is our custom pre-loader. </p>
<p>For more information on creating custom pre-loaders visit <a title="http://msdn.microsoft.com/en-us/library/cc838130(VS.95).aspx" href="http://msdn.microsoft.com/en-us/library/cc838130(VS.95).aspx">http://msdn.microsoft.com/en-us/library/cc838130(VS.95).aspx</a></p>
<p><a href="http://www.brianlagunas.com/downloads/source/CustomSplashScreen.zip" target="_blank">Download the Source</a></p>
]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2010/03/05/creating-a-custom-silverlight-pre-loader/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Introducing oEmbed</title>
		<link>http://elegantcode.com/2010/03/05/introducing-oembed/</link>
		<comments>http://elegantcode.com/2010/03/05/introducing-oembed/#comments</comments>
		<pubDate>Fri, 05 Mar 2010 06:12:08 +0000</pubDate>
		<dc:creator>cory.isakson</dc:creator>
				<category><![CDATA[WebServices]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[web]]></category>
		<category><![CDATA[oembed]]></category>

		<guid isPermaLink="false">http://elegantcode.com/?p=3325</guid>
		<description><![CDATA[Gadgets, widgets, flash, ActiveX, Silverlight, json, xml
With all of the competing technologies for content embedding and resource sharing on the web it can be difficult to determine which options to use.  Have you ever wished that you could embed YouTube videos and Flickr photos into your site just by knowing the consumer friendly URLi’s to [...]]]></description>
			<content:encoded><![CDATA[<p>Gadgets, widgets, flash, ActiveX, Silverlight, json, xml</p>
<p>With all of the competing technologies for content embedding and resource sharing on the web it can be difficult to determine which options to use.  Have you ever wished that you could embed YouTube videos and Flickr photos into your site just by knowing the consumer friendly URLi’s to them?  That is exactly what <a href="http://oembed.com">oEmbed</a> provides.  I would like to introduce you to the basics of the specification.  I hope the simplicity encourages you to support it as a provider and as a consumer when embedding resources from other providers.  Many popular sites already support it!</p>
<blockquote><p>oEmbed is a format for allowing an embedded representation of a URL on third party sites. The simple API allows a website to display embedded content (such as photos or videos) when a user posts a link to that resource, without having to parse the resource directly.</p></blockquote>
<p>Lets take a look at each side of a provider and consumer scenario to illustrate how oEmbed provides and elegant solution for each.</p>
<blockquote><p>Providers must specify one or more URL scheme and API endpoint pairs. The URL scheme describes which URLs provided by the service may have an embedded representation.</p></blockquote>
<p>The publisher must determine what scheme(s) they support in very basic format.  Typically the scheme matches URLs that consumers would browse resources at normally.  The YouTube API, for example, supports URLs matching the scheme <a href="http://*.youtube.com/watch">http://*.youtube.com/watch</a>*</p>
<p>The API endpoint is simply an http URL at which consumers request oEmbed representations of the resources you provide.  Most of the current providers offer API endpoints with obvious URL’s like <a title="http://www.youtube.com/oembed" href="http://www.youtube.com/oembed">http://www.youtube.com/oembed</a> and <a title="http://www.flickr.com/services/oembed/" href="http://www.flickr.com/services/oembed/">http://www.flickr.com/services/oembed/</a>.</p>
<p>Once you have the endpoint you just need to host a service there that accepts 4 specific query parameters:</p>
<p>url : The urlencoded url that matches a supported provider defined scheme.<br />
maxwidth : (optional) The maximum width you want for embedding the resource.<br />
maxheight : (optional) The maximum height you want for embedding the resource.<br />
format: (optional) xml or json are the possible values that determine the consumers desired response Content-Type.</p>
<blockquote><p>Requests sent to the API endpoint must be HTTP GET requests, with all arguments sent as query parameters. All arguments must be urlencoded (as per RFC 1738).</p></blockquote>
<p>oEmbed consumers make requests for the oEmbed representation of a resource by sending a basic GET request to an API endpoint with url query parameters and any optional parameters they choose.</p>
<p>A request to <a title="http://www.youtube.com/oembed?url=http%3A//www.youtube.com/watch?v%3D6lbDyXu7gUQ" href="http://www.youtube.com/oembed?url=http%3A//www.youtube.com/watch?v%3D6lbDyXu7gUQ">http://www.youtube.com/oembed?url=http%3A//www.youtube.com/watch?v%3D6lbDyXu7gUQ</a> results in a json response:</p>
<pre>{
"provider_url": "http://www.youtube.com/",
"title": "Insert a YouTube Video With oEmbed Wordpress 2.9",
"html": "&lt;object width=\"480\" height=\"295\"&gt;
    &lt;param name=\"movie\" value=\"http://www.youtube.com/v/6lbDyXu7gUQ&amp;fs=1\"&gt;&lt;/param&gt;
    &lt;param name=\"allowFullScreen\" value=\"true\"&gt;&lt;/param&gt;
    &lt;param name=\"allowscriptaccess\" value=\"always\"&gt;&lt;/param&gt;
    &lt;embed src=\"http://www.youtube.com/v/6lbDyXu7gUQ&amp;fs=1\" type=\"application/x-shockwave-flash\"
        width=\"480\" height=\"295\" allowscriptaccess=\"always\" allowfullscreen=\"true\"&gt;&lt;/embed&gt;&lt;/object&gt;",
"author_name": "adriarichards", "height": 295, "width": 480, "version": "1.0",
"author_url": "http://www.youtube.com/user/adriarichards",
"provider_name": "YouTube",
"type": "video"
}</pre>
<p>Note the html property.  It contains everything you need to embed the video.  If this installation of WordPress was running version 2.9 I could paste a YouTube URL here and it would automatically get embeded as described in the video <a href="http://www.youtube.com/watch?v=6lbDyXu7gUQ">Insert a YouTube Video With oEmbed Wordpress 2.9</a></p>
<p>oEmbed supports 4 result types including video, photo, link and rich.  The rich type allows for just about any html to be returned and thus embedded.</p>
<blockquote><p>Consumers may wish to load the HTML in an off-domain iframe to avoid XSS vulnerabilities.</p></blockquote>
<p>To learn more and see a list of some current providers check it out at:</p>
<p><a title="http://oembed.com/" href="http://oembed.com/">http://oembed.com/</a></p>
<p>And for a few more implementations check out <a title="http://oohembed.com/" href="http://oohembed.com/">http://oohembed.com/</a></p>
<p>I look forward to hearing how you end up using oEmbed!</p>
]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2010/03/05/introducing-oembed/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Soft Skills are Actual Skills</title>
		<link>http://elegantcode.com/2010/03/04/soft-skills-are-actual-skills/</link>
		<comments>http://elegantcode.com/2010/03/04/soft-skills-are-actual-skills/#comments</comments>
		<pubDate>Thu, 04 Mar 2010 15:12:50 +0000</pubDate>
		<dc:creator>David Starr</dc:creator>
				<category><![CDATA[Books]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2010/03/04/soft-skills-are-actual-skills/</guid>
		<description><![CDATA[Adam
I will never forget my first day at my first programming job. I was excited, eager, and happy to be there, feeling like I had finally made the big time. I thought, “I am going to get to be a real software developer,” and I was stoked beyond belief. 
In the elevator on the way [...]]]></description>
			<content:encoded><![CDATA[<h2>Adam</h2>
<p>I will never forget my first day at my first programming job. I was excited, eager, and happy to be there, feeling like I had finally made the big time. I thought, “I am going to get to be a real software developer,” and I was stoked beyond belief. </p>
<p>In the elevator on the way up to meet my new boss, I stood with an older, grizzled and tired looking man. I was chatty and excited, and tried to strike up a conversation. I told him it was my first day.</p>
<p>“F%@! you, new guy,” he said as the elevator doors opened and he strode off into the hallway. I was stunned. I stood there dumfounded long enough that the elevator doors began to close before I remembered to walk out.</p>
<p>Over time, I got to know Mr. Elevator. His real name was Adam and like so many people that we tend to make excuses for, I can tell you that Adam <em>wasn’t so bad once you get to know him</em>. In fact, after some time, Adam became something of a mentor to me technically and I worked alongside him learning a lot as I did so.</p>
<h2>Professionalism Isn’t Just in Your Code</h2>
<p>My introduction into the world of work and many subsequent experiences all conspired to teach me that acting like an a-hole was absolutely accepted in the subculture of software development. I struggled for years in other organizations when I carried those behaviors to other employers.</p>
<p>Over time, I learned not only is this ridiculous, but that this institutional acceptance of unprofessionalism has contributed significantly to the negative perception many people have of our profession. Tolerance of behavior like Adam’s is pervasive in our industry and is often dismissed as “Oh, those pesky developers”.</p>
<p>You want to turn IT from a cost to a value center in your organization? This is where you start. I learned a lot of terrible behaviors from Adam and it took years to replace them with new ones. The good news is that it can be done and the way to do so isn’t a big mystery.</p>
<h2>It’s Like Learning a New DSL</h2>
<p>I struggled for a long time before learning that soft skills are, in fact, skills. That means they can be taught, learned, dissected, studied, practiced, and honed. This was great news for me because unlike so many nuero-typicals I know, providing good feedback (as an example) doesn’t come naturally to me. People who share my tendencies toward autistic spectrum disorders often think that soft skills are a magical talent some people are born with. BTW: If you are reading this blog you have a good statistical chance of having at least mild Asperger’s Syndrome (it’s a super power).</p>
<p>Learning soft skills is like learning anything quantitative. For instance, you know how user stories have a little pattern? There are patterns to effective communication, too.</p>
<p><strong>An Effective Feedback Pattern</strong></p>
<ol>
<li>May I give you some feedback? </li>
<li>Here is something you do well. </li>
<li>Here is an example of a behavior that could be improved. </li>
<li>Here is the negative effect of the behavior. </li>
<li>Express confidence in the person’s ability to improve. </li>
<li>What are your thoughts about this? </li>
</ol>
<p><strong>Example</strong></p>
<p>Hey, Dave, may I give you some feedback?</p>
<p>Uh, sure.</p>
<p>You have some great development skills. Your OO skills are particularly good and it would be great if you could provide some design leadership to the team in helping them improve.</p>
<p>Being consistently late to the daily standup is hurting your effectiveness. When you are repeatedly late, it causes resentment in the team toward you. Ultimately, this undermines your own effectiveness as a leader.</p>
<p>I know you can do well at this if you choose to, but its up to you. What do you think about this?</p>
<p><strong>It Actually Works</strong></p>
<p>You may think this example is contrived and over-simplified. It isn’t. I have had this conversation and it really works. Books on the subject provide all kinds of reasons the formula works, but the bottom line is that there are patterns of human behavior and communication just like there are patterns of effective software development.</p>
<h2>Now What?</h2>
<p>If you care about any of this (and you likely wouldn’t have read this far if you didn’t) I think the best place to start is to do some reading about communication techniques. The cool part of this is that as you learn new techniques, you get chances to try them out on a daily basis, and not just at work. The world is a huge discovery spike for this kind of thing.</p>
<p>Here are some books I have found helpful.</p>
<ul>
<li><a href="http://www.amazon.com/Emotional-Intelligence-10th-Anniversary-Matter/dp/055380491X/ref=sr_1_1?ie=UTF8&amp;s=books&amp;qid=1267715268&amp;sr=8-1">Emotional Intelligence</a> </li>
<li><a href="http://www.amazon.com/Crucial-Conversations-Tools-Talking-Stakes/dp/0071401946/ref=sr_1_1?ie=UTF8&amp;s=books&amp;qid=1267715330&amp;sr=1-1">Crucial Conversations</a> </li>
<li><a href="http://www.amazon.com/Art-Science-Negotiation-Howard-Raiffa/dp/067404813X/ref=sr_1_2?ie=UTF8&amp;s=books&amp;qid=1267715360&amp;sr=1-2">The Art and Science of Negotiation</a> </li>
<li><a href="http://www.amazon.com/Practices-Agile-Developer-Pragmatic-Programmers/dp/097451408X/ref=sr_1_1?ie=UTF8&amp;s=books&amp;qid=1267715426&amp;sr=1-1">Practices of an Agile Developer</a> </li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2010/03/04/soft-skills-are-actual-skills/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>Is MSpec an Internal DSL?&#8230;And is that okay?</title>
		<link>http://elegantcode.com/2010/03/03/is-mspec-an-internal-dsland-is-that-okay/</link>
		<comments>http://elegantcode.com/2010/03/03/is-mspec-an-internal-dsland-is-that-okay/#comments</comments>
		<pubDate>Wed, 03 Mar 2010 20:27:07 +0000</pubDate>
		<dc:creator>Richard Cirerol</dc:creator>
				<category><![CDATA[Esoterica]]></category>
		<category><![CDATA[Internal DSL]]></category>
		<category><![CDATA[MSpec]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2010/03/03/is-mspec-an-internal-dsland-is-that-okay/</guid>
		<description><![CDATA[In my last post on MSpec, John Sonmez commented:
When I see the MSpec code, I think about it being an internal DSL for doing the testing, and I start to think that perhaps it should just go ahead and be it’s own language instead of trying to live inside of C#. On the other hand, [...]]]></description>
			<content:encoded><![CDATA[<p>In my <a href="http://codeprogression.blogspot.com/2010/03/evolution-of-test-specification-styles.html">last post</a> on MSpec, <a href="http://elegantcode.com/2010/03/01/an-evolution-of-test-specification-styles-my-journey-to-mspec/#comment-54161">John Sonmez commented</a>:</p>
<blockquote><p>When I see the MSpec code, I think about it being an internal DSL for doing the testing, and I start to think that perhaps it should just go ahead and be it’s own language instead of trying to live inside of C#. On the other hand, I wonder about the value of using another language to unit test C# code…</p></blockquote>
<p>I think John was spot-on with his instinct – in my opinion, MSpec is an internal DSL.  I also think that is the beauty of the framework.  Domain-specific languages are meant to solve a target problem in a particular domain.  MSpec’s problem domain is testing .NET code.  By convention, it constrains you to its limited language to help you test your code in a meaningful yet powerful manner.</p>
<h4>What is an Internal DSL?</h4>
<p>According to Martin Fowler:</p>
<blockquote><p>“Internal DSLs are particular ways of using a host language to give the host language the feel of a particular language&#8230;Internal DSLs are also referred to as embedded DSLs or FluentInterfaces”  (from Bliki article: <a href="http://www.martinfowler.com/bliki/DomainSpecificLanguage.html" target="_blank">Domain Specific Language</a>)</p>
<p>“Internal DSLs use the same general purpose programming language that the wider application uses, but uses that language in a particular and limited style.”<br />
(from DSL-WIP section: <a href="http://martinfowler.com/dslwip/UsingDsls.html#DefiningDomainSpecificLanguages" target="_blank">Using Domain Specific Languages</a>)</p></blockquote>
<p><strong>But, as John wondered, <em>is there value in using another language (external DSL) to test C# code?</em> </strong></p>
<p>Perhaps.  Yet, I believe there is more value in using external DSLs to test user interfaces (e.g., <a href="http://watir.com/" target="_blank">WatiR</a>, <a href="http://watin.sourceforge.net/" target="_blank">WatiN</a>, and <a href="http://seleniumhq.org/" target="_blank">Selenium</a>), or for build scripting (e.g.,<a href="http://rake.rubyforge.org/" target="_blank">Rake</a>, <a href="http://code.google.com/p/psake/" target="_blank">psake</a>).</p>
<p><strong>Let’s look at that question a little differently:<em> Is there value in using an internal DSL (like MSpec) to test C# code?</em></strong></p>
<p>To that I give a resounding YES! MSpec’s host language is C#…which provides great value to me.  I get all the benefits of intellisense, refactoring, and (R#) navigation in my IDE.  I don’t have to worry about the impedance mismatch between my code and an external DSL.</p>
<h4>You Probably Use DSLs All the Time</h4>
<p>In fact, I use several DSLs every day when I code.</p>
<p>Consider the following table of frameworks. You may not have thought any of these in the context of a domain-specific language, but each has a specific purpose with its own limited language constructs. Some are internal, some external.</p>
<table border="1" cellspacing="0" cellpadding="2" width="541">
<tbody>
<tr>
<td width="128" valign="top"><strong>DSL</strong></td>
<td width="90" valign="top"><strong>Type</strong></td>
<td width="124" valign="top"><strong>Host Language</strong></td>
<td width="197" valign="top"><strong>Problem Domain</strong></td>
</tr>
<tr>
<td width="133" valign="top"><a href="http://structuremap.sourceforge.net/" target="_blank">StructureMap</a></td>
<td width="97" valign="top">Internal</td>
<td width="124" valign="top">C#</td>
<td width="193" valign="top">Dependency injection<br />
Inversion of control</td>
</tr>
<tr>
<td width="135" valign="top"><a href="http://www.codeplex.com/AutoMapper" target="_blank">AutoMapper</a></td>
<td width="100" valign="top">Internal</td>
<td width="123" valign="top">C#</td>
<td width="192" valign="top">Object-to-object mapping</td>
</tr>
<tr>
<td width="135" valign="top"><a href="http://www.ayende.com/projects/rhino-mocks.aspx" target="_blank">RhinoMocks</a></td>
<td width="102" valign="top">Internal</td>
<td width="123" valign="top">C#</td>
<td width="191" valign="top">Proxy object interaction and verification</td>
</tr>
<tr>
<td width="135" valign="top"><a href="http://code.google.com/p/moq/" target="_blank">Moq</a></td>
<td width="103" valign="top">Internal</td>
<td width="123" valign="top">C#</td>
<td width="191" valign="top">Proxy object interaction and verification</td>
</tr>
<tr>
<td width="135" valign="top"><a href="http://jquery.com/" target="_blank">jQuery</a></td>
<td width="103" valign="top">Internal</td>
<td width="123" valign="top">JavaScript</td>
<td width="191" valign="top">Document traversal<br />
Event handling<br />
Animation</td>
</tr>
<tr>
<td width="135" valign="top"><a href="http://www.w3.org/Style/CSS/" target="_blank">Cascading Style Sheets</a></td>
<td width="103" valign="top">External</td>
<td width="123" valign="top">English</td>
<td width="191" valign="top">Presentation semantics</td>
</tr>
<tr>
<td width="135" valign="top"><a href="http://rake.rubyforge.org/" target="_blank">Rake</a></td>
<td width="103" valign="top">External</td>
<td width="123" valign="top">Ruby</td>
<td width="191" valign="top">Build/task automation</td>
</tr>
<tr>
<td width="135" valign="top"><a href="http://code.google.com/p/psake/" target="_blank">psake</a></td>
<td width="103" valign="top">External</td>
<td width="123" valign="top">PowerShell</td>
<td width="191" valign="top">Build/task automation</td>
</tr>
<tr>
<td width="135" valign="top"><a href="http://nant.sourceforge.net/" target="_blank">nAnt</a></td>
<td width="103" valign="top">External</td>
<td width="123" valign="top">XML</td>
<td width="191" valign="top">Build/task automation</td>
</tr>
<tr>
<td width="135" valign="top"><a href="http://en.wikipedia.org/wiki/SQL" target="_blank">SQL</a></td>
<td width="103" valign="top">External</td>
<td width="123" valign="top">English</td>
<td width="191" valign="top">Data management</td>
</tr>
<tr>
<td width="135" valign="top"><a href="http://cukes.info/" target="_blank">Cucumber</a></td>
<td width="103" valign="top">External</td>
<td width="123" valign="top">Gherkin</td>
<td width="191" valign="top">Behavior-driven development</td>
</tr>
</tbody>
</table>
<p>When considering a framework within your host language: If the framework has a fluent interface with language devoted to a specific problem domain, it is probably an internal DSL.</p>
<p>So is MSpec an internal DSL? Yes.</p>
<p>And is that okay? Definitely.</p>
<h4>Further Reading</h4>
<p>Check out Martin Fowler’s articles on domain-specific languages:</p>
<p><a href="http://www.martinfowler.com/bliki/DomainSpecificLanguage.html">http://www.martinfowler.com/bliki/DomainSpecificLanguage.html</a><br />
<a href="http://martinfowler.com/dslwip/UsingDsls.html">http://martinfowler.com/dslwip/UsingDsls.html</a><br />
<a href="http://martinfowler.com/dslwip/InternalOverview.html">http://martinfowler.com/dslwip/InternalOverview.html</a></p>
<p><script type="text/javascript">// <![CDATA[
  var cirerolGaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www."); document.write(unescape("%3Cscript src='" + cirerolGaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
// ]]&gt;</script><script type="text/javascript">// <![CDATA[
  var cirerolPageTracker = _gat._getTracker('UA-8257866-3'); cirerolPageTracker._initData(); cirerolPageTracker._trackPageview();
// ]]&gt;</script></p>
]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2010/03/03/is-mspec-an-internal-dsland-is-that-okay/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>JQuery Validator Cheat Sheet</title>
		<link>http://elegantcode.com/2010/03/02/jquery-validator-cheat-sheet/</link>
		<comments>http://elegantcode.com/2010/03/02/jquery-validator-cheat-sheet/#comments</comments>
		<pubDate>Tue, 02 Mar 2010 21:56:18 +0000</pubDate>
		<dc:creator>Chris Brandsma</dc:creator>
				<category><![CDATA[JQuery]]></category>

		<guid isPermaLink="false">http://elegantcode.com/?p=3313</guid>
		<description><![CDATA[I’m getting a session ready for Boise Code Camp 2010 on JQuery Validator.  I thought it would be cool to hand out a cheat sheet – but I couldn’t find one.  So here is rev. 1 of my Jquery Validator Cheat sheet.
]]></description>
			<content:encoded><![CDATA[<p>I’m getting a session ready for <a href="http://BoiseCodeCamp.com">Boise Code Camp 2010</a> on <a href="http://docs.jquery.com/Plugins/Validation">JQuery Validator</a>.  I thought it would be cool to hand out a cheat sheet – but I couldn’t find one.  So here is rev. 1 of my <a href="http://elegantcode.com/wp-content/uploads/2010/03/Jquery-Validator-Cheat-sheet.pdf">Jquery Validator Cheat sheet</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2010/03/02/jquery-validator-cheat-sheet/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
