<?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 &#187; Silverlight</title>
	<atom:link href="http://elegantcode.com/tag/silverlight/feed/" rel="self" type="application/rss+xml" />
	<link>http://elegantcode.com</link>
	<description></description>
	<lastBuildDate>Sun, 12 Feb 2012 04:40:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.5</generator>
		<item>
		<title>Free Pluralsight Prism Training</title>
		<link>http://elegantcode.com/2011/11/04/free-prism-training/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=free-prism-training</link>
		<comments>http://elegantcode.com/2011/11/04/free-prism-training/#comments</comments>
		<pubDate>Sat, 05 Nov 2011 04:23:40 +0000</pubDate>
		<dc:creator>Brian Lagunas</dc:creator>
				<category><![CDATA[.Net 4.0]]></category>
		<category><![CDATA[Prism]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[p&p]]></category>
		<category><![CDATA[prism]]></category>
		<category><![CDATA[training]]></category>
		<category><![CDATA[windows phone 7]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2011/11/04/free-prism-training/</guid>
		<description><![CDATA[I am excited to announce that Pluralsight and Microsoft’s Patterns &#38; Practices team have joined forces to provide you with free access to over 4 hours of online Prism training.&#160; That’s right, you heard me correctly. FREE online Prism training sponsored by the one and only Patterns &#38; Practices team.&#160; I know you have some [...]]]></description>
			<content:encoded><![CDATA[<p>I am excited to announce that <a href="http://www.pluralsight-training.net/microsoft/" target="_blank">Pluralsight</a> and <a href="http://msdn.microsoft.com/en-us/practices/bb190332" target="_blank">Microsoft’s Patterns &amp; Practices</a> team have joined forces to provide you with free access to over 4 hours of online Prism training.&#160; That’s right, you heard me correctly. FREE online Prism training sponsored by the one and only Patterns &amp; Practices team.&#160; I know you have some question so let me answer the most common:</p>
<h4>Q &amp; A</h4>
<p><strong>Q1. When is this free training available?</strong>     <br />A1. The entire weekend of Nov 12th 2011 through Nov 14th 2011.</p>
<p><strong>Q2. Do I have to be a Pluralsight subscriber to get this awesome training?</strong>     <br />A2. This training will be freely available to everyone. You do not have to be a subscriber.</p>
<p><strong>Q3. What does the course cover?</strong>     <br />A3. Well let’s take a look:</p>
<ul>
<li>Getting started with Prism </li>
<li>Bootstrapper and Shell </li>
<li>Regions </li>
<li>Modules </li>
<li>Views </li>
<li>Communication </li>
<li>State-Based Navigation </li>
<li>View-Based Navigation </li>
</ul>
<p><a href="http://www.pluralsight-training.net/microsoft/Courses/TableOfContents?courseName=prism-introduction" target="_blank"><em>More course information.</em></a></p>
<p><strong>Q4. Who is the author of this kick ass Prism course?</strong>     <br />Q4. That would be me.</p>
<p><strong>Q5. Is it really free?</strong>     <br />Q5. You’re kidding right? Didn’t I already cover this part? Yes, it is free.</p>
<h4>New and Improved</h4>
<p>If you are a subscriber and have already watched the course, I would like to bring to your attention that there have been two new modules added.&#160; These modules will cover everything you need to know in order to start using the navigation services provided by Prism.&#160; This includes state-based navigation and view-based navigation.</p>
<p>Mark your calendar for Nov 12th and be sure to cram as much Prism knowledge into your brain as you can before the weekend ends.&#160; Don’t worry, if you run out of time you can always ask me questions directly.&#160; You can contact me either through Twitter (@<a href="http://twitter.com/brianlagunas" target="_blank">brianlagunas</a>) or through the <a href="http://wpftoolkit.codeplex.com/" target="_blank">Extended WPF Toolkit</a> project site.&#160; I hope you enjoy the training.</p>
]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2011/11/04/free-prism-training/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>geekSpeak: Local Messaging and Silverlight on Channel9</title>
		<link>http://elegantcode.com/2010/07/17/geekspeak-local-messaging-and-silverlight-on-channel9/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=geekspeak-local-messaging-and-silverlight-on-channel9</link>
		<comments>http://elegantcode.com/2010/07/17/geekspeak-local-messaging-and-silverlight-on-channel9/#comments</comments>
		<pubDate>Sun, 18 Jul 2010 00:31:58 +0000</pubDate>
		<dc:creator>Brian Lagunas</dc:creator>
				<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[geekspeak]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2010/07/17/geekspeak-local-messaging-and-silverlight-on-channel9/</guid>
		<description><![CDATA[For those of you who did not get to see the “Local Messaging and Silverlight” geekSpeak webcast live, it has been posted on Channel9 for your viewing pleasure. http://channel9.msdn.com/shows/geekSpeak/geekSpeak-Recording-Local-Messaging-and-Silverlight-with-Brian-Lagunas/ And yes, I did give Elegant Code some love on the show.]]></description>
			<content:encoded><![CDATA[<p>For those of you who did not get to see the “Local Messaging and Silverlight” geekSpeak webcast live, it has been posted on Channel9 for your viewing pleasure.</p>
<p><a title="http://channel9.msdn.com/shows/geekSpeak/geekSpeak-Recording-Local-Messaging-and-Silverlight-with-Brian-Lagunas/" href="http://channel9.msdn.com/shows/geekSpeak/geekSpeak-Recording-Local-Messaging-and-Silverlight-with-Brian-Lagunas/">http://channel9.msdn.com/shows/geekSpeak/geekSpeak-Recording-Local-Messaging-and-Silverlight-with-Brian-Lagunas/</a></p>
<p>And yes, I did give Elegant Code some love on the show.</p>
]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2010/07/17/geekspeak-local-messaging-and-silverlight-on-channel9/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>NETDUG: Silverlight Bing Maps Sample Code</title>
		<link>http://elegantcode.com/2010/07/17/netdug-silverlight-bing-maps-sample-code/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=netdug-silverlight-bing-maps-sample-code</link>
		<comments>http://elegantcode.com/2010/07/17/netdug-silverlight-bing-maps-sample-code/#comments</comments>
		<pubDate>Sun, 18 Jul 2010 00:24:09 +0000</pubDate>
		<dc:creator>Brian Lagunas</dc:creator>
				<category><![CDATA[NETDUG]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[bing maps]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2010/07/17/netdug-silverlight-bing-maps-sample-code/</guid>
		<description><![CDATA[Thanks to everyone who attended last weeks NETDUG presentations. For those of you who would like to get started right away with Bing Maps in your Silverlight applications, you can start here: Get the Bing Maps Silverlight Control Get a Bing Maps API Key Play with the Bing Maps interactive SDK Application Read the Bing [...]]]></description>
			<content:encoded><![CDATA[<p>Thanks to everyone who attended last weeks NETDUG presentations. For those of you who would like to get started right away with Bing Maps in your Silverlight applications, you can start here:</p>
<ul>
<li><a href="http://www.microsoft.com/downloads/details.aspx?displaylang=en&amp;FamilyID=beb29d27-6f0c-494f-b028-1e0e3187e830" target="_blank">Get the Bing Maps Silverlight Control</a> </li>
<li><a href="https://www.bingmapsportal.com/" target="_blank">Get a Bing Maps API Key</a> </li>
<li><a href="http://www.microsoft.com/maps/isdk/silverlight/default.htm" target="_blank">Play with the Bing Maps interactive SDK Application</a> </li>
<li><a href="http://www.bing.com/community/blogs/maps/" target="_blank">Read the Bing Maps blog</a> </li>
<li><a href="http://social.msdn.microsoft.com/Forums/en-US/vemapcontroldev/threads" target="_blank">Check out the Bing Maps forum</a> </li>
</ul>
<p>You can also get the source code to my presentation here:&#160; <a href="http://brianlagunas.com/downloads/presentations/BingMapsSilverlightSamples.zip">Download the source</a>.</p>
<p><em><strong>Note</strong>: You will need to download the Bing Maps Silverlight control and re-reference the DLLs before the source will compile.&#160; Also, you have to have a Bing Maps API key in order to use any of the geocoding service examples.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2010/07/17/netdug-silverlight-bing-maps-sample-code/feed/</wfw:commentRss>
		<slash:comments>0</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/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=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; &#60;Setter Property=&#34;Foreground&#34; Value=&#34;Green&#34; /&#62; &#60;Setter Property=&#34;FontSize&#34; Value=&#34;24&#34; /&#62; &#60;/Style&#62; &#60;/UserControl.Resources&#62; Then, [...]]]></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/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=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>13</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/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=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>12</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/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=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>3</slash:comments>
		</item>
		<item>
		<title>NETDUG &#8211; Silverlight/WPF Multi-Targeting Presentation Sample Code</title>
		<link>http://elegantcode.com/2010/01/22/netdug-silverlightwpf-multi-targeting-presentation-sample-code/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=netdug-silverlightwpf-multi-targeting-presentation-sample-code</link>
		<comments>http://elegantcode.com/2010/01/22/netdug-silverlightwpf-multi-targeting-presentation-sample-code/#comments</comments>
		<pubDate>Sat, 23 Jan 2010 01:36:34 +0000</pubDate>
		<dc:creator>Brian Lagunas</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[NETDUG]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[multi-targeting]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2010/01/22/netdug-silverlightwpf-multi-targeting-presentation-sample-code/</guid>
		<description><![CDATA[If you attended the NETDUG user group meeting last night and would like to download the sample code for my Silverlight/WPF Multi-Targeting presentation, you can download it here. Recap: The Silverlight and WPF platforms are very similar, but they do not have binary compatibility; this means that an assembly compiled for one platform cannot execute [...]]]></description>
			<content:encoded><![CDATA[<p>If you attended the NETDUG user group meeting last night and would like to download the sample code for my Silverlight/WPF Multi-Targeting presentation, you can <a href="http://www.brianlagunas.com/downloads/presentations/MultiTargetingDemo.zip">download it here</a>. </p>
<p><strong>Recap:</strong></p>
<p>The Silverlight and WPF platforms are very similar, but they do not have binary compatibility; this means that an assembly compiled for one platform cannot execute on the other platform (Although, the story is a little different in Silverlight 4). You may want to target some or all of your application on WPF and Silverlight for a number of reasons. </p>
<p>Due to the fact that Silverlight and WPF are so closely related, the bulk of your application code can be shared between the two platforms. This encourages heavy use of pattern based development to isolate the logic from the presentation and maximize the separation between UI code and non-UI code.</p>
<p><strong>Elements you can share:</strong></p>
<ul>
<li>Presenters </li>
<li>Controllers </li>
<li>Models </li>
<li>Services </li>
<li>Unit tests </li>
<li>Simple views, if the XAML used is supported by both Silverlight and WPF. </li>
</ul>
<p><strong>Elements that are harder to share:</strong></p>
<ul>
<li>Complex views (XAML) </li>
<li>Controls </li>
<li>Styling </li>
<li>Animation </li>
</ul>
<p>Like always, if anyone has any questions feel free ask.</p>
]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2010/01/22/netdug-silverlightwpf-multi-targeting-presentation-sample-code/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Open Source Silverlight video players</title>
		<link>http://elegantcode.com/2010/01/22/open-source-silverlight-video-players/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=open-source-silverlight-video-players</link>
		<comments>http://elegantcode.com/2010/01/22/open-source-silverlight-video-players/#comments</comments>
		<pubDate>Fri, 22 Jan 2010 07:28:17 +0000</pubDate>
		<dc:creator>cschuman</dc:creator>
				<category><![CDATA[web]]></category>
		<category><![CDATA[Open Source Software]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[video]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2010/01/22/open-source-silverlight-video-players/</guid>
		<description><![CDATA[Lately I&#8217;ve been spending a lot of time in the Silverlight video space.&#160; Both with writing the video chapter for my Silverlight 4 book as well as at work.&#160; Creating a basic video player is straight forward (link 1 &#124; link 2), have a button to play, a way to control the volume, a scrubber [...]]]></description>
			<content:encoded><![CDATA[<p><a style="float: right" href="http://elegantcode.com/wp-content/uploads/2010/01/image4.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/01/image_thumb4.png" width="150" height="240" /></a> Lately I&#8217;ve been spending a lot of time in the Silverlight video space.&#160; Both with writing the video chapter for my Silverlight 4 book as well as at work.&#160; Creating a basic video player is straight forward (<a href="http://www.85turns.com/2008/04/02/create-a-video-player-silverlight-2-part-1/">link 1</a> | <a href="http://www.85turns.com/2008/04/15/create-a-video-player-silverlight-2-part-2/">link 2</a>), have a button to play, a way to control the volume, a scrubber to show the position of playback, and of course an area to view the video.&#160; </p>
<p>Once you get beyond the basic requirements, the “basic video player” becomes very involved.&#160; A few questions that will need attention are: </p>
<ul>
<li>“How do you handler markers?” </li>
<li>“How is streaming video handled?” </li>
<li>“What do you do an an error?” </li>
<li>“What’s the strategy for buffering?” </li>
<li>“Can the video player support Smooth Streaming content?” (this is a whole different conversation) </li>
<li>“How does the video player handle Closed captioning?” </li>
</ul>
<p>And on and on the list goes.&#160; At some point (hopefully in the analysis phase) you should ask is it better to build or buy.&#160; If you decide to build, give me a call <img src='http://elegantcode.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> , but before you do I would encourage you to take a look at the following open-source (free) Silverlight video player options.&#160; If nothing else, these players are great place to start.</p>
<p>I’ll start off with the three best options, then highlight other projects I am less familiar with.</p>
<h3>Silverlight Media Framework (SMF)</h3>
<p><a href="http://smf.codeplex.com/">http://smf.codeplex.com/</a></p>
<p>This is so much more than a video player, it’s an entire framework.&#160; Developed by <a href="http://www.vertigo.com/">Vertigo</a> in coordination with Microsoft, SMF has been used on the largest, most watched, Silverlight video players to date.&#160; Wimbledon, NFL’s Sunday Night Football, PDC live keynote, and the NBC’s Vancouver Olympics video players, to name a few, all use SMF.&#160; To say it’s robust would be an understatement.</p>
<p>Other than the standard video player controls, here are additional highlights of SMF:</p>
<ul>
<li>Smooth Streaming support – includes the <strong>Microsoft.Web.Media.SmoothStreaming.dll</strong> </li>
<li>Great base classes like <strong>MergeableCollection</strong>, <strong>SimpleEventArgs</strong> and <strong>ObservableObject</strong> </li>
<li>A light weight data project </li>
<li>Logging </li>
<li>Blendability – the player is easily skinned </li>
<li>InStream markers </li>
<li>Bitrate – the ability to show bitrate </li>
</ul>
<p>For a more detailed list of features, and the code, check out SMF’s site.</p>
<h3>Silverlight Video Player</h3>
<p><a href="http://slvideoplayer.codeplex.com/">http://slvideoplayer.codeplex.com/</a></p>
<p>If you have ever watched a video on <a href="http://channel9.msdn.com/">Channel 9</a> (if you haven’t check out <a href="http://channel9.msdn.com/shows/SilverlightTV/">Silverlight TV</a>) the player being used is this video player.&#160; It was developed by <a href="http://timheuer.com/blog/">Tim Heuer</a> (Microsoft) and <a href="http://joel.neubeck.net/">Joel Nuebeck</a> (Silverlight MVP).&#160; Although SVP does not the feature set the SMF player has, this is still a solid and proven video player.&#160; It’s is probably the best option for a standard, light weight, feature rich video player.</p>
<h3>Silverlight HyperVideo player (HVP)</h3>
<p><a title="http://slhvp.com/" href="http://slhvp.com/">http://slhvp.com/</a></p>
<p>A new video player to the scene is the Silverlight Hyper-Video Player (HVP).&#160; This offering is from <a href="http://blogs.silverlight.net/blogs/jesseliberty/">Jesse Liberty</a> (Microsoft) and the Community.&#160; Targeting Silverlight 4, HVP takes advantage of the MEF framework and is rooted in best development practices.&#160; Although the project is young, there is a lot of traction and Jesse is doing an amazing job of documenting each step.&#160; Keep on eye on HVP as this maybe the most scalable offering.</p>
<h3>Others</h3>
<p>The above three video players I have personally used, dug through the code, and/or evaluated.&#160; The following projects I am not as familiar with, but could be possible options for your scenario:</p>
<p><strong>Sharepoint video player</strong> &#8211; <a href="http://svp.codeplex.com/">http://svp.codeplex.com/</a></p>
<p><strong>Silverlight Media Player </strong><a href="http://silverlight30.codeplex.com/">http://silverlight30.codeplex.com/</a></p>
<p><strong>xLite player </strong>- <a href="http://xliteplayer.codeplex.com/">http://xliteplayer.codeplex.com/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2010/01/22/open-source-silverlight-video-players/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ToggleButton Command for Prism</title>
		<link>http://elegantcode.com/2009/06/24/togglebutton-command-for-prism/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=togglebutton-command-for-prism</link>
		<comments>http://elegantcode.com/2009/06/24/togglebutton-command-for-prism/#comments</comments>
		<pubDate>Wed, 24 Jun 2009 23:30:56 +0000</pubDate>
		<dc:creator>cschuman</dc:creator>
				<category><![CDATA[Esoterica]]></category>
		<category><![CDATA[commands]]></category>
		<category><![CDATA[composite framework]]></category>
		<category><![CDATA[prism]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[togglebutton]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2009/06/24/togglebutton-command-for-prism/</guid>
		<description><![CDATA[&#160;Prism Commands enables you to handle user interactions in Xaml.&#160; Even though the plumbing is there, Prism lacks commanding support for everything but Buttons.&#160; Fortunately, it’s relatively easy to create new Commands for a range of controls.&#160; This post details how to create a Checked and UnChecked Command for the ToggleButton (which can be applied [...]]]></description>
			<content:encoded><![CDATA[<p>&#160;<a href="http://msdn.microsoft.com/en-us/library/dd458928.aspx" target="_blank">Prism Commands</a> enables you to handle user interactions in Xaml.&#160; Even though the plumbing is there, Prism lacks commanding support for everything but Buttons.&#160; Fortunately, it’s relatively easy to create new Commands for a range of controls.&#160; This post details how to create a <strong>Checked</strong> and <strong>UnChecked</strong> Command for the <strong>ToggleButton</strong> (which can be applied to a <strong>RadioButton</strong> and a <strong>CheckBox</strong>).</p>
<p>Recently I had a need to create a <strong>Checked</strong> Command for a <strong>ToggleButton</strong>.&#160; There are many sources on how to create a Command, the best one probably being <a href="http://development-guides.silverbaylabs.org/Video/Prism-Commands" target="_blank">Erik Mork’s video</a>, but there wasn’t a place to <em>grab</em> the a Command from.&#160; The intention of this post is to share the <strong>Checked</strong> and <strong>UnChecked</strong> Prism Commands for you to use it in your project.&#160; (Moving forward, it might make sense to create a repository of these Commands.)</p>
<p>Finally, before diving in, if you just want the code and to see an example, follow these links:</p>
<ul>
<li><font size="5"><a href="http://85turns.com/silverlight/zips/CustomCommands.zip" target="_blank">Code</a></font>       </li>
<li><font size="5"><a href="http://85turns.com/silverlight/CustomCommands.html" target="_blank">Example</a></font> </li>
</ul>
<h3>Commands</h3>
<p>Creating the Commands is straight forward.&#160; Derive from <strong>CommandBehaviorBase</strong> and specify the type.&#160; Then, in the constructor, register the event.&#160; Below are both the <strong>Checked</strong> and <strong>UnChecked</strong> commands. </p>
<p><img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="image" border="0" alt="image" src="http://elegantcode.com/wp-content/uploads/2009/06/image-thumb1.png" width="600" height="510" /></p>
<h3>Extensions for Xaml</h3>
<p>After creating the Commands you need to create Static methods to reference in Xaml.&#160; The Static methods are named <strong>Checked</strong> and <strong>UnChecked</strong>.&#160; They include a definition for:</p>
<ul>
<li>SelectedCommandBehaviorProperty </li>
<li>CommandProperty </li>
<li>SetCommand </li>
<li>GetCommand </li>
<li>OnSetCommandCallback </li>
<li>GetOrCreateBehavior </li>
</ul>
<p>In an effort to be brief I have chosen to truncate the two static methods.&#160; To take a closer look at the code, click on the image or download the code. </p>
<p>Checked.cs    <br /><a href="http://elegantcode.com/wp-content/uploads/2009/06/image1.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/2009/06/image-thumb2.png" width="240" height="143" /></a></p>
<p align="center">UnChecked.cs    <br />&#160;<a href="http://elegantcode.com/wp-content/uploads/2009/06/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/2009/06/image-thumb3.png" width="240" height="143" /></a> </p>
<h3>Hooking everything up</h3>
<p>After the Commands are created, bind them to the <strong>ToggleButton</strong> in Xaml.&#160; In this sample application there are three main files:</p>
<ul>
<li><strong>MainPage.xaml</strong> – the presentation. This contains the binding to the Commands. </li>
<li><strong>MainPage.xaml.cs</strong> – the primary function of the code-behind is to new up the <strong>MainPageModel</strong> and set the <strong>DataContext</strong>. </li>
<li><strong>MainPageModel.cs</strong> – this is the model for the <strong>MainPage</strong>. It defines the commands the Xaml binds to as well as a property for the <strong>TextBox</strong> to bind to. </li>
</ul>
<p>Below are images of the classes mentioned above:</p>
<h4>MainPage.xaml</h4>
<p>Note in this Xaml, line 20 binds to the <strong>CheckedState</strong> property in the <strong>MainPageModel</strong>.&#160; The commands are bound on line 22 and 23.&#160; Take notice of the namespace command.&#160; Instead of referencing <strong>Microsoft.Practices.Composite.Presentation.Commands</strong> it references<strong> ProjectName.CustomCommands</strong>.</p>
<p><a href="http://elegantcode.com/wp-content/uploads/2009/06/image3.png"><img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="image" border="0" alt="image" src="http://elegantcode.com/wp-content/uploads/2009/06/image-thumb4.png" width="600" height="477" /></a> </p>
<h4>MainPage.xaml.cs</h4>
<p>This is the code-behind for the above <strong>UserControl</strong>.&#160; On the <strong>Loaded</strong>, a new instance of <strong>MainPageModel</strong> is initialized and then set as the <strong>DataContext</strong> to the <strong>UserControl</strong>.&#160; The heavy lifting is done in the <strong>MainPageModel</strong>.</p>
<p><a href="http://elegantcode.com/wp-content/uploads/2009/06/image4.png"><img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="image" border="0" alt="image" src="http://elegantcode.com/wp-content/uploads/2009/06/image-thumb5.png" width="592" height="601" /></a> </p>
<h4>MainPageModel.cs</h4>
<p>As noted above, the <strong>MainPageModel</strong> does the heavy lifting.&#160; The following describe what happens in this file:</p>
<ul>
<li>Two <strong>DelegateCommands</strong> are defined for <strong>Checked</strong> and <strong>UnChecked</strong>. (line 36 and 41) </li>
<li>A Property called <strong>CheckedState</strong> is defined and fires the <strong>PropertyChanged</strong> event when updated. (lines 13 – 22) </li>
<li>Two methods are defined to handle the actions on the Commands. (lines 47 – 59) </li>
</ul>
<p><a href="http://elegantcode.com/wp-content/uploads/2009/06/image5.png"><img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="image" border="0" alt="image" src="http://elegantcode.com/wp-content/uploads/2009/06/image-thumb6.png" width="600" height="1043" /></a> </p>
<h3>The final product   <br /></h3>
<p><font size="5"><a href="http://85turns.com/silverlight/zips/CustomCommands.zip" target="_blank">Code</a> | </font><font size="5"><a href="http://85turns.com/silverlight/CustomCommands.html" target="_blank">Example</a></font></p>
<p><a href="http://85turns.com/silverlight/CustomCommands.html"><img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="image" border="0" alt="image" src="http://elegantcode.com/wp-content/uploads/2009/06/image6.png" width="570" height="423" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2009/06/24/togglebutton-command-for-prism/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

