<?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>Veracity Solutions Blog &#187; Silverlight 2</title>
	<atom:link href="http://blogs.veracitysolutions.com/tag/silverlight-2/feed/" rel="self" type="application/rss+xml" />
	<link>http://blogs.veracitysolutions.com</link>
	<description>Software Consulting That Rocks</description>
	<lastBuildDate>Thu, 22 Apr 2010 17:21:20 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Head First C#: Silverlight Supplement For Chapter 1 (pages 8-16)</title>
		<link>http://blogs.veracitysolutions.com/head-first-c-silverlight-supplement-for-chapter-1-pages-8-16/</link>
		<comments>http://blogs.veracitysolutions.com/head-first-c-silverlight-supplement-for-chapter-1-pages-8-16/#comments</comments>
		<pubDate>Wed, 06 Aug 2008 17:45:25 +0000</pubDate>
		<dc:creator>Matthias Shapiro</dc:creator>
				<category><![CDATA[Blend]]></category>
		<category><![CDATA[Head First Supplement]]></category>
		<category><![CDATA[How To...]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[HtmlPage]]></category>
		<category><![CDATA[MessageBox]]></category>
		<category><![CDATA[Silverlight 2]]></category>

		<guid isPermaLink="false">http://www.designerwpf.com/2008/08/06/head-first-c-silverlight-supplement-for-chapter-1-pages-8-16/</guid>
		<description><![CDATA[Silverlight Concepts Covered:

Building a basic Silverlight project
Creating code behind for a event triggered by the user
Creating an HTML alert (a fake MessageBox) in Silverlight

Project Files are available for download at the bottom of the page.
Because I&#8217;m an interaction designer and not a coder, I find that there are certain things that can be very limiting [...]]]></description>
			<content:encoded><![CDATA[<h3>Silverlight Concepts Covered:</h3>
<ul>
<li>Building a basic Silverlight project</li>
<li>Creating code behind for a event triggered by the user</li>
<li>Creating an HTML alert (a fake MessageBox) in Silverlight</li>
</ul>
<p>Project Files are available for download at the bottom of the page.</p>
<p>Because I&#8217;m an interaction designer and not a coder, I find that there are certain things that can be very limiting for me. I&#8217;ve decided to fix that by learning how to code properly. To do so, I&#8217;m using a book that actually makes sense to me: <a href="http://www.amazon.com/Head-First-C-Brain-Friendly-Guides/dp/0596514824/ref=pd_bbs_sr_2?ie=UTF8&amp;s=books&amp;qid=1218036644&amp;sr=8-2">Head First C#.</a> If you&#8217;ve never used the Head First series, its generally a pretty good series zero-to-sixty book on the given topic which teaches by doing (the only way I&#8217;ve found I can learn anything).</p>
<p>Sadly, Head First C# currently uses WinForms for all user interfaces. This is the beginning of a series in which I&#8217;ll go through the book, but replace all the WinForms with Silverlight. I will very purposely not give the rest of the lessons because I have a nagging moral qualm in the back of my mind about taking someone else&#8217;s intellectual property and putting it up on my blog. Call me old fashioned.</p>
<p>I will, however, be going through the project and offering alternative code downloads of the projects (with Silverlight interfaces). I figure that, because the Heads First books allow <a href="http://www.headfirstlabs.com/books/hfcsharp/">free downloads of their project code</a> on their website, they don&#8217;t mind me doing this on mine. If anyone from O&#8217;Reilly is reading this and disagrees, just let me know.</p>
<p>The first chapter has you building a program for entering and saving Contacts from start to finish. I will be pointing to the pages and listing alternative Silverlight steps</p>
<h3>Pages 8-16</h3>
<p>1. Start Visual Studio 2008 and select &#8220;Silverlight Application&#8221; from your list of options. The default &#8220;Web Page&#8221; options should be fine for what we&#8217;re doing.</p>
<p><a href="http://www.designerwpf.com/wp-content/uploads/2008/08/clip-image0011.png"></a></p>
<p><a href="http://www.designerwpf.com/wp-content/uploads/2008/08/clip-image0011.png"><img border="0" width="697" src="http://www.designerwpf.com/wp-content/uploads/2008/08/clip-image001-thumb.png" alt="clip_image001" height="265" style="border: 0px" /></a></p>
<p>2. Open up Expression Blend 2.5 (I&#8217;m using the June 2008 Preview) and find your project and open it.</p>
<p><a href="http://www.designerwpf.com/wp-content/uploads/2008/08/clip-image00112.png"><img border="0" width="306" src="http://www.designerwpf.com/wp-content/uploads/2008/08/clip-image00112-thumb.png" alt="clip_image001[12]" height="171" style="border: 0px" /></a></p>
<p>3. Double Click on the Page.xaml file to open it up in Blend. We&#8217;re going to create the basics of our user interface here.</p>
<p>4. Go ahead and grab the &#8220;Objectville Paper Co&#8221; image from <a href="http://www.headfirstlabs.com/books/hfcsharp/">the Heads First web site</a>. Right click on your project in Blend and select &#8220;Add New Folder&#8221;. Name your new folder &#8220;Images&#8221;. Right click on that folder, click &#8220;Add Existing Item&#8230;&#8221; and navigate the graphic you downloaded. Your project should look something like this:</p>
<p><a href="http://www.designerwpf.com/wp-content/uploads/2008/08/clip-image00114.png"><img border="0" width="293" src="http://www.designerwpf.com/wp-content/uploads/2008/08/clip-image00114-thumb.png" alt="clip_image001[14]" height="398" style="border: 0px" /></a></p>
<p>5. Drag the image from the project to the canvas. Things may look a little crowded on the canvas, so lets make it a little bigger. Click the &#8220;<strong>Properties</strong>&#8221; tab (a) on the right side of Blend and make sure you have <strong>UserControl</strong> (the highest object in the tree) selected in the &#8220;<strong>Objects and Timeline</strong>&#8221; (on the left side) (b). Change the <strong>Width</strong> to <strong>600</strong> and the <strong>Height</strong> to<strong> 800</strong> (c).</p>
<p>(a)</p>
<p><img border="0" width="294" src="http://www.designerwpf.com/wp-content/uploads/2008/08/clip-image00116-thumb.png" alt="clip_image001[16]" height="37" style="border: 0px" /></p>
<p>(b)</p>
<p><a href="http://www.designerwpf.com/wp-content/uploads/2008/08/clip-image00118.png"><img border="0" width="322" src="http://www.designerwpf.com/wp-content/uploads/2008/08/clip-image00118-thumb.png" alt="clip_image001[18]" height="157" style="border: 0px" /></a></p>
<p>(c)</p>
<p><a href="http://www.designerwpf.com/wp-content/uploads/2008/08/clip-image00120.png"><img border="0" width="282" src="http://www.designerwpf.com/wp-content/uploads/2008/08/clip-image00120-thumb.png" alt="clip_image001[20]" height="75" style="border: 0px" /></a></p>
<p>6. You&#8217;ll probably notice that our images got stretched. We&#8217;re going to follow the spirit of HFC# and change it to be an unstretched size. Select the <strong>Image</strong> from your <strong>Objects and Timeline</strong> and set <strong>Stretch </strong>to <strong>None</strong>, <strong>HorizontalAlignment</strong> to <strong>Left </strong>and <strong>VerticalAlignment</strong> to <strong>Right</strong>.</p>
<p><a href="http://www.designerwpf.com/wp-content/uploads/2008/08/clip-image00122.png"><img border="0" width="283" src="http://www.designerwpf.com/wp-content/uploads/2008/08/clip-image00122-thumb.png" alt="clip_image001[22]" height="160" style="border: 0px" /></a></p>
<p><a href="http://www.designerwpf.com/wp-content/uploads/2008/08/clip-image00124.png"><img border="0" width="274" src="http://www.designerwpf.com/wp-content/uploads/2008/08/clip-image00124-thumb.png" alt="clip_image001[24]" height="60" style="border: 0px" /></a></p>
<p>7. Before we run the project, let&#8217;s change the background so we can tell where our page is. Select the <strong>LayoutRoot</strong> and change the <strong>Background</strong> to something not white (I chose a light blue). Save All in Blend and click on your open Visual Studio 2008 and hit <strong>F5</strong>. (I haven&#8217;t had a lot of luck getting Silverlight projects to run from Blend)</p>
<p>OK, that gets us to page 14. The next step is to add extra code to the auto-generated code in Visual Studio.</p>
<p>8. Go back to Blend and click on the <strong>Image</strong> and go to the <strong>Events</strong> section (the little lighting icon) of the <strong>Properties</strong> tab. This will give you a list of all the events available for the Image control.</p>
<p><a href="http://www.designerwpf.com/wp-content/uploads/2008/08/clip-image00126.png"><img border="0" width="295" src="http://www.designerwpf.com/wp-content/uploads/2008/08/clip-image00126-thumb.png" alt="clip_image001[26]" height="96" style="border: 0px" /></a></p>
<p>9. In <strong>MouseLeftButtonUp</strong>, type the name of the method you want called when the Image registers a MouseLeftButtonUp event (I typed ImageClick) and hit enter.</p>
<p><a href="http://www.designerwpf.com/wp-content/uploads/2008/08/clip-image00128.png"><img border="0" width="277" src="http://www.designerwpf.com/wp-content/uploads/2008/08/clip-image00128-thumb.png" alt="clip_image001[28]" height="33" style="border: 0px" /></a></p>
<p>10. Blend will communicate to Visual Studio, which will in turn auto-generate all the code you need for that event handler. It should look something like this:</p>
<blockquote><p><span style="color: blue">private void </span>ImageClick(<span style="color: blue">object </span>sender, <span style="color: #2b91af">MouseButtonEventArgs </span>e)</p>
<p>{</p>
<p>}</p></blockquote>
<p>11. Type the following at the top of the page:</p>
<blockquote><p><span style="color: blue">using </span>System.Windows.Browser;</p></blockquote>
<p>and then type the following into the ImageClick method:</p>
<blockquote><p><span style="color: #2b91af">HtmlPage</span>.Window.Alert(<span style="color: #a31515">&#8220;Contact List 1.0. \nWritten by: Your Name&#8221;</span>);</p></blockquote>
<p>Run your project.</p>
<p>From here, HFC# walks through creating a database. The next installment will pick up after the database is created and we get to bind the data to our interface.</p>
<p>Download Project Files for this post: <a href="http://www.designerwpf.com/wp-content/uploads/2008/08/headsfirstchaper1_part1.zip" title="HFCSharp Part 1 Project Files">HFCSharp Part 1 Project Files</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.veracitysolutions.com/head-first-c-silverlight-supplement-for-chapter-1-pages-8-16/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
