<?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>&#60; web:Blog x:Name=&#34;Brian Lagunas&#34; &#47;&#62; &#187; XAML</title>
	<atom:link href="http://www.brianlagunas.com/index.php/category/xaml/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.brianlagunas.com</link>
	<description></description>
	<lastBuildDate>Fri, 03 Sep 2010 01:55:48 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Creating a Custom Silverlight Pre-Loader</title>
		<link>http://www.brianlagunas.com/index.php/2010/03/05/creating-a-custom-silverlight-pre-loader/</link>
		<comments>http://www.brianlagunas.com/index.php/2010/03/05/creating-a-custom-silverlight-pre-loader/#comments</comments>
		<pubDate>Fri, 05 Mar 2010 23:47:26 +0000</pubDate>
		<dc:creator>Brian Lagunas</dc:creator>
				<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[XAML]]></category>
		<category><![CDATA[pre-loader]]></category>

		<guid isPermaLink="false">http://www.brianlagunas.com/index.php/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://www.brianlagunas.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://www.brianlagunas.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://www.brianlagunas.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://www.brianlagunas.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://www.brianlagunas.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://www.brianlagunas.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://www.brianlagunas.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://www.brianlagunas.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://www.brianlagunas.com/index.php/2010/03/05/creating-a-custom-silverlight-pre-loader/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Silverlight 4 – Accessing System Devices with Com Interop, such as a Scanner.</title>
		<link>http://www.brianlagunas.com/index.php/2010/02/19/silverlight-4-accessing-system-devices-with-com-interop/</link>
		<comments>http://www.brianlagunas.com/index.php/2010/02/19/silverlight-4-accessing-system-devices-with-com-interop/#comments</comments>
		<pubDate>Sat, 20 Feb 2010 05:03:07 +0000</pubDate>
		<dc:creator>Brian Lagunas</dc:creator>
				<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[XAML]]></category>
		<category><![CDATA[silverlight 4 beta]]></category>

		<guid isPermaLink="false">http://www.brianlagunas.com/index.php/2010/02/19/silverlight-4-com-interop-and-the-cool-stuff-you-can-do-with-it/</guid>
		<description><![CDATA[Yesterday I gave a presentation on some new features in Silverlight 4.  During this presentation I mentioned the newly available ability to interoperate with Office applications such as Outlook and Excel though the new ComAutomationFactory that is in Silverlight 4.  Someone in the audience asked the question, “Can I access my scanner”, and of course [...]]]></description>
			<content:encoded><![CDATA[<p>Yesterday I gave a presentation on some new features in Silverlight 4.  During this presentation I mentioned the newly available ability to interoperate with Office applications such as Outlook and Excel though the new ComAutomationFactory that is in Silverlight 4.  Someone in the audience asked the question, “Can I access my scanner”, and of course I said yes; then he said, “how?”, and I said, “I will get back to you”.  Well here I am, with code!</p>
<p>A couple of things to note; this feature requires your application to run as an Out Of Browser (OOB) with elevated permissions. Also, there is no IntelliSense for your COM objects. So make sure you have the documentation to the API you are trying to use. So lets get started.</p>
<h3>Creating an OOB Application</h3>
<p>First thing you need to do is crack open VS 2010 Beta 2 and create a new Silverlight project. Make sure you are targeting the .NET Framework 4 it is a Silverlight 4 application.</p>
<p><a href="http://www.brianlagunas.com/wp-content/uploads/2010/02/image11.png" target="_blank"><img style="display: inline; border-width: 0px;" title="image" src="http://www.brianlagunas.com/wp-content/uploads/2010/02/image_thumb11.png" border="0" alt="image" width="248" height="174" /></a></p>
<p>For this test project we don’t need to host this in a website.</p>
<p><a href="http://www.brianlagunas.com/wp-content/uploads/2010/02/image12.png" target="_blank"><img style="display: inline; border-width: 0px;" title="image" src="http://www.brianlagunas.com/wp-content/uploads/2010/02/image_thumb12.png" border="0" alt="image" width="248" height="200" /></a></p>
<p>The next thing you need to do is right-click on the project and choose “Properties”.  Check the “Enable Running Application out of browser”</p>
<p><a href="http://www.brianlagunas.com/wp-content/uploads/2010/02/image13.png" target="_blank"><img style="display: inline; border-width: 0px;" title="image" src="http://www.brianlagunas.com/wp-content/uploads/2010/02/image_thumb13.png" border="0" alt="image" width="248" height="33" /></a></p>
<p>Now click the Out of Browser Settings button and set “Require Elevated Trust when running outside the browser.”</p>
<p><a href="http://www.brianlagunas.com/wp-content/uploads/2010/02/image14.png" target="_blank"><img style="display: inline; border-width: 0px;" title="image" src="http://www.brianlagunas.com/wp-content/uploads/2010/02/image_thumb14.png" border="0" alt="image" width="248" height="60" /></a></p>
<p>Next add a button to the application to install our OOB application.</p>
<div id="codeSnippetWrapper" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; width: 97.5%; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; cursor: text; border: silver 1px solid; padding: 4px;">
<div id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #0000ff;">&lt;</span><span style="color: #800000;">Button</span> <span style="color: #ff0000;">x:Name</span><span style="color: #0000ff;">="btnInstall"</span> <span style="color: #ff0000;">Content</span><span style="color: #0000ff;">="Install Me"</span> <span style="color: #ff0000;">Click</span><span style="color: #0000ff;">="btnInstall_Click"</span> <span style="color: #0000ff;">/&gt;</span></pre>
</div>
</div>
<div id="codeSnippetWrapper" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; width: 97.5%; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; cursor: text; border: silver 1px solid; padding: 4px;">
<div id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #0000ff;">if</span> (Application.Current.InstallState == InstallState.NotInstalled)</pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">               Application.Current.Install();</pre>
</div>
</div>
<p>Now run the application and install it by clicking the install button you just created.  When you start the installation, you will be prompted to install the app, and whether or not you want to create some shortcuts. Just say yes, we trust ourselves, sort of.</p>
<p><a href="http://www.brianlagunas.com/wp-content/uploads/2010/02/image15.png" target="_blank"><img style="display: inline; border-width: 0px;" title="image" src="http://www.brianlagunas.com/wp-content/uploads/2010/02/image_thumb15.png" border="0" alt="image" width="248" height="175" /></a></p>
<p>The next thing we want to do is enable debugging our OOB application.  So right click your project and chose properties –&gt; Debug –&gt; Installed out of browser application –&gt; YourApplication</p>
<p><a href="http://www.brianlagunas.com/wp-content/uploads/2010/02/image16.png" target="_blank"><img style="display: inline; border-width: 0px;" title="image" src="http://www.brianlagunas.com/wp-content/uploads/2010/02/image_thumb16.png" border="0" alt="image" width="248" height="107" /></a></p>
<p>The final step is to add a reference to Microsoft.CSharp.dll so we can use the dynamic keyword.  Look for it in C:\Program Files\Microsoft SDKs\Silverlight\v4.0\Libraries\Client\.  Now on to fun stuff.</p>
<h3>Send an Email with Outlook</h3>
<p>First create a form that will take your user input for the “To” and “Message” data, and a button to send the message.</p>
<div id="codeSnippetWrapper" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; width: 97.5%; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; cursor: text; border: silver 1px solid; padding: 4px;">
<div id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #0000ff;">&lt;</span><span style="color: #800000;">StackPanel</span><span style="color: #0000ff;">&gt;</span></pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">    <span style="color: #0000ff;">&lt;</span><span style="color: #800000;">StackPanel</span> <span style="color: #ff0000;">Margin</span><span style="color: #0000ff;">="5"</span><span style="color: #0000ff;">&gt;</span></pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">        <span style="color: #0000ff;">&lt;</span><span style="color: #800000;">TextBlock</span> <span style="color: #ff0000;">Text</span><span style="color: #0000ff;">="To:"</span> <span style="color: #0000ff;">/&gt;</span></pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">        <span style="color: #0000ff;">&lt;</span><span style="color: #800000;">TextBox</span> <span style="color: #ff0000;">x:Name</span><span style="color: #0000ff;">="txtTo"</span> <span style="color: #0000ff;">/&gt;</span></pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">    <span style="color: #0000ff;">&lt;/</span><span style="color: #800000;">StackPanel</span><span style="color: #0000ff;">&gt;</span></pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">    <span style="color: #0000ff;">&lt;</span><span style="color: #800000;">StackPanel</span> <span style="color: #ff0000;">Margin</span><span style="color: #0000ff;">="5"</span><span style="color: #0000ff;">&gt;</span></pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">        <span style="color: #0000ff;">&lt;</span><span style="color: #800000;">TextBlock</span> <span style="color: #ff0000;">Text</span><span style="color: #0000ff;">="Message"</span> <span style="color: #0000ff;">/&gt;</span></pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">        <span style="color: #0000ff;">&lt;</span><span style="color: #800000;">TextBox</span> <span style="color: #ff0000;">x:Name</span><span style="color: #0000ff;">="txtMessage"</span> <span style="color: #ff0000;">Height</span><span style="color: #0000ff;">="200"</span> <span style="color: #0000ff;">/&gt;</span></pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">    <span style="color: #0000ff;">&lt;/</span><span style="color: #800000;">StackPanel</span><span style="color: #0000ff;">&gt;</span></pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">    <span style="color: #0000ff;">&lt;</span><span style="color: #800000;">Button</span> <span style="color: #ff0000;">x:Name</span><span style="color: #0000ff;">="btnSend"</span> <span style="color: #ff0000;">Content</span><span style="color: #0000ff;">="Send Message"</span> <span style="color: #ff0000;">Click</span><span style="color: #0000ff;">="btnSend_Click"</span> <span style="color: #0000ff;">/&gt;</span></pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #0000ff;">&lt;/</span><span style="color: #800000;">StackPanel</span><span style="color: #0000ff;">&gt;</span></pre>
</div>
</div>
<p>Then handle the button click event as follows.</p>
<div id="codeSnippetWrapper" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; width: 97.5%; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; cursor: text; border: silver 1px solid; padding: 4px;">
<div id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">private void btnSend_Click(object sender, RoutedEventArgs e)</pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">{</pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">    using (dynamic outlook = ComAutomationFactory.CreateObject("Outlook.Application"))</pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">    {</pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">        dynamic mail = outlook.CreateItem(0);</pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">        mail.To = txtTo.Text;</pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">        mail.Subject = "Hello, from Silverlight";</pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">        mail.HTMLBody = txtMessage.Text;</pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">        mail.Display();</pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">    }</pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">}</pre>
</div>
</div>
<p>And you done.  Of course this will only display the message, but just call mail.Send() to actually send it; one thing to mention is to make sure you have Outlook open when you hit send or bad things will happen.</p>
<h3>Send Data to Excel, edit it, and update Silverlight</h3>
<p>Now this little trick is cool. We will have a data source, send it to excel for display and editing, then send the updated data back to our Silverlight application and update the UI.  Now this is a poor mans implementation for demo reasons.</p>
<p>First lets create our UI and populate it with data.  This is what mine looks like.</p>
<p><a href="http://www.brianlagunas.com/wp-content/uploads/2010/02/image17.png" target="_blank"><img style="display: inline; border-width: 0px;" title="image" src="http://www.brianlagunas.com/wp-content/uploads/2010/02/image_thumb17.png" border="0" alt="image" width="248" height="147" /></a></p>
<p>Lets code up the Launch Excel button.</p>
<div id="codeSnippetWrapper" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; width: 97.5%; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; cursor: text; border: silver 1px solid; padding: 4px;">
<div id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #0000ff;">bool</span> firstTime = <span style="color: #0000ff;">true</span>;</pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #0000ff;">private</span> <span style="color: #0000ff;">void</span> LaunchExcel(<span style="color: #0000ff;">object</span> sender, RoutedEventArgs e)</pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">{</pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">   <span style="color: #008000;">// create an instance of excel</span></pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">   dynamic excel = ComAutomationFactory.CreateObject(<span style="color: #006080;">"Excel.Application"</span>);</pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">   excel.Visible = <span style="color: #0000ff;">true</span>;  <span style="color: #008000;">// make it visible to the user.</span></pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"> </pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">   <span style="color: #008000;">// add a workbook to the instance </span></pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">   dynamic workbook = excel.workbooks;</pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">   workbook.Add();</pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"> </pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">   dynamic sheet = excel.ActiveSheet; <span style="color: #008000;">// get the active sheet</span></pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"> </pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">   dynamic cell = <span style="color: #0000ff;">null</span>;</pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"> </pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">   <span style="color: #0000ff;">int</span> i = 1;</pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"> </pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">   <span style="color: #008000;">// iterate through our data source and populate the excel spreadsheet</span></pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">   <span style="color: #0000ff;">foreach</span> (Entity item <span style="color: #0000ff;">in</span> CustomerList.ItemsSource)</pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">   {</pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">       cell = sheet.Cells[i, 1]; <span style="color: #008000;">// row, column</span></pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">       cell.Value = item.CustomerName;</pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">       cell.ColumnWidth = 25;</pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"> </pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">       cell = sheet.Cells[i, 2];</pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">       cell.Value = item.UnitSales;</pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">       i++;</pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">   }</pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"> </pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">   <span style="color: #008000;">// add a chart</span></pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">   dynamic sheetShapes = sheet.Shapes;</pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">   sheetShapes.AddChart(-4100, 200, 2, 400, 300);</pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"> </pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">   <span style="color: #008000;">// wire up an event handler to the Excel SheetChanged event</span></pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">   <span style="color: #0000ff;">if</span> (firstTime)</pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">   {</pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">       excel.SheetChange += <span style="color: #0000ff;">new</span> SheetChangedDelegate(SheetChangedEventHandler);</pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">       <span style="color: #0000ff;">string</span> sheetName = sheet.Name;</pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"> </pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">       firstTime = <span style="color: #0000ff;">false</span>;</pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">   }</pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"> </pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">   ExcelButton.IsEnabled = <span style="color: #0000ff;">true</span>;</pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">}</pre>
</div>
</div>
<p>As you can see we are hooking into the Sheet changed event so we can respond to when the data is update in excel. So here is the code for that.</p>
<div id="codeSnippetWrapper" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; width: 97.5%; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; cursor: text; border: silver 1px solid; padding: 4px;">
<div id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #0000ff;">delegate</span> <span style="color: #0000ff;">void</span> SheetChangedDelegate(dynamic excelSheet, dynamic rangeArgs);</pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"> </pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #008000;">// event handler for the sheet changed event</span></pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #008000;">// looks at the data and creates a new items source to rebind to the datagrid</span></pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #0000ff;">private</span> <span style="color: #0000ff;">void</span> SheetChangedEventHandler(dynamic excelSheet, dynamic rangeArgs)</pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">{</pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">    dynamic sheet = excelSheet;</pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"> </pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">    <span style="color: #0000ff;">string</span> sheetName = sheet.Name;</pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"> </pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">    dynamic range = rangeArgs;</pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"> </pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">    dynamic rowValue = range.Row;</pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"> </pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">    Entity[] entities = CustomerList.ItemsSource <span style="color: #0000ff;">as</span> Entity[];</pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">    Entity[] newEntities = <span style="color: #0000ff;">new</span> Entity[10];</pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"> </pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">    dynamic col2range = sheet.Range(<span style="color: #006080;">"B1:B10"</span>);</pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"> </pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">    <span style="color: #0000ff;">for</span> (<span style="color: #0000ff;">int</span> i = 0; i &lt; 10; i++)</pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">    {</pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">        Entity newEntity = <span style="color: #0000ff;">new</span> Entity();</pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">        newEntity.CustomerName = entities[i].CustomerName;</pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">        newEntity.PhoneNumber = entities[i].PhoneNumber;</pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"> </pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">        dynamic item = col2range.Item(i + 1);</pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">        newEntity.UnitSales = Convert.ToInt32(item.Value);</pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"> </pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">        newEntities[i] = newEntity;</pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">    }</pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"> </pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">    CustomerList.ItemsSource = newEntities;</pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">    CustomerList.SelectedIndex = Convert.ToInt32(rowValue) - 1;</pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"> </pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">    UpdateNotification.Text = <span style="color: #006080;">"Data updated from Excel spreadsheet"</span>;</pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">}</pre>
</div>
</div>
<p>Now, I will click the Launch Excel button, and edit my data.</p>
<p><a href="http://www.brianlagunas.com/wp-content/uploads/2010/02/image18.png" target="_blank"><img style="display: inline; border-width: 0px;" title="image" src="http://www.brianlagunas.com/wp-content/uploads/2010/02/image_thumb18.png" border="0" alt="image" width="248" height="131" /></a></p>
<p>Now if I look back in my Silverlight application, I will now see that all of my data in the grid has been updated.</p>
<p><a href="http://www.brianlagunas.com/wp-content/uploads/2010/02/image19.png" target="_blank"><img style="display: inline; border-width: 0px;" title="image" src="http://www.brianlagunas.com/wp-content/uploads/2010/02/image_thumb19.png" border="0" alt="image" width="248" height="132" /></a></p>
<h3>Lets Open a Program</h3>
<p>Using the <a href="http://msdn.microsoft.com/en-us/library/ahcz2kh6(VS.85).aspx" target="_blank">WScript.Shell</a> API we can execute any command and open any program.  In this example lets open Notepad and write some text to it.  So first I am going to create a simple UI to allow a user to enter some text, then click a button to send it to Notepad.</p>
<div id="codeSnippetWrapper" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; width: 97.5%; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; cursor: text; border: silver 1px solid; padding: 4px;">
<div id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #0000ff;">&lt;</span><span style="color: #800000;">StackPanel</span><span style="color: #0000ff;">&gt;</span></pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">   <span style="color: #0000ff;">&lt;</span><span style="color: #800000;">TextBlock</span> <span style="color: #ff0000;">Text</span><span style="color: #0000ff;">="Enter text to send to NotePad."</span> <span style="color: #0000ff;">/&gt;</span></pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">   <span style="color: #0000ff;">&lt;</span><span style="color: #800000;">TextBox</span> <span style="color: #ff0000;">x:Name</span><span style="color: #0000ff;">="txtTextToSend"</span> <span style="color: #0000ff;">/&gt;</span></pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">   <span style="color: #0000ff;">&lt;</span><span style="color: #800000;">Button</span> <span style="color: #ff0000;">x:Name</span><span style="color: #0000ff;">="txtOpenProgram"</span> <span style="color: #ff0000;">Content</span><span style="color: #0000ff;">="Open NotePad"</span> <span style="color: #ff0000;">Click</span><span style="color: #0000ff;">="txtOpenProgram_Click"</span>  <span style="color: #0000ff;">/&gt;</span></pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #0000ff;">&lt;/</span><span style="color: #800000;">StackPanel</span><span style="color: #0000ff;">&gt;</span></pre>
</div>
</div>
<div id="codeSnippetWrapper" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; width: 97.5%; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; cursor: text; border: silver 1px solid; padding: 4px;">
<div id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #0000ff;">private</span> <span style="color: #0000ff;">void</span> txtOpenProgram_Click(<span style="color: #0000ff;">object</span> sender, RoutedEventArgs e)</pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">{</pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">    <span style="color: #0000ff;">using</span> (dynamic shell = ComAutomationFactory.CreateObject(<span style="color: #006080;">"WScript.Shell"</span>))</pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">    {</pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">        shell.Run(<span style="color: #006080;">@"C:\windows\notepad.exe"</span>); <span style="color: #008000;">//you can open anything</span></pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">        shell.SendKeys(txtTextToSend.Text);</pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">    }</pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">}</pre>
</div>
</div>
<p>Now lets enter some text and click that button.</p>
<p><a href="http://www.brianlagunas.com/wp-content/uploads/2010/02/image20.png" target="_blank"><img style="display: inline; border-width: 0px;" title="image" src="http://www.brianlagunas.com/wp-content/uploads/2010/02/image_thumb20.png" border="0" alt="image" width="248" height="45" /></a></p>
<p><a href="http://www.brianlagunas.com/wp-content/uploads/2010/02/image21.png" target="_blank"><img style="display: inline; border-width: 0px;" title="image" src="http://www.brianlagunas.com/wp-content/uploads/2010/02/image_thumb21.png" border="0" alt="image" width="248" height="102" /></a></p>
<p>Now that's pretty cool. I am sure your mind is thinking of all the cool stuff you can do with this.</p>
<p>Well, this stuff is cool and all, but where is the really cool stuff? <strong>Wait no more!</strong></p>
<h3>Text to Speech</h3>
<p>That’s right, I said it.  I am going to use the <a href="http://msdn.microsoft.com/en-us/library/ms723602(VS.85).aspx" target="_blank">SAPI.SpVoice</a> API to tap into the power of text to speech. So lets build a UI that will allow a user to enter some text. Heck lets let them control the rate and pitch of the speech.</p>
<div id="codeSnippetWrapper" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; width: 97.5%; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; cursor: text; border: silver 1px solid; padding: 4px;">
<div id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #0000ff;">&lt;</span><span style="color: #800000;">StackPanel</span><span style="color: #0000ff;">&gt;</span></pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">    <span style="color: #0000ff;">&lt;</span><span style="color: #800000;">TextBlock</span> <span style="color: #ff0000;">Text</span><span style="color: #0000ff;">="Enter text to say: "</span> <span style="color: #0000ff;">/&gt;</span></pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">    <span style="color: #0000ff;">&lt;</span><span style="color: #800000;">TextBox</span> <span style="color: #ff0000;">x:Name</span><span style="color: #0000ff;">="txtTextToSay"</span> <span style="color: #ff0000;">Margin</span><span style="color: #0000ff;">="0,0,0,20"</span> <span style="color: #0000ff;">/&gt;</span></pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">    <span style="color: #0000ff;">&lt;</span><span style="color: #800000;">TextBlock</span> <span style="color: #ff0000;">Text</span><span style="color: #0000ff;">="Pitch"</span> <span style="color: #0000ff;">/&gt;</span></pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">    <span style="color: #0000ff;">&lt;</span><span style="color: #800000;">Slider</span> <span style="color: #ff0000;">x:Name</span><span style="color: #0000ff;">="sldrPitch"</span> <span style="color: #ff0000;">Minimum</span><span style="color: #0000ff;">="-10"</span> <span style="color: #ff0000;">Maximum</span><span style="color: #0000ff;">="10"</span> <span style="color: #ff0000;">Value</span><span style="color: #0000ff;">="0"</span> <span style="color: #0000ff;">/&gt;</span></pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">    <span style="color: #0000ff;">&lt;</span><span style="color: #800000;">TextBlock</span> <span style="color: #ff0000;">Text</span><span style="color: #0000ff;">="Rate"</span> <span style="color: #0000ff;">/&gt;</span></pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">    <span style="color: #0000ff;">&lt;</span><span style="color: #800000;">Slider</span> <span style="color: #ff0000;">x:Name</span><span style="color: #0000ff;">="sldrRate"</span> <span style="color: #ff0000;">Minimum</span><span style="color: #0000ff;">="-10"</span> <span style="color: #ff0000;">Maximum</span><span style="color: #0000ff;">="10"</span> <span style="color: #ff0000;">Value</span><span style="color: #0000ff;">="0"</span> <span style="color: #0000ff;">/&gt;</span></pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">    <span style="color: #0000ff;">&lt;</span><span style="color: #800000;">Button</span> <span style="color: #ff0000;">x:Name</span><span style="color: #0000ff;">="btnSpeak"</span> <span style="color: #ff0000;">Content</span><span style="color: #0000ff;">="Speak"</span> <span style="color: #ff0000;">Click</span><span style="color: #0000ff;">="btnSpeak_Click"</span> <span style="color: #ff0000;">Margin</span><span style="color: #0000ff;">="20"</span> <span style="color: #0000ff;">/&gt;</span></pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #0000ff;">&lt;/</span><span style="color: #800000;">StackPanel</span><span style="color: #0000ff;">&gt;</span></pre>
</div>
</div>
<p>This should look something like this.</p>
<p><a href="http://www.brianlagunas.com/wp-content/uploads/2010/02/image22.png" target="_blank"><img style="display: inline; border-width: 0px;" title="image" src="http://www.brianlagunas.com/wp-content/uploads/2010/02/image_thumb22.png" border="0" alt="image" width="248" height="141" /></a></p>
<p>Lets hook up our button’s click event and make some noise.</p>
<div id="codeSnippetWrapper" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; width: 97.5%; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; cursor: text; border: silver 1px solid; padding: 4px;">
<div id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #0000ff;">private</span> <span style="color: #0000ff;">void</span> btnSpeak_Click(<span style="color: #0000ff;">object</span> sender, RoutedEventArgs e)</pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">{</pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">   <span style="color: #0000ff;">using</span> (dynamic ISpeechVoice = ComAutomationFactory.CreateObject(<span style="color: #006080;">"SAPI.SpVoice"</span>))</pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">   {</pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">       ISpeechVoice.Volume = 100;</pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">       ISpeechVoice.Speak(<span style="color: #0000ff;">string</span>.Format(<span style="color: #006080;">"&lt;rate speed=\"{0}\"&gt;&lt;pitch middle=\"{1}\"&gt;{2}"</span>, Math.Round(sldrRate.Value), Math.Round(sldrPitch.Value), txtTextToSay.Text));</pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">   }</pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">}</pre>
</div>
</div>
<p>If you wanted to you could create a volume control for it as well.</p>
<p>What? This still isn’t cool enough for you? Well I think I can satisfy your need for coolness. Enter:</p>
<h3>Acquire an Image from your Scanner/Camera</h3>
<p>That’s right I said it.  You can access your scanner, scan an image, and then save it to your hard drive.  Here we are using the <a href="http://msdn.microsoft.com/en-us/library/ms630827(VS.85).aspx" target="_blank">WIA</a> (Windows Image Acquisition). “WIA is a full-featured image manipulation component that provides end-to-end image processing capabilities.  The WIA Automation Layer makes it easy to acquire images on digital cameras, scanners, or Web cameras, and to rotate, scale, and annotate your image files.” So, enough with the talking, lets get coding.</p>
<p>First all I need to do it create a button that will initiate the process.</p>
<div id="codeSnippetWrapper" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; width: 97.5%; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; cursor: text; border: silver 1px solid; padding: 4px;">
<div id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #0000ff;">&lt;</span><span style="color: #800000;">Button</span> <span style="color: #ff0000;">x:Name</span><span style="color: #0000ff;">="btnAquireImage"</span> <span style="color: #ff0000;">Content</span><span style="color: #0000ff;">="Aquire Image from Scanner/Camera"</span> <span style="color: #ff0000;">Click</span><span style="color: #0000ff;">="btnAquireImage_Click"</span> <span style="color: #0000ff;">/&gt;</span></pre>
</div>
</div>
<p>Now we need to handle the button’s click event and do all the complicated code.</p>
<div id="codeSnippetWrapper" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; width: 97.5%; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; cursor: text; border: silver 1px solid; padding: 4px;">
<div id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #0000ff;">private</span> <span style="color: #0000ff;">void</span> btnAquireImage_Click(<span style="color: #0000ff;">object</span> sender, RoutedEventArgs e)</pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">{</pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">   <span style="color: #0000ff;">using</span> (dynamic CommonDialog = ComAutomationFactory.CreateObject(<span style="color: #006080;">"WIA.CommonDialog"</span>))</pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">   {</pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">       dynamic imageFile = CommonDialog.ShowAcquireImage();</pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">       <span style="color: #0000ff;">if</span> (imageFile != <span style="color: #0000ff;">null</span>)</pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">       {</pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">           <span style="color: #0000ff;">string</span> filePath = <span style="color: #0000ff;">string</span>.Format(<span style="color: #006080;">"D:\\{0}.jpg"</span>, Guid.NewGuid());</pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">           imageFile.SaveFile(filePath);</pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">           MessageBox.Show(<span style="color: #0000ff;">string</span>.Format(<span style="color: #006080;">"Saved {0}"</span>, filePath));</pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">       }</pre>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">   }</pre>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">}</pre>
</div>
</div>
<p>So what does this actually do?  Well lets push the button and find out:</p>
<p><a href="http://www.brianlagunas.com/wp-content/uploads/2010/02/image23.png" target="_blank"><img style="display: inline; border-width: 0px;" title="image" src="http://www.brianlagunas.com/wp-content/uploads/2010/02/image_thumb23.png" border="0" alt="image" width="248" height="166" /></a></p>
<p>Well the first thing it does is asks me which device I want to get my images from.  Lets pick my scanner.</p>
<p><a href="http://www.brianlagunas.com/wp-content/uploads/2010/02/image24.png" target="_blank"><img style="display: inline; border-width: 0px;" title="image" src="http://www.brianlagunas.com/wp-content/uploads/2010/02/image_thumb24.png" border="0" alt="image" width="248" height="193" /></a></p>
<p>Well, holly crap, that’s my scanner. And I can preview and crop my image before I even get the image. Yes, that is my baby picture, it was the only thing I could find OKAY!  All my current pictures are digital.  Anyways, so once I like my settings I click scan, the scanner will do its thing and my image will be saved.</p>
<p><a href="http://www.brianlagunas.com/wp-content/uploads/2010/02/image25.png" target="_blank"><img style="display: inline; border-width: 0px;" title="image" src="http://www.brianlagunas.com/wp-content/uploads/2010/02/image_thumb25.png" border="0" alt="image" width="248" height="120" /></a></p>
<p><a href="http://www.brianlagunas.com/wp-content/uploads/2010/02/image26.png" target="_blank"><img style="display: inline; border-width: 0px;" title="image" src="http://www.brianlagunas.com/wp-content/uploads/2010/02/image_thumb26.png" border="0" alt="image" width="248" height="116" /></a></p>
<p><a href="http://www.brianlagunas.com/wp-content/uploads/2010/02/image27.png" target="_blank"><img style="display: inline; border-width: 0px;" title="image" src="http://www.brianlagunas.com/wp-content/uploads/2010/02/image_thumb27.png" border="0" alt="image" width="248" height="91" /></a></p>
<p>And there it is right where I told it to save.  How fun is that? I did you a favor and already coded all this up and packed it up in a nice little zip file.  So <a href="http://brianlagunas.com/downloads/source/Silverlight4_ComInterop.zip" target="_blank">download the code</a>, play with it, and write some kick ass applications!</p>
<p>I almost forgot to mention, when you open the source code, go into Properties –&gt; Debug –&gt; and select “Dynamically create the page”, then run the application, install it, and go back and change the option back to “Installed out of browser application ”.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.brianlagunas.com/index.php/2010/02/19/silverlight-4-accessing-system-devices-with-com-interop/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>NETDUG – Silverlight/WPF Multi-Targeting Presentation Sample Code</title>
		<link>http://www.brianlagunas.com/index.php/2010/01/28/netdug-silverlightwpf-multi-targeting-presentation-sample-code/</link>
		<comments>http://www.brianlagunas.com/index.php/2010/01/28/netdug-silverlightwpf-multi-targeting-presentation-sample-code/#comments</comments>
		<pubDate>Fri, 29 Jan 2010 03:12:03 +0000</pubDate>
		<dc:creator>Brian Lagunas</dc:creator>
				<category><![CDATA[NETDUG]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[XAML]]></category>
		<category><![CDATA[multi-targeting]]></category>

		<guid isPermaLink="false">http://brianlagunas.com/2010/01/28/netdug-silverlightwpf-multi-targeting-presentation-sample-code/</guid>
		<description><![CDATA[If you attended the NETDUG user group meeting last Thursday 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 on [...]]]></description>
			<content:encoded><![CDATA[<p>If you attended the NETDUG user group meeting last Thursday 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://www.brianlagunas.com/index.php/2010/01/28/netdug-silverlightwpf-multi-targeting-presentation-sample-code/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>BSDG &#8211; Silverlight/WPF Multi-Targeting Presentation Sample Code</title>
		<link>http://www.brianlagunas.com/index.php/2009/12/04/bsdg-silverlightwpf-multi-targeting-presentation-sample-code/</link>
		<comments>http://www.brianlagunas.com/index.php/2009/12/04/bsdg-silverlightwpf-multi-targeting-presentation-sample-code/#comments</comments>
		<pubDate>Fri, 04 Dec 2009 18:37:46 +0000</pubDate>
		<dc:creator>Brian Lagunas</dc:creator>
				<category><![CDATA[BSDG]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[XAML]]></category>
		<category><![CDATA[multi-targeting]]></category>

		<guid isPermaLink="false">http://brianlagunas.com/2009/12/04/bsdg-silverlightwpf-multi-targeting-presentation-sample-code/</guid>
		<description><![CDATA[If you attended the BSDG 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 on [...]]]></description>
			<content:encoded><![CDATA[<p>If you attended the BSDG 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" target="_blank">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://www.brianlagunas.com/index.php/2009/12/04/bsdg-silverlightwpf-multi-targeting-presentation-sample-code/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A Simple WPF Loading Animation</title>
		<link>http://www.brianlagunas.com/index.php/2009/08/21/a-simple-wpf-loading-animation/</link>
		<comments>http://www.brianlagunas.com/index.php/2009/08/21/a-simple-wpf-loading-animation/#comments</comments>
		<pubDate>Sat, 22 Aug 2009 03:45:05 +0000</pubDate>
		<dc:creator>Brian Lagunas</dc:creator>
				<category><![CDATA[WPF]]></category>
		<category><![CDATA[XAML]]></category>
		<category><![CDATA[animation]]></category>

		<guid isPermaLink="false">http://brianlagunas.com/2009/08/21/a-simple-wpf-loading-animation/</guid>
		<description><![CDATA[Okay, so I needed a very simple and clean loading animation for a multi threaded application I was working on to notify the user that something was in the process of being loaded.&#160; So of course the first place I looked was Google, because I figured someone else has already written one and I could [...]]]></description>
			<content:encoded><![CDATA[<p>Okay, so I needed a very simple and clean loading animation for a multi threaded application I was working on to notify the user that something was in the process of being loaded.&#160; So of course the first place I looked was Google, because I figured someone else has already written one and I could save myself some time by just using theirs.&#160; Well, after almost an hour searching, I found nothing.&#160; So much for being a timesaver.&#160; Now, don’t get me wrong, I found a couple of WPF animations out there, but none of them really fit what I needed.&#160; So I just decided to bite the bullet and create my own.&#160; After creating the animation I decided to share the fruits of my labor so that anyone else who is looking for the same thing I was, or something similar, wouldn’t have as much trouble as I did.</p>
<p>Here is what it looks like.</p>
<p><a href="http://brianlagunas.com/wp-content/uploads/2009/08/loadingAnimation.jpg"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="loadingAnimation" border="0" alt="loadingAnimation" src="http://brianlagunas.com/wp-content/uploads/2009/08/loadingAnimation_thumb.jpg" width="114" height="114" /></a> </p>
<p>Here is the source: <a href="http://brianlagunas.com/downloads/source/LoadingControl.zip">Download the Loading Animation Source</a></p>
<p>I hope it is useful to someone besides me.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.brianlagunas.com/index.php/2009/08/21/a-simple-wpf-loading-animation/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Debugging XAML</title>
		<link>http://www.brianlagunas.com/index.php/2009/04/14/debugging-xaml-2/</link>
		<comments>http://www.brianlagunas.com/index.php/2009/04/14/debugging-xaml-2/#comments</comments>
		<pubDate>Wed, 15 Apr 2009 01:41:09 +0000</pubDate>
		<dc:creator>Brian Lagunas</dc:creator>
				<category><![CDATA[WPF]]></category>
		<category><![CDATA[XAML]]></category>
		<category><![CDATA[debugging]]></category>

		<guid isPermaLink="false">http://brianlagunas.com/2009/07/06/debugging-xaml-2/</guid>
		<description><![CDATA[Okay, so I have been asked this question more than almost any XAML related question in the past few weeks; How do I debug XAML?  The problem with XAML’s powerful binding model is that it can be difficult to debug errors in your binding paths.
Lets say I have the following code snippet:


&#60;StatusBar&#62;
   &#60;StatusBarItem&#62;
 [...]]]></description>
			<content:encoded><![CDATA[<p>Okay, so I have been asked this question more than almost any XAML related question in the past few weeks; How do I debug XAML?  The problem with XAML’s powerful binding model is that it can be difficult to debug errors in your binding paths.</p>
<p>Lets say I have the following code snippet:</p>
<div style="font-size: 8pt; margin: 20px 0px 10px; overflow: auto; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; border: gray 1px solid; padding: 4px;">
<div style="font-size: 8pt; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; border-style: none; padding: 0px;">
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: white; border-style: none; padding: 0px;"><span style="color: #0000ff">&lt;</span><span style="color: #800000">StatusBar</span><span style="color: #0000ff">&gt;</span></pre>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; border-style: none; padding: 0px;">   <span style="color: #0000ff">&lt;</span><span style="color: #800000">StatusBarItem</span><span style="color: #0000ff">&gt;</span></pre>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: white; border-style: none; padding: 0px;">       <span style="color: #0000ff">&lt;</span><span style="color: #800000">TextBlock</span> <span style="color: #ff0000">Text</span><span style="color: #0000ff">="{Binding Message}"</span> <span style="color: #0000ff">/&gt;</span></pre>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; border-style: none; padding: 0px;">   <span style="color: #0000ff">&lt;/</span><span style="color: #800000">StatusBarItem</span><span style="color: #0000ff">&gt;</span></pre>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: white; border-style: none; padding: 0px;"><span style="color: #0000ff">&lt;/</span><span style="color: #800000">StatusBar</span><span style="color: #0000ff">&gt;</span></pre>
</div>
</div>
<p>As you can see my property Message is totally misspelled.  If I were to run this application nothing would ever appear in my status bar, and I would not know why.  I didn’t get any compile errors, and my view renders perfectly in my designer, so what the hell is going on.  You might spend hours looking at your object’s property, stepping through the property changed events, or just saying XAML is a piece of crap and I give up.  Well never fear, I am about to reveal the secret to debugging your XAML.</p>
<p>Look in your Output Window!</p>
<p><a href="http://brianlagunas.com/wp-content/uploads/2009/07/OutputWindow.jpg" target="_blank"><img style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" title="OutputWindow" src="http://brianlagunas.com/wp-content/uploads/2009/07/OutputWindow_thumb.jpg" border="0" alt="OutputWindow" width="404" height="79" /></a></p>
<p>Yes, the nearly always forgotten Output Window.  As you can see, if you click on the image above, it tells me that I have a binding expression path error and gives the line number where the error occurred.  So don’t spend hours stepping through code looking for a ghost.  Just check your Output Window.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.brianlagunas.com/index.php/2009/04/14/debugging-xaml-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Free Office WPF Ribbon</title>
		<link>http://www.brianlagunas.com/index.php/2009/04/07/the-free-office-wpf-ribbon-2/</link>
		<comments>http://www.brianlagunas.com/index.php/2009/04/07/the-free-office-wpf-ribbon-2/#comments</comments>
		<pubDate>Wed, 08 Apr 2009 01:47:00 +0000</pubDate>
		<dc:creator>Brian Lagunas</dc:creator>
				<category><![CDATA[WPF]]></category>
		<category><![CDATA[XAML]]></category>
		<category><![CDATA[office ribbon]]></category>

		<guid isPermaLink="false">http://brianlagunas.com/2009/04/07/the-free-office-wpf-ribbon-2/</guid>
		<description><![CDATA[So you want to use a Ribbon toolbar similar to Microsoft Word in your applications, but you don’t want to purchase one from a third party. Well if you haven’t heard already, you can get a free one directly from Microsoft. Yes, you heard me correctly, FREE, and FROM MICROSOFT. So where do you get [...]]]></description>
			<content:encoded><![CDATA[<p>So you want to use a Ribbon toolbar similar to Microsoft Word in your applications, but you don’t want to purchase one from a third party. Well if you haven’t heard already, you can get a free one directly from Microsoft. Yes, you heard me correctly, FREE, and FROM MICROSOFT. So where do you get this free Ribbon control?</p>
<p>To get it just follow these steps:</p>
<ol>
<li>Go to <a href="http://msdn.microsoft.com/officeui">http://msdn.microsoft.com/officeui</a> </li>
<li>Click on “License the Office UI” </li>
<li>Login using you Windows Live ID. If you don’t have one you can create one for free. </li>
<li>Read and accept the Office UI License </li>
<li>Click on the WPF Ribbon download button </li>
<li>Accept the WPF Ribbon CTP License and follow the instructions to save the ribbon binaries to your computer. </li>
</ol>
<p>Now that you have the Ribbon, you will notice there isn’t a lot of documentation.&#160; So how do you use this thing? Well lets start with the basics.</p>
<p><strong><font size="4">Adding the WPF Ribbon Control:</font></strong></p>
<p>The first thing you need to do is add a reference to the RibbonControlsLibrary to your project. Next add the namespace declaration to your XAML.</p>
<div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, &#39;Courier New&#39;, courier, monospace; height: 41px; background-color: #f4f4f4">
<div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #0000ff">&lt;</span><span style="color: #800000">xmlns:r</span>=&quot;<span style="color: #ff0000">clr-namespace:Microsoft</span>.<span style="color: #ff0000">Windows</span>.<span style="color: #ff0000">Controls</span>.<span style="color: #ff0000">Ribbon</span>;<span style="color: #ff0000">assembly</span>=<span style="color: #ff0000">RibbonControlsLibrary</span>“ <span style="color: #0000ff">/&gt;</span></pre>
</p></div>
</div>
<p>Now that you have that done you can add the Ribbon control like so.</p>
<div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, &#39;Courier New&#39;, courier, monospace; background-color: #f4f4f4">
<div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #0000ff">&lt;</span><span style="color: #800000">DockPanel</span> <span style="color: #ff0000">LastChildFill</span><span style="color: #0000ff">=&quot;True&quot;</span><span style="color: #0000ff">&gt;</span></pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">     <span style="color: #0000ff">&lt;</span><span style="color: #800000">r:Ribbon</span> <span style="color: #ff0000">DockPanel</span>.<span style="color: #ff0000">Dock</span><span style="color: #0000ff">=&quot;Top&quot;</span><span style="color: #0000ff">&gt;</span></pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">            </pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">     <span style="color: #0000ff">&lt;/</span><span style="color: #800000">r:Ribbon</span><span style="color: #0000ff">&gt;</span></pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #0000ff">&lt;/</span><span style="color: #800000">DockPanel</span><span style="color: #0000ff">&gt;</span> </pre>
</p></div>
</div>
<p>I personally like to place it DockPanel and dock it to the top. So this is what you should have so far. I know it is not much to look at right now, but we will fix that.</p>
<p><a href="http://brianlagunas.com/wp-content/uploads/2009/07/AddingRibbon.png"><img title="AddingRibbon" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="170" alt="AddingRibbon" src="http://brianlagunas.com/wp-content/uploads/2009/07/AddingRibbon_thumb.png" width="436" border="0" /></a> </p>
<p><strong><font size="4">Adding the Application Menu:</font></strong></p>
<p>Now that we have a Ribbon control we can start setting up our Application Menu. In Microsoft Word, this is the big round button in the top left corner of the application.</p>
<div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, &#39;Courier New&#39;, courier, monospace; background-color: #f4f4f4">
<div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #0000ff">&lt;</span><span style="color: #800000">r:Ribbon.ApplicationMenu</span><span style="color: #0000ff">&gt;</span></pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">     <span style="color: #0000ff">&lt;</span><span style="color: #800000">r:RibbonApplicationMenu</span><span style="color: #0000ff">&gt;</span></pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">          <span style="color: #0000ff">&lt;</span><span style="color: #800000">r:RibbonApplicationMenuItem</span> <span style="color: #0000ff">/&gt;</span></pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">     <span style="color: #0000ff">&lt;/</span><span style="color: #800000">r:RibbonApplicationMenu</span><span style="color: #0000ff">&gt;</span></pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #0000ff">&lt;/</span><span style="color: #800000">r:Ribbon.ApplicationMenu</span><span style="color: #0000ff">&gt;</span></pre>
</p></div>
</div>
<p>The above XAML will produce this:</p>
<p><a href="http://brianlagunas.com/wp-content/uploads/2009/07/AddingApplicationMenu.png"><img title="AddingApplicationMenu" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="170" alt="AddingApplicationMenu" src="http://brianlagunas.com/wp-content/uploads/2009/07/AddingApplicationMenu_thumb.png" width="436" border="0" /></a> </p>
<p>I know what your thinking. What the hell is that? How do I set my text? How do I set my icon? All I see is an empty box. Enter the <strong>RibbonCommand.</strong> RibbonCommands allow you to define a ribbon element’s UI and reuse it at will. So how do you set one up? Let me show you.</p>
<div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, &#39;Courier New&#39;, courier, monospace; background-color: #f4f4f4">
<div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #0000ff">&lt;</span><span style="color: #800000">r:Ribbon.Resources</span><span style="color: #0000ff">&gt;</span></pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">     <span style="color: #0000ff">&lt;</span><span style="color: #800000">r:RibbonCommand</span> <span style="color: #ff0000">x:Key</span><span style="color: #0000ff">=&quot;cmdAddNew&quot;</span></pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">                      <span style="color: #ff0000">Executed</span><span style="color: #0000ff">=&quot;OnAddNew_Executed&quot;</span></pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">                      <span style="color: #ff0000">LabelTitle</span><span style="color: #0000ff">=&quot;New Project&quot;</span></pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">                      <span style="color: #ff0000">LabelDescription</span><span style="color: #0000ff">=&quot;Creates an empty project.&quot;</span> </pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">                      <span style="color: #ff0000">LargeImageSource</span><span style="color: #0000ff">=&quot;Images/Large/New32.png&quot;</span></pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">                      <span style="color: #ff0000">SmallImageSource</span><span style="color: #0000ff">=&quot;Images/Small/New16.png&quot;</span><span style="color: #0000ff">/&gt;</span></pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #0000ff">&lt;/</span><span style="color: #800000">r:Ribbon.Resources</span><span style="color: #0000ff">&gt;</span></pre>
</p></div>
</div>
<p>Now we set the Command attribute on our element.</p>
<div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, &#39;Courier New&#39;, courier, monospace; background-color: #f4f4f4">
<div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #0000ff">&lt;</span><span style="color: #800000">r:Ribbon.ApplicationMenu</span><span style="color: #0000ff">&gt;</span></pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">     <span style="color: #0000ff">&lt;</span><span style="color: #800000">r:RibbonApplicationMenu</span><span style="color: #0000ff">&gt;</span></pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">          <span style="color: #0000ff">&lt;</span><span style="color: #800000">r:RibbonApplicationMenuItem</span> <span style="color: #ff0000">Command</span><span style="color: #0000ff">=&quot;{StaticResource cmdAddNew}&quot;</span><span style="color: #0000ff">/&gt;</span></pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">     <span style="color: #0000ff">&lt;/</span><span style="color: #800000">r:RibbonApplicationMenu</span><span style="color: #0000ff">&gt;</span></pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #0000ff">&lt;/</span><span style="color: #800000">r:Ribbon.ApplicationMenu</span><span style="color: #0000ff">&gt;</span></pre>
</p></div>
</div>
<p>And BAM! You now have your icons and text. One thing to mention is that if you do not specify an Executed event, your button will be disabled until you do so.</p>
<p><a href="http://brianlagunas.com/wp-content/uploads/2009/07/AddingRibbonCommand.png"><img title="AddingRibbonCommand" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="170" alt="AddingRibbonCommand" src="http://brianlagunas.com/wp-content/uploads/2009/07/AddingRibbonCommand_thumb.png" width="436" border="0" /></a> </p>
</p>
</p>
<p><strong><font size="4">Adding the Quick Access Toolbar:</font></strong></p>
<p>The Quick Access Toolbar, also known as the QAT, is the mini menu that is normally at the top of the application just to the right of the application menu and&#160; includes a Customize Menu which end-users can use to add and remove buttons from the QAT. So how do we add one? Like so….</p>
<div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, &#39;Courier New&#39;, courier, monospace; background-color: #f4f4f4">
<div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #0000ff">&lt;</span><span style="color: #800000">r:Ribbon.QuickAccessToolBar</span><span style="color: #0000ff">&gt;</span></pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">     <span style="color: #0000ff">&lt;</span><span style="color: #800000">r:RibbonQuickAccessToolBar</span><span style="color: #0000ff">&gt;</span></pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">          <span style="color: #0000ff">&lt;</span><span style="color: #800000">r:RibbonButton</span> <span style="color: #ff0000">Command</span><span style="color: #0000ff">=&quot;{StaticResource cmdAddNew}“ r:RibbonQuickAccessToolBar.Placement=&quot;</span><span style="color: #ff0000">InCustomizeMenuAndToolBar</span>&quot; <span style="color: #0000ff">/&gt;</span></pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">     <span style="color: #0000ff">&lt;/</span><span style="color: #800000">r:RibbonQuickAccessToolBar</span><span style="color: #0000ff">&gt;</span></pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #0000ff">&lt;/</span><span style="color: #800000">r:Ribbon.QuickAccessToolBar</span><span style="color: #0000ff">&gt;</span></pre>
</p></div>
</div>
<p>Remember that RibbonCommand we created earlier, well here it is again. Now you should have something like this:</p>
<p><a href="http://brianlagunas.com/wp-content/uploads/2009/07/AddingQAT.png"><img title="AddingQAT" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="170" alt="AddingQAT" src="http://brianlagunas.com/wp-content/uploads/2009/07/AddingQAT_thumb.png" width="436" border="0" /></a> </p>
<p>See our new little icon at the top of the screen? Pretty isn’t it? Okay, not really, but it will be when we get finished with it.</p>
<p><strong><font size="4">Adding Tabs:</font></strong></p>
<p>Okay this is really easy.</p>
<div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, &#39;Courier New&#39;, courier, monospace; background-color: #f4f4f4">
<div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #0000ff">&lt;</span><span style="color: #800000">r:RibbonTab</span> <span style="color: #ff0000">Label</span><span style="color: #0000ff">=&quot;Home&quot;</span><span style="color: #0000ff">&gt;</span></pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">                    </pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #0000ff">&lt;/</span><span style="color: #800000">r:RibbonTab</span><span style="color: #0000ff">&gt;</span></pre>
</p></div>
</div>
<p>Thats it! Now you should have this:</p>
<p><a href="http://brianlagunas.com/wp-content/uploads/2009/07/AddingTabs.png"><img title="AddingTabs" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="170" alt="AddingTabs" src="http://brianlagunas.com/wp-content/uploads/2009/07/AddingTabs_thumb.png" width="436" border="0" /></a> </p>
<p><strong><font size="4">Adding Groups:</font></strong></p>
<p>These are just as easy.</p>
<div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, &#39;Courier New&#39;, courier, monospace; background-color: #f4f4f4">
<div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #0000ff">&lt;</span><span style="color: #800000">r:RibbonGroup</span><span style="color: #0000ff">&gt;</span></pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">    <span style="color: #0000ff">&lt;</span><span style="color: #800000">r:RibbonGroup.Command</span><span style="color: #0000ff">&gt;</span></pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">        <span style="color: #0000ff">&lt;</span><span style="color: #800000">r:RibbonCommand</span> <span style="color: #ff0000">LabelTitle</span><span style="color: #0000ff">=&quot;File&quot;</span> <span style="color: #0000ff">/&gt;</span></pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">    <span style="color: #0000ff">&lt;/</span><span style="color: #800000">r:RibbonGroup.Command</span><span style="color: #0000ff">&gt;</span></pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">    <span style="color: #0000ff">&lt;</span><span style="color: #800000">r:RibbonButton</span> <span style="color: #ff0000">Command</span><span style="color: #0000ff">=&quot;{StaticResource cmdAddNew}&quot;</span><span style="color: #0000ff">/&gt;</span></pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #0000ff">&lt;/</span><span style="color: #800000">r:RibbonGroup</span><span style="color: #0000ff">&gt;</span></pre>
</p></div>
</div>
<p>Make sure this code snippet goes inside the Tab you created. </p>
<p><a href="http://brianlagunas.com/wp-content/uploads/2009/07/AddingGroups.png"><img title="AddingGroups" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="170" alt="AddingGroups" src="http://brianlagunas.com/wp-content/uploads/2009/07/AddingGroups_thumb.png" width="436" border="0" /></a> </p>
<p>Also, a little caveat, or word of caution, you cannot have an empty group. If you do, then you will get a compile error. So make sure you have at least one control inside of your group definition.</p>
<p><strong><font size="4">Styling the WPF Ribbon:</font></strong></p>
<p>Okay, I admit, our ribbon is still butt ugly. So lets go ahead and fix this. There are a couple of different ways we can style our ribbon. We could custom write a resource dictionary and manually set all the style attributes to get the look we want. Or we can just use a supplied Office 2007 theme by using the <strong>PopularApplicationSkins</strong> class that is included with the RibbonControlsLibrary.dll.</p>
<p>In code behind you would do something like this:</p>
<div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, &#39;Courier New&#39;, courier, monospace; height: 60px; background-color: #f4f4f4">
<div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">Resources.MergedDictionaries.Add(Microsoft.Windows.Controls.Ribbon.PopularApplicationSkins.Office2007Blue);</pre>
</p></div>
</div>
<p>In XAML it would look like this:</p>
<div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, &#39;Courier New&#39;, courier, monospace; background-color: #f4f4f4">
<div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #0000ff">&lt;</span><span style="color: #800000">Window.Resources</span><span style="color: #0000ff">&gt;</span></pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">    <span style="color: #0000ff">&lt;</span><span style="color: #800000">ResourceDictionary</span><span style="color: #0000ff">&gt;</span></pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">        <span style="color: #0000ff">&lt;</span><span style="color: #800000">ResourceDictionary.MergedDictionaries</span><span style="color: #0000ff">&gt;</span></pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">            <span style="color: #0000ff">&lt;</span><span style="color: #800000">ResourceDictionary</span> <span style="color: #ff0000">Source</span><span style="color: #0000ff">=&quot;/RibbonControlsLibrary;component/Themes/Office2007Blue.xaml&quot;</span> <span style="color: #0000ff">/&gt;</span></pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">        <span style="color: #0000ff">&lt;/</span><span style="color: #800000">ResourceDictionary.MergedDictionaries</span><span style="color: #0000ff">&gt;</span></pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #0000ff">&lt;/</span><span style="color: #800000">ResourceDictionary</span><span style="color: #0000ff">&gt;</span></pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #0000ff">&lt;/</span><span style="color: #800000">Window.Resources</span><span style="color: #0000ff">&gt;</span></pre>
</p></div>
</div>
<p>Either way our application is now looking good and ready to roll.</p>
<p><a href="http://brianlagunas.com/wp-content/uploads/2009/07/AddingStyle.png"><img title="AddingStyle" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="170" alt="AddingStyle" src="http://brianlagunas.com/wp-content/uploads/2009/07/AddingStyle_thumb.png" width="436" border="0" /></a> </p>
</p>
<p>I hope this gets you going in the right direction. I plan on posting more advanced topics dealing with the ribbon in the future such as using the RibbonWindow, populating the “Most Recent Items List”, and using a Dialog Launcher. If you have any requests please feel free to ask.</p>
<p><a href="http://brianlagunas.com/Downloads/Source/WPFRibbon.zip">Download Source</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.brianlagunas.com/index.php/2009/04/07/the-free-office-wpf-ribbon-2/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
