<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Saad Blog</title>
	<atom:link href="http://saadtips.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://saadtips.wordpress.com</link>
	<description>Visual Studio &#38; MS Sql Server Blog</description>
	<lastBuildDate>Thu, 26 Aug 2010 10:21:16 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='saadtips.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Saad Blog</title>
		<link>http://saadtips.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://saadtips.wordpress.com/osd.xml" title="Saad Blog" />
	<atom:link rel='hub' href='http://saadtips.wordpress.com/?pushpress=hub'/>
		<item>
		<title>الفتاة النصرانية التي اسلمت وتركت كل شئ لاجل الله</title>
		<link>http://saadtips.wordpress.com/2010/08/26/%d8%a7%d9%84%d9%81%d8%aa%d8%a7%d8%a9-%d8%a7%d9%84%d9%86%d8%b5%d8%b1%d8%a7%d9%86%d9%8a%d8%a9-%d8%a7%d9%84%d8%aa%d9%8a-%d8%a7%d8%b3%d9%84%d9%85%d8%aa-%d9%88%d8%aa%d8%b1%d9%83%d8%aa-%d9%83%d9%84-%d8%b4/</link>
		<comments>http://saadtips.wordpress.com/2010/08/26/%d8%a7%d9%84%d9%81%d8%aa%d8%a7%d8%a9-%d8%a7%d9%84%d9%86%d8%b5%d8%b1%d8%a7%d9%86%d9%8a%d8%a9-%d8%a7%d9%84%d8%aa%d9%8a-%d8%a7%d8%b3%d9%84%d9%85%d8%aa-%d9%88%d8%aa%d8%b1%d9%83%d8%aa-%d9%83%d9%84-%d8%b4/#comments</comments>
		<pubDate>Thu, 26 Aug 2010 10:21:16 +0000</pubDate>
		<dc:creator>saadtips</dc:creator>
		
		<guid isPermaLink="false">http://saadtips.wordpress.com/2010/08/26/%d8%a7%d9%84%d9%81%d8%aa%d8%a7%d8%a9-%d8%a7%d9%84%d9%86%d8%b5%d8%b1%d8%a7%d9%86%d9%8a%d8%a9-%d8%a7%d9%84%d8%aa%d9%8a-%d8%a7%d8%b3%d9%84%d9%85%d8%aa-%d9%88%d8%aa%d8%b1%d9%83%d8%aa-%d9%83%d9%84-%d8%b4/</guid>
		<description><![CDATA[<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=saadtips.wordpress.com&amp;blog=9673707&amp;post=223&amp;subd=saadtips&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=saadtips.wordpress.com&amp;blog=9673707&amp;post=223&amp;subd=saadtips&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://saadtips.wordpress.com/2010/08/26/%d8%a7%d9%84%d9%81%d8%aa%d8%a7%d8%a9-%d8%a7%d9%84%d9%86%d8%b5%d8%b1%d8%a7%d9%86%d9%8a%d8%a9-%d8%a7%d9%84%d8%aa%d9%8a-%d8%a7%d8%b3%d9%84%d9%85%d8%aa-%d9%88%d8%aa%d8%b1%d9%83%d8%aa-%d9%83%d9%84-%d8%b4/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/16b7fdb6045a11e7ac6f021becbca7bf?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">saadtips</media:title>
		</media:content>
	</item>
		<item>
		<title>تفعيل البث المباشر لصلاة العشـاء والتراويح من جـامع الشيخ ظ ن اصر القطامي بالرياض</title>
		<link>http://saadtips.wordpress.com/2010/08/18/%d8%aa%d9%81%d8%b9%d9%8a%d9%84-%d8%a7%d9%84%d8%a8%d8%ab-%d8%a7%d9%84%d9%85%d8%a8%d8%a7%d8%b4%d8%b1-%d9%84%d8%b5%d9%84%d8%a7%d8%a9-%d8%a7%d9%84%d8%b9%d8%b4%d9%80%d8%a7%d8%a1-%d9%88%d8%a7%d9%84%d8%aa/</link>
		<comments>http://saadtips.wordpress.com/2010/08/18/%d8%aa%d9%81%d8%b9%d9%8a%d9%84-%d8%a7%d9%84%d8%a8%d8%ab-%d8%a7%d9%84%d9%85%d8%a8%d8%a7%d8%b4%d8%b1-%d9%84%d8%b5%d9%84%d8%a7%d8%a9-%d8%a7%d9%84%d8%b9%d8%b4%d9%80%d8%a7%d8%a1-%d9%88%d8%a7%d9%84%d8%aa/#comments</comments>
		<pubDate>Wed, 18 Aug 2010 14:19:16 +0000</pubDate>
		<dc:creator>saadtips</dc:creator>
		
		<guid isPermaLink="false">http://saadtips.wordpress.com/2010/08/18/%d8%aa%d9%81%d8%b9%d9%8a%d9%84-%d8%a7%d9%84%d8%a8%d8%ab-%d8%a7%d9%84%d9%85%d8%a8%d8%a7%d8%b4%d8%b1-%d9%84%d8%b5%d9%84%d8%a7%d8%a9-%d8%a7%d9%84%d8%b9%d8%b4%d9%80%d8%a7%d8%a1-%d9%88%d8%a7%d9%84%d8%aa/</guid>
		<description><![CDATA[البـث المبــاشر . حرصًا من إدارة موقع الشيخ نـاصر بن علي القطـامي تم تفعيل البث المباشر لصلاة العشـاء والتراويح من جـامع القاضي عبر الموقع الرسمي وبـدقة عالية . من خلال الرابط التالي : http://www.alqtami.com/live علمــا أن موعـد البـث الســاعة 8:25 إلــى السـاعة 10 مساء بتــوقيت مكة المكرمة . رابط الخبر<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=saadtips.wordpress.com&amp;blog=9673707&amp;post=222&amp;subd=saadtips&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h2>البـث المبــاشر . </h2>
<p> حرصًا من إدارة موقع الشيخ نـاصر بن علي القطـامي تم تفعيل البث المباشر لصلاة العشـاء والتراويح من جـامع القاضي عبر الموقع الرسمي وبـدقة عالية . من خلال الرابط التالي :</p>
<p><a href="http://www.alqtami.com/live">http://www.alqtami.com/live</a></p>
<p>علمــا أن موعـد البـث الســاعة 8:25 إلــى السـاعة 10 مساء</p>
<p>بتــوقيت مكة المكرمة .</p>
<p><a href="http://www.alqtami.com/A-762"><strong>رابط الخبر</strong></a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/saadtips.wordpress.com/222/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/saadtips.wordpress.com/222/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/saadtips.wordpress.com/222/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/saadtips.wordpress.com/222/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/saadtips.wordpress.com/222/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/saadtips.wordpress.com/222/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/saadtips.wordpress.com/222/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/saadtips.wordpress.com/222/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/saadtips.wordpress.com/222/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/saadtips.wordpress.com/222/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/saadtips.wordpress.com/222/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/saadtips.wordpress.com/222/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/saadtips.wordpress.com/222/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/saadtips.wordpress.com/222/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=saadtips.wordpress.com&amp;blog=9673707&amp;post=222&amp;subd=saadtips&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://saadtips.wordpress.com/2010/08/18/%d8%aa%d9%81%d8%b9%d9%8a%d9%84-%d8%a7%d9%84%d8%a8%d8%ab-%d8%a7%d9%84%d9%85%d8%a8%d8%a7%d8%b4%d8%b1-%d9%84%d8%b5%d9%84%d8%a7%d8%a9-%d8%a7%d9%84%d8%b9%d8%b4%d9%80%d8%a7%d8%a1-%d9%88%d8%a7%d9%84%d8%aa/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/16b7fdb6045a11e7ac6f021becbca7bf?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">saadtips</media:title>
		</media:content>
	</item>
		<item>
		<title>5: Using the ListBox and DataBinding to Display List Data</title>
		<link>http://saadtips.wordpress.com/2009/12/19/5-using-the-listbox-and-databinding-to-display-list-data/</link>
		<comments>http://saadtips.wordpress.com/2009/12/19/5-using-the-listbox-and-databinding-to-display-list-data/#comments</comments>
		<pubDate>Sat, 19 Dec 2009 18:36:25 +0000</pubDate>
		<dc:creator>saadtips</dc:creator>
				<category><![CDATA[1]]></category>

		<guid isPermaLink="false">http://saadtips.wordpress.com/?p=221</guid>
		<description><![CDATA[Source: http://weblogs.asp.net/scottgu/pages/silverlight-tutorial-part-5-using-the-listbox-and-databinding-to-display-list-data.aspx Silverlight Tutorial Part 5: Using the ListBox and DataBinding to Display List Data This is part five of eight tutorials that walk through how to build a simple Digg client application using Silverlight 2. These tutorials are intended to be read in-order, and help explain some of the core programming concepts of Silverlight. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=saadtips.wordpress.com&amp;blog=9673707&amp;post=221&amp;subd=saadtips&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Source: <a href="http://weblogs.asp.net/scottgu/pages/silverlight-tutorial-part-5-using-the-listbox-and-databinding-to-display-list-data.aspx">http://weblogs.asp.net/scottgu/pages/silverlight-tutorial-part-5-using-the-listbox-and-databinding-to-display-list-data.aspx</a></p>
<h2> Silverlight Tutorial Part 5: Using the ListBox and DataBinding to Display List Data </h2>
<p>This is <a href="http://weblogs.asp.net/scottgu/pages/silverlight-2-end-to-end-tutorial-building-a-digg-search-client.aspx">part five of eight tutorials</a> that walk through how to build a simple Digg client application using Silverlight 2. These tutorials are intended to be read in-order, and help explain some of the core programming concepts of Silverlight. Bookmark my <a href="http://weblogs.asp.net/scottgu/pages/silverlight-posts.aspx">Silverlight 2 Reference page</a> for more of Silverlight posts and content.</p>
<p><strong>&lt;Download Code&gt; </strong><a href="http://www.scottgu.com/blogposts/slbeta1apps/diggsample.zip">Click here</a> to download a completed version of this Digg client sample. <strong>&lt;/Download Code&gt;</strong></p>
<h3>Displaying our Digg Stories using the ListBox and DataBinding</h3>
<p>Previously we&#8217;ve been using the DataGrid control to display our Digg stories. This works great when we want to display the content in a column format. For our Digg application, though, we probably want to tweak the appearance a little more and have it look less like a DataGrid of stories and more like a List of them. The good news is that this easy &#8211; and it doesn&#8217;t require us to change any of our application code to accomplish this.</p>
<p>We&#8217;ll start by replacing our DataGrid control with a &lt;ListBox&gt; control. We&#8217;ll keep the control name the same as before (&quot;StoriesList&quot;):</p>
<p><img src="http://silverlight1blogpost.s3.amazonaws.com/step73.png" alt="step73.png" /></p>
<p>When we run our application again and search for stories, the ListBox will display the following results:</p>
<p><img src="http://silverlight1blogpost.s3.amazonaws.com/step74.png" alt="step74.png" /></p>
<p>You might be wondering &#8211; why is each item &quot;DiggSample.DiggStory&quot;? The reason for this is because we are binding DiggStory objects to the ListBox (and the default behavior is to call ToString() on them). If we want to display the &quot;Title&quot; property of the DiggStory object instead, we can set the &quot;DisplayMemberPath&quot; property on the ListBox:</p>
<p><img src="http://silverlight1blogpost.s3.amazonaws.com/step76.png" alt="step76.png" /></p>
<p>When we do this the Title will be what is displayed in the ListBox:</p>
<p><img src="http://silverlight1blogpost.s3.amazonaws.com/step75.png" alt="step75.png" /></p>
<p>If we want to show more than one value at a time, or customize the layout of each item more, we can override the ListBox control&#8217;s ItemTemplate and supply a custom DataTemplate. Within this DataTemplate we can customize how each DiggStory object is displayed.</p>
<p>For example, we could display both the DiggStory Title and NumDiggs value using a DataTemplate like below.</p>
<p><img src="http://silverlight1blogpost.s3.amazonaws.com/step77.png" alt="step77.png" /></p>
<p>We can databind any public properties we want from our DiggStory object within the DataTemplate. Notice above how we are using the {Binding Path=<em>PropertyName</em>} syntax to accomplish this with the two TextBlock controls.</p>
<p>With the above DataTemplate in place, our ListBox will now display its items like below:</p>
<p><img src="http://silverlight1blogpost.s3.amazonaws.com/step78.png" alt="step78.png" /></p>
<p>Let&#8217;s then go one step further and change our DataTemplate to the one below. This DataTemplate uses two StackPanels &#8211; one to stack row items horizontally, and one to stack some textblocks together vertically:</p>
<p><img src="http://silverlight1blogpost.s3.amazonaws.com/step85.png" alt="step85.png" /></p>
<p>The above DataTemplate causes our ListBox to display items like the screen-shot below:</p>
<p><img src="http://silverlight1blogpost.s3.amazonaws.com/step84.png" alt="step84.png" /></p>
<p>when we define the following Style rules in our App.xaml (note how we are using a LinearGradientBrush to get the nice yellow gradient background on the DiggPanel):</p>
<p><img src="http://silverlight1blogpost.s3.amazonaws.com/step86.png" alt="step86.png" /></p>
<p>One important thing to notice about our ListBox &#8211; even though we have customized what the items in it look like, it still automatically provides support for hover and item selection semantics. This is true both when using the mouse and when using the keyboard (up/down arrow keys, home/end, etc):</p>
<p><img src="http://silverlight1blogpost.s3.amazonaws.com/step84.png" alt="step84.png" /></p>
<p>The ListBox also supports full flow resizing &#8211; and will provide automatic scrolling of our custom content when necessary (notice how the horizontal scroll bar appears as the window gets smaller):</p>
<p><img src="http://silverlight1blogpost.s3.amazonaws.com/step87.png" alt="step87.png" /></p>
<h3>Next Steps</h3>
<p>We&#8217;ve now switched our data visualization to be List based, and cleaned up the content listing of it.</p>
<p>Let&#8217;s now complete the last bits of the functionality behavior in the application &#8211; and implement a master/details workflow which allows end-users to drill into the specifics of a story when they select an article from the list. To-do that let&#8217;s jump to our next tutorial: <a href="http://weblogs.asp.net/scottgu/pages/silverlight-tutorial-part-6-using-user-controls-to-implement-master-detail-scenarios.aspx">Using User Controls to Implement Master/Detail Scenarios</a>.</p>
<p>Published Friday, February 22, 2008 5:51 AM by <a href="http://weblogs.asp.net/members/ScottGu.aspx">ScottGu</a> <img src="http://weblogs.asp.net/Themes/default/images/common/star-left-on.gif" alt="star-left-on.gif" /><img src="http://weblogs.asp.net/Themes/default/images/common/star-right-on.gif" alt="star-right-on.gif" /><img src="http://weblogs.asp.net/Themes/default/images/common/star-left-on.gif" alt="star-left-on.gif" /><img src="http://weblogs.asp.net/Themes/default/images/common/star-right-on.gif" alt="star-right-on.gif" /><img src="http://weblogs.asp.net/Themes/default/images/common/star-left-on.gif" alt="star-left-on.gif" /><img src="http://weblogs.asp.net/Themes/default/images/common/star-right-on.gif" alt="star-right-on.gif" /><img src="http://weblogs.asp.net/Themes/default/images/common/star-left-off.gif" alt="star-left-off.gif" /><img src="http://weblogs.asp.net/Themes/default/images/common/star-right-off.gif" alt="star-right-off.gif" /><img src="http://weblogs.asp.net/Themes/default/images/common/star-left-off.gif" alt="star-left-off.gif" /><img src="http://weblogs.asp.net/Themes/default/images/common/star-right-off.gif" alt="star-right-off.gif" /></p>
<br />Posted in 1  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/saadtips.wordpress.com/221/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/saadtips.wordpress.com/221/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/saadtips.wordpress.com/221/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/saadtips.wordpress.com/221/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/saadtips.wordpress.com/221/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/saadtips.wordpress.com/221/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/saadtips.wordpress.com/221/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/saadtips.wordpress.com/221/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/saadtips.wordpress.com/221/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/saadtips.wordpress.com/221/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/saadtips.wordpress.com/221/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/saadtips.wordpress.com/221/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/saadtips.wordpress.com/221/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/saadtips.wordpress.com/221/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=saadtips.wordpress.com&amp;blog=9673707&amp;post=221&amp;subd=saadtips&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://saadtips.wordpress.com/2009/12/19/5-using-the-listbox-and-databinding-to-display-list-data/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/16b7fdb6045a11e7ac6f021becbca7bf?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">saadtips</media:title>
		</media:content>

		<media:content url="http://silverlight1blogpost.s3.amazonaws.com/step73.png" medium="image">
			<media:title type="html">step73.png</media:title>
		</media:content>

		<media:content url="http://silverlight1blogpost.s3.amazonaws.com/step74.png" medium="image">
			<media:title type="html">step74.png</media:title>
		</media:content>

		<media:content url="http://silverlight1blogpost.s3.amazonaws.com/step76.png" medium="image">
			<media:title type="html">step76.png</media:title>
		</media:content>

		<media:content url="http://silverlight1blogpost.s3.amazonaws.com/step75.png" medium="image">
			<media:title type="html">step75.png</media:title>
		</media:content>

		<media:content url="http://silverlight1blogpost.s3.amazonaws.com/step77.png" medium="image">
			<media:title type="html">step77.png</media:title>
		</media:content>

		<media:content url="http://silverlight1blogpost.s3.amazonaws.com/step78.png" medium="image">
			<media:title type="html">step78.png</media:title>
		</media:content>

		<media:content url="http://silverlight1blogpost.s3.amazonaws.com/step85.png" medium="image">
			<media:title type="html">step85.png</media:title>
		</media:content>

		<media:content url="http://silverlight1blogpost.s3.amazonaws.com/step84.png" medium="image">
			<media:title type="html">step84.png</media:title>
		</media:content>

		<media:content url="http://silverlight1blogpost.s3.amazonaws.com/step86.png" medium="image">
			<media:title type="html">step86.png</media:title>
		</media:content>

		<media:content url="http://silverlight1blogpost.s3.amazonaws.com/step84.png" medium="image">
			<media:title type="html">step84.png</media:title>
		</media:content>

		<media:content url="http://silverlight1blogpost.s3.amazonaws.com/step87.png" medium="image">
			<media:title type="html">step87.png</media:title>
		</media:content>

		<media:content url="http://weblogs.asp.net/Themes/default/images/common/star-left-on.gif" medium="image">
			<media:title type="html">star-left-on.gif</media:title>
		</media:content>

		<media:content url="http://weblogs.asp.net/Themes/default/images/common/star-right-on.gif" medium="image">
			<media:title type="html">star-right-on.gif</media:title>
		</media:content>

		<media:content url="http://weblogs.asp.net/Themes/default/images/common/star-left-on.gif" medium="image">
			<media:title type="html">star-left-on.gif</media:title>
		</media:content>

		<media:content url="http://weblogs.asp.net/Themes/default/images/common/star-right-on.gif" medium="image">
			<media:title type="html">star-right-on.gif</media:title>
		</media:content>

		<media:content url="http://weblogs.asp.net/Themes/default/images/common/star-left-on.gif" medium="image">
			<media:title type="html">star-left-on.gif</media:title>
		</media:content>

		<media:content url="http://weblogs.asp.net/Themes/default/images/common/star-right-on.gif" medium="image">
			<media:title type="html">star-right-on.gif</media:title>
		</media:content>

		<media:content url="http://weblogs.asp.net/Themes/default/images/common/star-left-off.gif" medium="image">
			<media:title type="html">star-left-off.gif</media:title>
		</media:content>

		<media:content url="http://weblogs.asp.net/Themes/default/images/common/star-right-off.gif" medium="image">
			<media:title type="html">star-right-off.gif</media:title>
		</media:content>

		<media:content url="http://weblogs.asp.net/Themes/default/images/common/star-left-off.gif" medium="image">
			<media:title type="html">star-left-off.gif</media:title>
		</media:content>

		<media:content url="http://weblogs.asp.net/Themes/default/images/common/star-right-off.gif" medium="image">
			<media:title type="html">star-right-off.gif</media:title>
		</media:content>
	</item>
		<item>
		<title>4: Using Style Elements to Better Encapsulate Look and Feel</title>
		<link>http://saadtips.wordpress.com/2009/12/19/4-using-style-elements-to-better-encapsulate-look-and-feel/</link>
		<comments>http://saadtips.wordpress.com/2009/12/19/4-using-style-elements-to-better-encapsulate-look-and-feel/#comments</comments>
		<pubDate>Sat, 19 Dec 2009 18:32:52 +0000</pubDate>
		<dc:creator>saadtips</dc:creator>
				<category><![CDATA[1]]></category>

		<guid isPermaLink="false">http://saadtips.wordpress.com/?p=220</guid>
		<description><![CDATA[Source: http://weblogs.asp.net/scottgu/pages/silverlight-tutorial-part-4-using-style-elements-to-better-encapsulate-look-and-feel.aspx Silverlight Tutorial Part 4: Using Style Elements to Better Encapsulate Look and Feel This is part four of eight tutorials that walk through how to build a simple Digg client application using Silverlight 2. These tutorials are intended to be read in-order, and help explain some of the core programming concepts of Silverlight. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=saadtips.wordpress.com&amp;blog=9673707&amp;post=220&amp;subd=saadtips&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong>Source: <a href="http://weblogs.asp.net/scottgu/pages/silverlight-tutorial-part-4-using-style-elements-to-better-encapsulate-look-and-feel.aspx">http://weblogs.asp.net/scottgu/pages/silverlight-tutorial-part-4-using-style-elements-to-better-encapsulate-look-and-feel.aspx</a> </strong></p>
<p><strong>Silverlight Tutorial Part 4: Using Style Elements to Better Encapsulate Look and Feel </strong></p>
<p>This is <a href="http://weblogs.asp.net/scottgu/pages/silverlight-2-end-to-end-tutorial-building-a-digg-search-client.aspx">part four of eight tutorials</a> that walk through how to build a simple Digg client application using Silverlight 2. These tutorials are intended to be read in-order, and help explain some of the core programming concepts of Silverlight. Bookmark my <a href="http://weblogs.asp.net/scottgu/pages/silverlight-posts.aspx">Silverlight 2 Reference page</a> for more of Silverlight posts and content.</p>
<p><strong>&lt;Download Code&gt;</strong><a href="http://www.scottgu.com/blogposts/slbeta1apps/diggsample.zip">Click here</a> to download a completed version of this Digg client sample. <strong>&lt;/Download Code&gt;</strong></p>
<p><strong>Using Style Elements to Better Encapsulate Look and Feel </strong></p>
<p>WPF and Silverlight support a Style mechanism that allows us to encapsulate control property values as a reusable resource. We can store these style declarations in separate files from our pages, and re-use them across multiple controls and pages in an application (as well as re-use them across multiple applications). This is conceptually similar to using CSS with HTML when doing basic customization scenarios.</p>
<p><em>Note: In addition to defining basic property settings (Color, Font, Size, Margins, etc), styles in WPF and Silverlight can also be used to define and re-use Control Templates &#8211; which enable super rich skinning and adaptation of control structure (and support customization scenarios not possible with CSS in HTML today). I discuss Control Templates in Part 7 of this series.</em></p>
<p>For our Digg sample application we&#8217;ll define our Style declarations within the App.xaml file of our project. This will enable them to be reused across all pages and controls in the application:</p>
<p>Let&#8217;s start by encapsulating styles for the &lt;Border&gt; control (and the &lt;TextBlock&gt; title contained within it) of our Digg page:</p>
<p>We can create two Style elements within our App.xaml file that encapsulate the &lt;Border&gt; and &lt;TextBlock&gt; settings we were previously declaring inline using the markup below:</p>
<p>Note how we are giving each Style a unique &quot;Key&quot; value above. We can then update our &lt;Border&gt; and &lt;TextBlock&gt; controls to reference the Styles using these keys. We&#8217;ll be using a XAML feature called &quot;markup extensions&quot; to do this. Markup extensions are used when there are non-literal values that we want to set (another example of where we&#8217;ll use this feature is with databinding expressions).</p>
<p>When we update the other controls within our Page.xaml file to use styles as well, we are left with a file that looks like below:</p>
<p>Encapsulating the style settings this way allows developers to better focus on the behavior semantics of the application, and also enables us to re-use styles across other controls/pages we build.</p>
<p><strong>Next Steps</strong></p>
<p>Now that we&#8217;ve cleaned up the markup of our Page.xaml file using Style references, let&#8217;s go one step further and customize the appearance of our Story data more.</p>
<p>To-do that let&#8217;s jump to our next tutorial: <a href="http://weblogs.asp.net/scottgu/pages/silverlight-tutorial-part-5-using-the-listbox-and-databinding-to-display-list-data.aspx">Using the ListBox and Databinding to Display List Data</a>.</p>
<br />Posted in 1  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/saadtips.wordpress.com/220/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/saadtips.wordpress.com/220/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/saadtips.wordpress.com/220/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/saadtips.wordpress.com/220/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/saadtips.wordpress.com/220/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/saadtips.wordpress.com/220/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/saadtips.wordpress.com/220/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/saadtips.wordpress.com/220/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/saadtips.wordpress.com/220/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/saadtips.wordpress.com/220/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/saadtips.wordpress.com/220/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/saadtips.wordpress.com/220/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/saadtips.wordpress.com/220/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/saadtips.wordpress.com/220/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=saadtips.wordpress.com&amp;blog=9673707&amp;post=220&amp;subd=saadtips&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://saadtips.wordpress.com/2009/12/19/4-using-style-elements-to-better-encapsulate-look-and-feel/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/16b7fdb6045a11e7ac6f021becbca7bf?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">saadtips</media:title>
		</media:content>
	</item>
		<item>
		<title>Using Style Elements to Better Encapsulate Look and Feel</title>
		<link>http://saadtips.wordpress.com/2009/12/19/using-style-elements-to-better-encapsulate-look-and-feel/</link>
		<comments>http://saadtips.wordpress.com/2009/12/19/using-style-elements-to-better-encapsulate-look-and-feel/#comments</comments>
		<pubDate>Sat, 19 Dec 2009 18:24:48 +0000</pubDate>
		<dc:creator>saadtips</dc:creator>
				<category><![CDATA[1]]></category>

		<guid isPermaLink="false">http://saadtips.wordpress.com/?p=219</guid>
		<description><![CDATA[http://weblogs.asp.net/scottgu/pages/silverlight-tutorial-part-4-using-style-elements-to-better-encapsulate-look-and-feel.aspx Silverlight Tutorial Part 4: Using Style Elements to Better Encapsulate Look and Feel This is part four of eight tutorials that walk through how to build a simple Digg client application using Silverlight 2. These tutorials are intended to be read in-order, and help explain some of the core programming concepts of Silverlight. Bookmark [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=saadtips.wordpress.com&amp;blog=9673707&amp;post=219&amp;subd=saadtips&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong><a href="http://weblogs.asp.net/scottgu/pages/silverlight-tutorial-part-4-using-style-elements-to-better-encapsulate-look-and-feel.aspx">http://weblogs.asp.net/scottgu/pages/silverlight-tutorial-part-4-using-style-elements-to-better-encapsulate-look-and-feel.aspx</a> </strong></p>
<h2>
</h2>
<h2> Silverlight Tutorial Part 4: Using Style Elements to Better Encapsulate Look and Feel </h2>
<p>This is <a href="http://weblogs.asp.net/scottgu/pages/silverlight-2-end-to-end-tutorial-building-a-digg-search-client.aspx">part four of eight tutorials</a> that walk through how to build a simple Digg client application using Silverlight 2. These tutorials are intended to be read in-order, and help explain some of the core programming concepts of Silverlight. Bookmark my <a href="http://weblogs.asp.net/scottgu/pages/silverlight-posts.aspx">Silverlight 2 Reference page</a> for more of Silverlight posts and content.</p>
<p><strong>&lt;Download Code&gt; </strong><a href="http://www.scottgu.com/blogposts/slbeta1apps/diggsample.zip">Click here</a> to download a completed version of this Digg client sample. <strong>&lt;/Download Code&gt;</strong></p>
<h3>Using Style Elements to Better Encapsulate Look and Feel </h3>
<p>WPF and Silverlight support a Style mechanism that allows us to encapsulate control property values as a reusable resource. We can store these style declarations in separate files from our pages, and re-use them across multiple controls and pages in an application (as well as re-use them across multiple applications). This is conceptually similar to using CSS with HTML when doing basic customization scenarios.</p>
<p><em>Note: In addition to defining basic property settings (Color, Font, Size, Margins, etc), styles in WPF and Silverlight can also be used to define and re-use Control Templates &#8211; which enable super rich skinning and adaptation of control structure (and support customization scenarios not possible with CSS in HTML today). I discuss Control Templates in Part 7 of this series.</em></p>
<p>For our Digg sample application we&#8217;ll define our Style declarations within the App.xaml file of our project. This will enable them to be reused across all pages and controls in the application:</p>
<p><img src="http://silverlight1blogpost.s3.amazonaws.com/step65.png" alt="step65.png" /></p>
<p>Let&#8217;s start by encapsulating styles for the &lt;Border&gt; control (and the &lt;TextBlock&gt; title contained within it) of our Digg page:</p>
<p><img src="http://silverlight1blogpost.s3.amazonaws.com/step66.png" alt="step66.png" /></p>
<p><img src="http://silverlight1blogpost.s3.amazonaws.com/step67.png" alt="step67.png" /></p>
<p>We can create two Style elements within our App.xaml file that encapsulate the &lt;Border&gt; and &lt;TextBlock&gt; settings we were previously declaring inline using the markup below:</p>
<p><img src="http://silverlight1blogpost.s3.amazonaws.com/step72.png" alt="step72.png" /></p>
<p>Note how we are giving each Style a unique &quot;Key&quot; value above. We can then update our &lt;Border&gt; and &lt;TextBlock&gt; controls to reference the Styles using these keys. We&#8217;ll be using a XAML feature called &quot;markup extensions&quot; to do this. Markup extensions are used when there are non-literal values that we want to set (another example of where we&#8217;ll use this feature is with databinding expressions).</p>
<p><img src="http://silverlight1blogpost.s3.amazonaws.com/step71.png" alt="step71.png" /></p>
<p>When we update the other controls within our Page.xaml file to use styles as well, we are left with a file that looks like below:</p>
<p><img src="http://silverlight1blogpost.s3.amazonaws.com/step70.png" alt="step70.png" /></p>
<p>Encapsulating the style settings this way allows developers to better focus on the behavior semantics of the application, and also enables us to re-use styles across other controls/pages we build.</p>
<h3>Next Steps</h3>
<p>Now that we&#8217;ve cleaned up the markup of our Page.xaml file using Style references, let&#8217;s go one step further and customize the appearance of our Story data more.</p>
<p>To-do that let&#8217;s jump to our next tutorial: <a href="http://weblogs.asp.net/scottgu/pages/silverlight-tutorial-part-5-using-the-listbox-and-databinding-to-display-list-data.aspx">Using the ListBox and Databinding to Display List Data</a>.</p>
<br />Posted in 1  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/saadtips.wordpress.com/219/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/saadtips.wordpress.com/219/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/saadtips.wordpress.com/219/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/saadtips.wordpress.com/219/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/saadtips.wordpress.com/219/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/saadtips.wordpress.com/219/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/saadtips.wordpress.com/219/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/saadtips.wordpress.com/219/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/saadtips.wordpress.com/219/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/saadtips.wordpress.com/219/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/saadtips.wordpress.com/219/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/saadtips.wordpress.com/219/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/saadtips.wordpress.com/219/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/saadtips.wordpress.com/219/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=saadtips.wordpress.com&amp;blog=9673707&amp;post=219&amp;subd=saadtips&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://saadtips.wordpress.com/2009/12/19/using-style-elements-to-better-encapsulate-look-and-feel/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/16b7fdb6045a11e7ac6f021becbca7bf?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">saadtips</media:title>
		</media:content>

		<media:content url="http://silverlight1blogpost.s3.amazonaws.com/step65.png" medium="image">
			<media:title type="html">step65.png</media:title>
		</media:content>

		<media:content url="http://silverlight1blogpost.s3.amazonaws.com/step66.png" medium="image">
			<media:title type="html">step66.png</media:title>
		</media:content>

		<media:content url="http://silverlight1blogpost.s3.amazonaws.com/step67.png" medium="image">
			<media:title type="html">step67.png</media:title>
		</media:content>

		<media:content url="http://silverlight1blogpost.s3.amazonaws.com/step72.png" medium="image">
			<media:title type="html">step72.png</media:title>
		</media:content>

		<media:content url="http://silverlight1blogpost.s3.amazonaws.com/step71.png" medium="image">
			<media:title type="html">step71.png</media:title>
		</media:content>

		<media:content url="http://silverlight1blogpost.s3.amazonaws.com/step70.png" medium="image">
			<media:title type="html">step70.png</media:title>
		</media:content>
	</item>
		<item>
		<title>Using Networking to Retrieve Data and Populate a DataGrid</title>
		<link>http://saadtips.wordpress.com/2009/12/19/using-networking-to-retrieve-data-and-populate-a-datagrid/</link>
		<comments>http://saadtips.wordpress.com/2009/12/19/using-networking-to-retrieve-data-and-populate-a-datagrid/#comments</comments>
		<pubDate>Sat, 19 Dec 2009 10:53:45 +0000</pubDate>
		<dc:creator>saadtips</dc:creator>
				<category><![CDATA[1]]></category>

		<guid isPermaLink="false">http://saadtips.wordpress.com/?p=211</guid>
		<description><![CDATA[Source: http://weblogs.asp.net/scottgu/pages/silverlight-tutorial-part-3-using-networking-to-retrieve-data-and-populate-a-datagrid.aspx Silverlight Tutorial Part 3: Using Networking to Retrieve Data and Populate a DataGrid This is part three of eight tutorials that walk through how to build a simple Digg client application using Silverlight 2. These tutorials are intended to be read in-order, and help explain some of the core programming concepts of Silverlight. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=saadtips.wordpress.com&amp;blog=9673707&amp;post=211&amp;subd=saadtips&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Source: <a href="http://weblogs.asp.net/scottgu/pages/silverlight-tutorial-part-3-using-networking-to-retrieve-data-and-populate-a-datagrid.aspx">http://weblogs.asp.net/scottgu/pages/silverlight-tutorial-part-3-using-networking-to-retrieve-data-and-populate-a-datagrid.aspx</a></p>
<h2>Silverlight Tutorial Part 3: Using Networking to Retrieve Data and Populate a DataGrid </h2>
<p>This is <a href="http://weblogs.asp.net/scottgu/pages/silverlight-2-end-to-end-tutorial-building-a-digg-search-client.aspx">part three of eight tutorials</a> that walk through how to build a simple Digg client application using Silverlight 2. These tutorials are intended to be read in-order, and help explain some of the core programming concepts of Silverlight. Bookmark my <a href="http://weblogs.asp.net/scottgu/pages/silverlight-posts.aspx">Silverlight 2 Reference page</a> for more of Silverlight posts and content.</p>
<p><strong>&lt;Download Code&gt;</strong><a href="http://www.scottgu.com/blogposts/slbeta1apps/diggsample.zip">Click here</a> to download a completed version of this Digg client sample. <strong>&lt;/Download Code&gt;</strong></p>
<h3>Using Networking to Retrieve Digg Stories </h3>
<p>Silverlight 2 has built-in networking APIs that enable Silverlight clients to call remote REST, SOAP/WS*, RSS, JSON and XML HTTP services. Silverlight 2 also includes a built-in sockets API (System.Net.Sockets) that enables Silverlight clients to communicate over non-HTTP protocols (ideal for scenarios like chat servers, etc).</p>
<p><strong>Cross Domain Network Access</strong></p>
<p>Silverlight 2 applications can always call back to their &quot;origin&quot; server when making network calls (meaning they can call URLs on the same domain that the application was downloaded from). Silverlight 2 applications can also optionally make cross-domain network calls (meaning they can call URLs on different domains from where the application was downloaded from) when the remote web server has an XML policy file in place that indicates that clients are allowed to make these cross-domain calls.</p>
<p>Silverlight 2 defines an XML policy file format that allows server administrators to precisely control what access a client should have. Silverlight 2 also honors the default Flash cross domain policy file format &#8211; which means that you can use Silverlight 2 to call any existing remote REST, SOAP/WS*, RSS, JSON or XML end-point on the web that already enables cross-domain access for Flash clients.</p>
<p>Digg.com has a pretty cool set of <a href="http://apidoc.digg.com/">Digg APIs</a> that they publish over HTTP. Because they have a Flash cross-domain policy file in place on their server, we can call them directly from our Silverlight Digg client application (and not require us to tunnel back through our web-server to reach their APIs).</p>
<p><strong>Digg.com Topic Feed API</strong></p>
<p>We want to enable end-users using our application to type in a search topic (for example: &quot;Programming&quot;) and then click the &quot;Search&quot; button to pull back the top stories from Digg.com that match it:</p>
<p><a href="http://saadtips.files.wordpress.com/2009/12/image0013.png"><img src="http://saadtips.files.wordpress.com/2009/12/image0013.png?w=450&#038;h=214" alt="" title="image0013" width="450" height="214" class="alignnone size-full wp-image-212" /></a></p>
<p>We can use the <a href="http://apidoc.digg.com/ListStories">Digg.com List Stories REST API feed</a> API to-do this. It takes a topic parameter in its URL (for example: GET /stories/topic/programming), and then returns back an XML payload of Digg stories that match that topic. <a href="http://services.digg.com/stories/topic/programming?count=20&amp;appkey=http%3A%2F%2Fscottgu.com">Click here</a> to see an example of what this XML looks like.</p>
<p><strong>Using System.Net.WebClient to Asynchronously Call the Digg REST Feed</strong></p>
<p>When the SearchButton is clicked above, we&#8217;ll handle its &quot;Click&quot; event, retrieve the topic string to search for from the TextBox control, and then initiate a network call to Digg to retrieve the XML listing for that topic.</p>
<p>Silverlight includes the WebClient helper class within the System.Net namespace (this is also in the full .NET Framework). We can use this class to asynchronously download content from a URL. The benefit of downloading our Digg stories asynchronously is that our UI will not block or become unresponsive while waiting on the remote server (allowing us to have a very fluid user experience).</p>
<p>All we need to-do to perform an async download with the WebClient class is to register a &quot;DownloadStringCompleted&quot; event handler method that will be invoked once the requested content has been downloaded, and then call the WebClient.DownloadStringAsync(url) helper method to initiate the download:</p>
<p><a href="http://saadtips.files.wordpress.com/2009/12/image0022.png"><img src="http://saadtips.files.wordpress.com/2009/12/image0022.png?w=450&#038;h=186" alt="" title="image0022" width="450" height="186" class="alignnone size-full wp-image-213" /></a></p>
<p>And with the code above we can now asynchronously retrieve a string of XML data that contains the Digg stores about any topic a user wants.</p>
<h3>Using LINQ to XML to Parse Digg XML Stories into Story Classes</h3>
<p>Now that we can retrieve an XML snippet back of Digg story data, our next step will be to parse and convert it into &quot;DiggStory&quot; objects that we can manipulate and databind our controls against.</p>
<p>We&#8217;ll do this by first defining a &quot;DiggStory&quot; class that has properties that map to the XML content from Digg (we&#8217;ll take advantage of the new C# <a href="http://weblogs.asp.net/scottgu/archive/2007/03/08/new-c-orcas-language-features-automatic-properties-object-initializers-and-collection-initializers.aspx">&quot;automatic properties&quot;</a> feature to-do this):</p>
<p><a href="http://saadtips.files.wordpress.com/2009/12/image0032.png"><img src="http://saadtips.files.wordpress.com/2009/12/image0032.png?w=450&#038;h=300" alt="" title="image0032" width="450" height="300" class="alignnone size-full wp-image-214" /></a></p>
<p>We can then use LINQ (which is built-into Silverlight 2) and LINQ to XML (which is an extra library we can include with our Silverlight application) to easily parse and filter the XML document that was returned from Digg, and translate it into a sequence of &quot;DiggStory&quot; objects using the code below:</p>
<p><a href="http://saadtips.files.wordpress.com/2009/12/image0042.png"><img src="http://saadtips.files.wordpress.com/2009/12/image0042.png?w=450&#038;h=382" alt="" title="image0042" width="450" height="382" class="alignnone size-full wp-image-215" /></a></p>
<p>Notice above how we now have strongly typed DiggStory objects from our XML that we can work against.</p>
<h3>Displaying our Digg Stories in a DataGrid Control</h3>
<p>We&#8217;ll use the Silverlight DataGrid control to display the Digg stories in our application. To enable this we&#8217;ll reference the Silverlight Data controls assembly, and then replace our previous &quot;Todo&quot; text on the page with a DataGrid control declaration (note: you can double click on the &quot;datagrid&quot; control in the toolbox to automatically add one to the page):</p>
<p><img src="http://saadtips.files.wordpress.com/2009/12/image0052.png?w=450&#038;h=46" alt="" title="image0052" width="450" height="46" class="alignnone size-full wp-image-216" /></p>
<p>The DataGrid allows you to explicitly configure column declarations and display types (for maximum control). Alternatively if you do not specify these, the DataGrid control will use reflection on its datasource to create default columns for you based on the schema of your objects.</p>
<p>We&#8217;ll then update our code-behind class to programmatically bind the &quot;ItemSource&quot; property of the DataGrid to the sequence of stories we receive back from Digg when the search button is clicked:</p>
<p><a href="http://saadtips.files.wordpress.com/2009/12/image0062.png"><img src="http://saadtips.files.wordpress.com/2009/12/image0062.png?w=450&#038;h=318" alt="" title="image0062" width="450" height="318" class="alignnone size-full wp-image-217" /></a></p>
<p>And now when we run our Silverlight application and do a search, we&#8217;ll see a listing of live topic story data pulled from Digg:</p>
<p><a href="http://saadtips.files.wordpress.com/2009/12/image0072.png"><img src="http://saadtips.files.wordpress.com/2009/12/image0072.png?w=450&#038;h=244" alt="" title="image0072" width="450" height="244" class="alignnone size-full wp-image-218" /></a></p>
<p>The Silverlight Datagrid supports all the standard features you expect with a client-side grid control: two way in-place editing, selection, scrolling, column resizing, column re-ordering, etc. It also supports auto-flow layout, which means it can dynamically expand or shrink to fill the content container it is in. The DataGrid also has a rich templating model that allows you to customize both the display and editing of column data.</p>
<h3>Next Steps</h3>
<p>We can now retrieve Digg story data from Digg.com and display the story data within our application.</p>
<p>Our next step will be to go back to our Page.xaml markup and remove the in-line style declarations we are currently using there.</p>
<p>To-do that let&#8217;s jump to our next tutorial: <a href="http://weblogs.asp.net/scottgu/pages/silverlight-tutorial-part-4-using-style-elements-to-better-encapsulate-look-and-feel.aspx">Using Style Elements to Better Encapsulate Look and Feel</a>.</p>
<br />Posted in 1  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/saadtips.wordpress.com/211/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/saadtips.wordpress.com/211/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/saadtips.wordpress.com/211/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/saadtips.wordpress.com/211/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/saadtips.wordpress.com/211/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/saadtips.wordpress.com/211/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/saadtips.wordpress.com/211/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/saadtips.wordpress.com/211/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/saadtips.wordpress.com/211/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/saadtips.wordpress.com/211/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/saadtips.wordpress.com/211/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/saadtips.wordpress.com/211/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/saadtips.wordpress.com/211/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/saadtips.wordpress.com/211/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=saadtips.wordpress.com&amp;blog=9673707&amp;post=211&amp;subd=saadtips&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://saadtips.wordpress.com/2009/12/19/using-networking-to-retrieve-data-and-populate-a-datagrid/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/16b7fdb6045a11e7ac6f021becbca7bf?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">saadtips</media:title>
		</media:content>

		<media:content url="http://saadtips.files.wordpress.com/2009/12/image0013.png" medium="image">
			<media:title type="html">image0013</media:title>
		</media:content>

		<media:content url="http://saadtips.files.wordpress.com/2009/12/image0022.png" medium="image">
			<media:title type="html">image0022</media:title>
		</media:content>

		<media:content url="http://saadtips.files.wordpress.com/2009/12/image0032.png" medium="image">
			<media:title type="html">image0032</media:title>
		</media:content>

		<media:content url="http://saadtips.files.wordpress.com/2009/12/image0042.png" medium="image">
			<media:title type="html">image0042</media:title>
		</media:content>

		<media:content url="http://saadtips.files.wordpress.com/2009/12/image0052.png" medium="image">
			<media:title type="html">image0052</media:title>
		</media:content>

		<media:content url="http://saadtips.files.wordpress.com/2009/12/image0062.png" medium="image">
			<media:title type="html">image0062</media:title>
		</media:content>

		<media:content url="http://saadtips.files.wordpress.com/2009/12/image0072.png" medium="image">
			<media:title type="html">image0072</media:title>
		</media:content>
	</item>
		<item>
		<title>Best Explanations: 1- Creating &#8220;Hello World&#8221; with Silverlight 2 and VS 2008</title>
		<link>http://saadtips.wordpress.com/2009/12/19/best-explanations-1-creating-hello-world-with-silverlight-2-and-vs-2008/</link>
		<comments>http://saadtips.wordpress.com/2009/12/19/best-explanations-1-creating-hello-world-with-silverlight-2-and-vs-2008/#comments</comments>
		<pubDate>Sat, 19 Dec 2009 06:25:11 +0000</pubDate>
		<dc:creator>saadtips</dc:creator>
				<category><![CDATA[1]]></category>

		<guid isPermaLink="false">http://saadtips.wordpress.com/?p=198</guid>
		<description><![CDATA[Source: http://weblogs.asp.net/scottgu/pages/silverlight-tutorial-part-1-creating-quot-hello-world-quot-with-silverlight-2-and-vs-2008.aspx Silverlight Tutorial Part 1: Creating &#34;Hello World&#34; with Silverlight 2 and VS 2008 This is part one of eight tutorials that walk through how to build a simple Digg client application using Silverlight 2. These tutorials are intended to be read in-order, and help explain some of the core programming concepts of Silverlight. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=saadtips.wordpress.com&amp;blog=9673707&amp;post=198&amp;subd=saadtips&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h2>Source: <a href="http://weblogs.asp.net/scottgu/pages/silverlight-tutorial-part-1-creating-quot-hello-world-quot-with-silverlight-2-and-vs-2008.aspx">http://weblogs.asp.net/scottgu/pages/silverlight-tutorial-part-1-creating-quot-hello-world-quot-with-silverlight-2-and-vs-2008.aspx</a></h2>
<h2>Silverlight Tutorial Part 1: Creating &quot;Hello World&quot; with Silverlight 2 and VS 2008 </h2>
<p>This is <a href="http://weblogs.asp.net/scottgu/pages/silverlight-2-end-to-end-tutorial-building-a-digg-search-client.aspx">part one of eight tutorials</a> that walk through how to build a simple Digg client application using Silverlight 2. These tutorials are intended to be read in-order, and help explain some of the core programming concepts of Silverlight.</p>
<p><strong>&lt;Download Code&gt;</strong><a href="http://www.scottgu.com/blogposts/slbeta1apps/diggsample.zip">Click here</a> to download a completed version of this Digg client sample. Bookmark my <a href="http://weblogs.asp.net/scottgu/pages/silverlight-posts.aspx">Silverlight 2 Reference page</a> for more of Silverlight posts and content. <strong>&lt;/Download Code&gt;</strong></p>
<h3>Creating a New Silverlight Application using VS 2008</h3>
<p>We&#8217;ll start our Digg application by selecting the File-&gt;New Project menu item within Visual Studio 2008 or Visual Web Developer 2008 Express (which is free) and use the New Project dialog to create a &quot;Silverlight Application&quot; (note: you will need to download and install the Silverlight Tools for VS 2008 release to get this support):</p>
<p><a href="http://saadtips.files.wordpress.com/2009/12/image0012.png"><img src="http://saadtips.files.wordpress.com/2009/12/image0012.png?w=450&#038;h=302" alt="" title="image0012" width="450" height="302" class="alignnone size-full wp-image-199" /></a></p>
<p>We&#8217;ll name the project &quot;DiggSample&quot;. When we click the &quot;OK&quot; button Visual Studio will prompt us with an additional dialog that allows us to choose whether we want to create just a Silverlight Application project, or optionally also add a server-side ASP.NET Web project to our solution to host the Silverlight Application within. For this sample we&#8217;ll choose to add an ASP.NET Web Application project to the solution as well and name it &quot;DiggSample_WebServer&quot;. When we click &quot;ok&quot; Visual Studio will create a solution for us that has both a Silverlight client application and an ASP.NET web server application in it:</p>
<p><a href="http://saadtips.files.wordpress.com/2009/12/image0021.png"><img src="http://saadtips.files.wordpress.com/2009/12/image0021.png?w=233&#038;h=324" alt="" title="image0021" width="233" height="324" class="alignnone size-full wp-image-200" /></a></p>
<p>When we do a &quot;build&quot; Visual Studio will automatically copy the compiled Silverlight application to our web server project (no manual step or configuration required). The default web server project that VS created for us contains both an ASP.NET page and a static HTML page that we can use to run and test our Silverlight Application within.</p>
<p><em>Note: Silverlight Applications can be used with any web-server (including Apache on Linux) and hosted within static HTML files or any server-side generated page (including PHP, Java, Python, Ruby, etc). For this Digg sample we won&#8217;t be writing any server-side code &#8211; we&#8217;ll instead use the cross-domain networking feature of Silverlight to access the Digg service API directly. I chose to create the ASP.NET web server project mainly to get automatic deployment and use its built-in web-server for testing.</em></p>
<h3>Understanding What Is In a Silverlight Application</h3>
<p>By default a newly created Silverlight application project contains a Page.xaml and App.xaml file, as well as code behind class files (which can be written in VB, C#, Ruby or Python) that are associated with them:</p>
<p><a href="http://saadtips.files.wordpress.com/2009/12/image0031.png"><img src="http://saadtips.files.wordpress.com/2009/12/image0031.png?w=225&#038;h=260" alt="" title="image0031" width="225" height="260" class="alignnone size-full wp-image-201" /></a></p>
<p>XAML files are XML text files that can be used to declaratively specify the UI of a Silverlight or WPF application. XAML can also be used more broadly to declaratively represent .NET objects.</p>
<p>The App.xaml file is typically used to declare resources, such as brush and style objects that are shared across the application. The Application code-behind class for the App.xaml file can be used to handle application level events &#8211; like Application_Startup, Application_Exit and Application_UnhandledException.</p>
<p>The Page.xaml file is by default the initial UI control that is loaded when the application activates. Within it we can use UI controls to define our user interface, and then handle events off of them within the Page code-behind class (much more on this later).</p>
<p>When we build our DiggSample project, Visual Studio will by default compile the code and .XAML markup into a standard .NET assembly file, and then package it and any static resources (like images or static files we want to include in it) into a &quot;DiggSample.xap&quot; file on disk:</p>
<p><a href="http://saadtips.files.wordpress.com/2009/12/image0041.png"><img src="http://saadtips.files.wordpress.com/2009/12/image0041.png?w=450&#038;h=226" alt="" title="image0041" width="450" height="226" class="alignnone size-full wp-image-202" /></a></p>
<p>&quot;.xap&quot; files (pronounced &quot;zap&quot;) use the standard .zip compression algorithm to minimize client download size. A &quot;hello world&quot; .NET Silverlight application (built using VB or C#) is about 4KB in size.</p>
<p>To host and run a Silverlight 2 application, you can add an &lt;object&gt; tag into any standard HTML page (no JavaScript required) that points to the .xap file. Silverlight will then automatically download the .xap file, instantiate it, and host it within that HTML page in the browser. This works cross browser (Safari, FireFox, IE, etc) and cross platform (Windows, Mac, and Linux).</p>
<p>Test HTML and ASP.NET pages (containing the &lt;object&gt; tag reference that points to our Silverlight application) were automatically added for us when we created our project &#8211; which means we can just hit F5 to build, run and test it.</p>
<h3>Learning how to Add Controls and Handle Events</h3>
<p>Right now our Digg application doesn&#8217;t do anything, and when it is run it brings up an empty page.</p>
<p>We can change this by opening up the Page.xaml file in the project and adding some content to it:</p>
<p><a href="http://saadtips.files.wordpress.com/2009/12/image0051.png"><img src="http://saadtips.files.wordpress.com/2009/12/image0051.png?w=450&#038;h=358" alt="" title="image0051" width="450" height="358" class="alignnone size-full wp-image-203" /></a></p>
<p>We&#8217;ll begin by changing the background of the grid and by declaring a Button control within it. We&#8217;ll give the button an &quot;x:Name&quot; attribute value of &quot;MyButton&quot; &#8211; which will allow us to programmatically reference it within our code-behind class. We&#8217;ll also set its Content, Width and Height properties:</p>
<p><a href="http://saadtips.files.wordpress.com/2009/12/image0061.png"><img src="http://saadtips.files.wordpress.com/2009/12/image0061.png?w=450&#038;h=155" alt="" title="image0061" width="450" height="155" class="alignnone size-full wp-image-204" /></a></p>
<p>When we run the application our button will then show up in the middle of the page with &quot;Push Me&quot; content text like below:</p>
<p><a href="http://saadtips.files.wordpress.com/2009/12/image0071.png"><img src="http://saadtips.files.wordpress.com/2009/12/image0071.png?w=425&#038;h=416" alt="" title="image0071" width="425" height="416" class="alignnone size-full wp-image-205" /></a></p>
<p>To add behavior to our button we can add a &quot;Click&quot; event handler to it. We can do this in source view by typing the event name:</p>
<p><a href="http://saadtips.files.wordpress.com/2009/12/image0081.png"><img src="http://saadtips.files.wordpress.com/2009/12/image0081.png?w=450&#038;h=133" alt="" title="image0081" width="450" height="133" class="alignnone size-full wp-image-206" /></a></p>
<p>Which will then prompt us for the event handler in our code-behind class to use:</p>
<p><a href="http://saadtips.files.wordpress.com/2009/12/image0091.png"><img src="http://saadtips.files.wordpress.com/2009/12/image0091.png?w=450&#038;h=48" alt="" title="image0091" width="450" height="48" class="alignnone size-full wp-image-207" /></a></p>
<p>We can then either type a new event handler method name to use, or optionally just press the enter key to name the event handler method using the default naming convention:</p>
<p><img src="http://saadtips.files.wordpress.com/2009/12/image0101.png?w=450&#038;h=28" alt="" title="image0101" width="450" height="28" class="alignnone size-full wp-image-208" /></p>
<p>VS will then automatically create a stub event handler implementation in our code-behind class file. We can use this event handler to update the Button&#8217;s content with a new message when it is clicked:</p>
<p><a href="http://saadtips.files.wordpress.com/2009/12/image0111.png"><img src="http://saadtips.files.wordpress.com/2009/12/image0111.png?w=450&#038;h=337" alt="" title="image0111" width="450" height="337" class="alignnone size-full wp-image-209" /></a></p>
<p>After making the change above we can re-run the application and push the button again, and now its content is updated with a &quot;Pushed!&quot; message:</p>
<p><a href="http://saadtips.files.wordpress.com/2009/12/image0121.png"><img src="http://saadtips.files.wordpress.com/2009/12/image0121.png?w=423&#038;h=415" alt="" title="image0121" width="423" height="415" class="alignnone size-full wp-image-210" /></a></p>
<br />Posted in 1  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/saadtips.wordpress.com/198/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/saadtips.wordpress.com/198/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/saadtips.wordpress.com/198/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/saadtips.wordpress.com/198/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/saadtips.wordpress.com/198/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/saadtips.wordpress.com/198/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/saadtips.wordpress.com/198/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/saadtips.wordpress.com/198/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/saadtips.wordpress.com/198/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/saadtips.wordpress.com/198/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/saadtips.wordpress.com/198/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/saadtips.wordpress.com/198/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/saadtips.wordpress.com/198/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/saadtips.wordpress.com/198/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=saadtips.wordpress.com&amp;blog=9673707&amp;post=198&amp;subd=saadtips&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://saadtips.wordpress.com/2009/12/19/best-explanations-1-creating-hello-world-with-silverlight-2-and-vs-2008/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/16b7fdb6045a11e7ac6f021becbca7bf?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">saadtips</media:title>
		</media:content>

		<media:content url="http://saadtips.files.wordpress.com/2009/12/image0012.png" medium="image">
			<media:title type="html">image0012</media:title>
		</media:content>

		<media:content url="http://saadtips.files.wordpress.com/2009/12/image0021.png" medium="image">
			<media:title type="html">image0021</media:title>
		</media:content>

		<media:content url="http://saadtips.files.wordpress.com/2009/12/image0031.png" medium="image">
			<media:title type="html">image0031</media:title>
		</media:content>

		<media:content url="http://saadtips.files.wordpress.com/2009/12/image0041.png" medium="image">
			<media:title type="html">image0041</media:title>
		</media:content>

		<media:content url="http://saadtips.files.wordpress.com/2009/12/image0051.png" medium="image">
			<media:title type="html">image0051</media:title>
		</media:content>

		<media:content url="http://saadtips.files.wordpress.com/2009/12/image0061.png" medium="image">
			<media:title type="html">image0061</media:title>
		</media:content>

		<media:content url="http://saadtips.files.wordpress.com/2009/12/image0071.png" medium="image">
			<media:title type="html">image0071</media:title>
		</media:content>

		<media:content url="http://saadtips.files.wordpress.com/2009/12/image0081.png" medium="image">
			<media:title type="html">image0081</media:title>
		</media:content>

		<media:content url="http://saadtips.files.wordpress.com/2009/12/image0091.png" medium="image">
			<media:title type="html">image0091</media:title>
		</media:content>

		<media:content url="http://saadtips.files.wordpress.com/2009/12/image0101.png" medium="image">
			<media:title type="html">image0101</media:title>
		</media:content>

		<media:content url="http://saadtips.files.wordpress.com/2009/12/image0111.png" medium="image">
			<media:title type="html">image0111</media:title>
		</media:content>

		<media:content url="http://saadtips.files.wordpress.com/2009/12/image0121.png" medium="image">
			<media:title type="html">image0121</media:title>
		</media:content>
	</item>
		<item>
		<title>Silverlight User Interface Controls</title>
		<link>http://saadtips.wordpress.com/2009/12/16/silverlight-user-interface-controls/</link>
		<comments>http://saadtips.wordpress.com/2009/12/16/silverlight-user-interface-controls/#comments</comments>
		<pubDate>Wed, 16 Dec 2009 08:14:52 +0000</pubDate>
		<dc:creator>saadtips</dc:creator>
				<category><![CDATA[1]]></category>

		<guid isPermaLink="false">http://saadtips.wordpress.com/?p=182</guid>
		<description><![CDATA[Source: http://www.silverlight.net/learn/tutorials/controls-cs/ Silverlight has over 3 dozen User Interface (UI) controls. .NET programmers already familiar with ASP.Net or (especially) WPF, will find using the Silverlight controls very natural and straight forward. Figure 1-1. Silverlight Controls (split in two to make it easier to view) Silverlight controls were created to look great and provide extensive and [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=saadtips.wordpress.com&amp;blog=9673707&amp;post=182&amp;subd=saadtips&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Source: <a href="http://www.silverlight.net/learn/tutorials/controls-cs/">http://www.silverlight.net/learn/tutorials/controls-cs/</a></p>
<p>Silverlight has over 3 dozen User Interface (UI) controls. .NET programmers already familiar with ASP.Net or (especially) WPF, will find using the Silverlight controls very natural and straight forward.</p>
<p><a href="http://saadtips.files.wordpress.com/2009/12/image0011.png"><img src="http://saadtips.files.wordpress.com/2009/12/image0011.png?w=334&#038;h=401" alt="" title="image0011" width="334" height="401" class="alignnone size-full wp-image-183" /></a></p>
<p>Figure 1-1. Silverlight Controls (split in two to make it easier to view)</p>
<p>Silverlight controls were created to look great and provide extensive and customizable functionality right out of the box. Moreover, all of the standard controls can be modified in numerous ways to meet your needs.</p>
<p>The look and feel of the control can be tweaked through styles or can be entirely redesigned through templates, and the behavior of the controls can be modified through event handlers. In the rare cases when none of that is enough, you can create (or derive) your own customized controls as well.</p>
<p>This tutorial will cover event handlers. Styles, Templates and Custom Controls will be covered in future tutorials. .</p>
<p>A Note On The Design Surface</p>
<p>The current Visual Studio design surface is read-only. That is, you can drag and drop controls into the markup (or write the Xaml by hand) and the effects are seen immediately in the design surface, but you cannot yet drag or otherwise manipulate controls directly in design mode.</p>
<p>That is a temporary limitation. For now, one alternative is to use Expression Blend, and we have a full tutorial on <a href="http://silverlight.net/learn/tutorials/ExpressionBlendforDevelopers.aspx">Blend for Programmers</a> that shows how to work with the two environments together.</p>
<p>Note that controls can also be created dynamically (in code, at run time) as explained at the end of this tutorial.</p>
<p>Layout Controls</p>
<p>The use of layout controls is both straight-forward and essential to the creation of Silverlight applications. Layout controls are used to manage the placement of other controls (including other layout controls!) in your Silverlight application. You can think of the layout controls as &quot;containers.&quot;</p>
<p>The three Layout controls you&#8217;ll use most often are:</p>
<p>Grid &#8211; essentially a table used for positioning objects in rows and columns.</p>
<p>StackPanel &#8211; used to position objects next to one another, or atop one another.</p>
<p>Canvas &#8211; used for absolute positioning (and unchanged from Silverlight 1.0)</p>
<p>They are listed in the order of how frequently they are used. And to be honest, if you learn Grid and StackPanel, you can probably program for a long time on just those two.</p>
<p>Grids</p>
<p>Grids (not to be confused with DataGrids) offer easy and exact placement by providing a table-like structure. You declare rows and columns, and then place controls into a specific row/column location (spanning across rows or columns as needed).</p>
<p>While you can tweak your grids to achieve very precise placement, the basic use of grids is extremely straight forward.</p>
<p>You typically declare a grid, declare its rows and columns and then start placing controls into specific cells (e.g., column 1, row 3). To see this at work, let&#8217;s create our first Silverlight Application: Easy Grid.</p>
<p>Creating The First Example &#8211; A Grid With Controls</p>
<p>Open Visual Studio 2008 and click on Create Project and then in the new project window you&#8217;ll want to create a C# project using the Silverlight Application Template.</p>
<p>Pick a location for your application and give it a meaningful name; be sure that you are building against the latest framework.</p>
<p><a href="http://www.silverlight.net/content/learn/tutorials/Beta2Tutorial1_2x.png"><a href="http://saadtips.files.wordpress.com/2009/12/image002.png"><img src="http://saadtips.files.wordpress.com/2009/12/image002.png?w=450&#038;h=302" alt="" title="image002" width="450" height="302" class="alignnone size-full wp-image-184" /></a></p>
<p></a></p>
<p>Figure 1-2. Creating A New Silverlight Project <a href="http://www.silverlight.net/content/learn/tutorials/Beta2Tutorial1_2x.png">(Click to view full-size image)</a></p>
<p>When you click OK you will next be asked if you&#8217;d like to generate a Web Site or a Web Application (using the top radio button) or just a test page (using the bottom radio button) or if you&#8217;d like to link to an existing web site; all as shown in the next figure.</p>
<p><a href="http://saadtips.files.wordpress.com/2009/12/image003.png"><img src="http://saadtips.files.wordpress.com/2009/12/image003.png?w=450&#038;h=399" alt="" title="image003" width="450" height="399" class="alignnone size-full wp-image-185" /></a></p>
<p>Figure 1-3. Choose Simple HTML Test Page</p>
<p>If you create just a test page, the project is kept very simple, but if you generate a Web Site or Web Application Project, then Visual Studio creates two projects in your new solution; the Silverlight Application and a test application; excellent for test-based programming but more than we need right now.</p>
<p>Choose the second radio button (Test Page) and let Visual Studio create a simple application for you. If Page.xaml doesn&#8217;t open automatically, double click on it in the Solution Explorer. You should find that Visual Studio has guessed that you want a grid as your main container, and has created one for you and named it LayoutRoot. (Also note that the very first declaration in each &quot;page&quot; is a UserControl.</p>
<p>&lt;UserControl x:Class=&quot;EasyGrid.Page&quot;<br />
xmlns=&quot;<a href="http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;">http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;</a><br />
xmlns:x=&quot;<a href="http://schemas.microsoft.com/winfx/2006/xaml&quot;">http://schemas.microsoft.com/winfx/2006/xaml&quot;</a><br />
Width=&quot;400&quot; Height=&quot;300&quot;&gt;</p>
<p>In fact a Page is a UserControl, and we&#8217;ll return to that relationship in a later tutorial.</p>
<p>The Grid definition created by Visual Studio 2008 looks like this:</p>
<p>&lt;Grid x:Name=&quot;LayoutRoot&quot; Background=&quot;White&quot;&gt;<br />
&lt;/Grid&gt;</p>
<p>Many times, your entire application will go between the opening and closing Grid tags; other times you’ll replace the Grid with another container.</p>
<p>Defining Rows And Properties</p>
<p>You define the Rows for a table inside the Grid.RowDefinitions element. For each Row, you add a RowDefinition element, which itself may have various properties, including a specific height, or if you prefer you may set the height to be proportional to the available space or to take all the space not taken by other rows.</p>
<p>&lt;Grid x:Name=&quot;LayoutRoot&quot; Background=&quot;White&quot;&gt;<br />
&lt;Grid.RowDefinitions&gt;<br />
&lt;RowDefinition Height=&quot;50&quot; /&gt;<br />
&lt;RowDefinition Height=&quot;30*&quot; MaxHeight=&quot;70&quot; /&gt;<br />
&lt;RowDefinition Height=&quot;40*&quot; MaxHeight=&quot;70&quot; /&gt;<br />
&lt;RowDefinition Height=&quot;*&quot; MinHeight=&quot;30&quot; MaxHeight=&quot;50&quot; /&gt;<br />
&lt;RowDefinition Height=&quot;Auto&quot; MinHeight=&quot;5&quot; MaxHeight=&quot;30&quot; /&gt;<br />
&lt;/Grid.RowDefinitions&gt;<br />
&lt;/Grid&gt;</p>
<p>Height=&quot;Auto&quot;</p>
<p>With Auto, the Grid’s space is distributed evenly based on the size of the content within the row.</p>
<p>Star or Proportional Sizing</p>
<p>In proportional sizing the value of a column or row is expressed in Xaml as *.</p>
<p>&lt;RowDefinition Height=&quot;*&quot;</p>
<p>However, you can give twice the space to one column or row as another by using 2* (or a 5:7 ration by using 5* and 7*).</p>
<p>&lt;RowDefinition Height=&quot;30*&quot;<br />
&lt;RowDefinition Height=&quot;40*&quot;</p>
<p>If you combine this with a Minimum or Maximum Height you get finer control over the limits of the row&#8217;s range of sizes,</p>
<p>&lt;RowDefinition Height=&quot;30*&quot; MaxHeight=&quot;70&quot; /&gt;<br />
&lt;RowDefinition Height=&quot;40*&quot; MaxHeight=&quot;70&quot; /&gt;<br />
&lt;RowDefinition Height=&quot;*&quot; MinHeight=&quot;30&quot; MaxHeight=&quot;50&quot; /&gt;</p>
<p>Minimal or Controlled space</p>
<p>By default child elements of grid take up the least amount of space necessary to to accommodate the largest content within a cell in a given row or column. You can take greater control over positioning, however, by using the margin and alignment properties as described below</p>
<p>Sizing Units</p>
<p>To provide the most flexibility, Grid columns and rows are sized by GridLength objects which use the GridUnitType, which in turn allows you to choose among:</p>
<p>Auto (size based on the size properties of the object being placed in the grid)</p>
<p>Pixel (size in pixels)</p>
<p>Star (size based on a weighted proportion of the available space)</p>
<p>designating, if we choose, the minimum and maximum dimensions of each.</p>
<p>To see the effect of all this we&#8217;ll create five rows using different sizing rules. We&#8217;ll also create three columns with no sizing rules at all (!). We&#8217;ll then fill our grid with controls and take a look at some of the effects. Here is the code, which we&#8217;ll take apart piece by piece.</p>
<p>Example 1-1. The Xaml for EasyGrid</p>
<p>&lt;UserControl x:Class=&quot;EasyGrid.Page&quot;<br />
xmlns=&quot;<a href="http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;">http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;</a><br />
xmlns:x=&quot;<a href="http://schemas.microsoft.com/winfx/2006/xaml&quot;">http://schemas.microsoft.com/winfx/2006/xaml&quot;</a><br />
Width=&quot;400&quot; Height=&quot;300&quot;&gt;<br />
&lt;Grid x:Name=&quot;LayoutRoot&quot; Background=&quot;White&quot;&gt;<br />
&lt;Grid.RowDefinitions&gt;<br />
&lt;RowDefinition Height=&quot;50&quot; /&gt;<br />
&lt;RowDefinition Height=&quot;30*&quot; MaxHeight=&quot;70&quot; /&gt;<br />
&lt;RowDefinition Height=&quot;40*&quot; MaxHeight=&quot;70&quot; /&gt;<br />
&lt;RowDefinition Height=&quot;*&quot; MinHeight=&quot;30&quot; MaxHeight=&quot;50&quot; /&gt;<br />
&lt;RowDefinition Height=&quot;Auto&quot; MinHeight=&quot;5&quot; MaxHeight=&quot;30&quot; /&gt;<br />
&lt;/Grid.RowDefinitions&gt;<br />
&lt;Grid.ColumnDefinitions&gt;<br />
&lt;ColumnDefinition /&gt;<br />
&lt;ColumnDefinition /&gt;<br />
&lt;ColumnDefinition /&gt;<br />
&lt;/Grid.ColumnDefinitions&gt;</p>
<p>&lt;TextBlock x:Name=&quot;FirstNamePrompt &quot;<br />
Grid.Row=&quot;0&quot; Grid.Column=&quot;0&quot; Text=&quot;First Name:&quot; Margin=&quot;5&quot;/&gt;<br />
&lt;TextBox x:Name=&quot;FirstName&quot;<br />
Grid.Row=&quot;0&quot; Grid.Column=&quot;1&quot; Grid.ColumnSpan=&quot;2&quot;<br />
Width=&quot;150&quot; Background=&quot;Bisque&quot; Margin=&quot;5&quot; /&gt;</p>
<p>&lt;TextBlock x:Name=&quot;LastNamePrompt &quot;<br />
Grid.Row=&quot;1&quot; Grid.Column=&quot;0&quot; Text=&quot;First Name:&quot; Margin=&quot;5&quot;/&gt;<br />
&lt;TextBox x:Name=&quot;LastName&quot;<br />
Grid.Row=&quot;1&quot; Grid.Column=&quot;1&quot; Grid.ColumnSpan=&quot;2&quot;<br />
Width=&quot;150&quot; Background=&quot;Beige&quot; Margin=&quot;5&quot; /&gt;</p>
<p>&lt;TextBlock x:Name=&quot;SubscriberPrompt&quot;<br />
Grid.Row=&quot;2&quot; Grid.Column=&quot;0&quot;<br />
Text=&quot;Subscriber?&quot; VerticalAlignment=&quot;Bottom&quot; /&gt;<br />
&lt;CheckBox x:Name=&quot;PlanA&quot; Grid.Row=&quot;2&quot; Grid.Column=&quot;1&quot;<br />
Content=&quot;Plan A&quot; IsChecked=&quot;true&quot;<br />
VerticalAlignment=&quot;Bottom&quot; /&gt;<br />
&lt;CheckBox x:Name=&quot;PlanB&quot; Grid.Row=&quot;2&quot; Grid.Column=&quot;2&quot;<br />
Content=&quot;Plan B&quot; VerticalAlignment=&quot;Bottom&quot; /&gt;</p>
<p>&lt;TextBlock x:Name=&quot;Hello&quot; Text=&quot;Hello&quot;<br />
Grid.Row=&quot;3&quot; Grid.Column=&quot;2&quot; VerticalAlignment=&quot;Bottom&quot;/&gt;</p>
<p>&lt;TextBlock x:Name=&quot;World&quot; Text=&quot;World&quot;<br />
Grid.Row=&quot;4&quot; Grid.Column=&quot;2&quot; VerticalAlignment=&quot;Bottom&quot;<br />
FontFamily=&quot;Comic Sans MS&quot; FontSize=&quot;24&quot;<br />
FontWeight=&quot;Bold&quot; Margin=&quot;0,20,0,0&quot;/&gt;<br />
&lt;/Grid&gt;<br />
&lt;/UserControl&gt;</p>
<p>The result of the Xaml code is shown in</p>
<p><a href="http://saadtips.files.wordpress.com/2009/12/image004.png"><img src="http://saadtips.files.wordpress.com/2009/12/image004.png?w=427&#038;h=323" alt="" title="image004" width="427" height="323" class="alignnone size-full wp-image-186" /></a></p>
<p>Figure 1-4. The Xaml as Design</p>
<p>First, it is important to understand that the Xaml shown in Example 1-1 is all that is needed to produce the Silverlight control shown in Figure 1-4. It is true that you can&#8217;t see the rows and columns, but that is easily remedied. Find the declaration of the Grid and set its ShowGridLines property to True (Intellisense will help as shown inFigure 1-5</p>
<p><a href="http://www.silverlight.net/content/learn/tutorials/Beta2Tutorial1_5x.png"><a href="http://saadtips.files.wordpress.com/2009/12/image005.png"><img src="http://saadtips.files.wordpress.com/2009/12/image005.png?w=450&#038;h=185" alt="" title="image005" width="450" height="185" class="alignnone size-full wp-image-187" /></a></p>
<p></a></p>
<p>Figure 1-5. Adding Property ShowGridLines and setting it True <a href="http://www.silverlight.net/content/learn/tutorials/Beta2Tutorial1_5x.png">(Click to view full-size image)</a></p>
<p>When you do, the grid lines become visible; which can be very useful during design, as long as you remember to set the property to false before you post your Silverlight application!</p>
<p><a href="http://www.silverlight.net/content/learn/tutorials/Beta2Tutorial1_6x.png"><a href="http://saadtips.files.wordpress.com/2009/12/image006.png"><img src="http://saadtips.files.wordpress.com/2009/12/image006.png?w=450&#038;h=333" alt="" title="image006" width="450" height="333" class="alignnone size-full wp-image-188" /></a></p>
<p></a></p>
<p>Figure 1-6. ShowGridLines Makes The Alignment Very Visible <a href="http://www.silverlight.net/content/learn/tutorials/Beta2Tutorial1_6x.png">(Click to view full-size image)</a></p>
<p>Unpacking the Xaml</p>
<p>The first lines create the Grid and define how the rows will share the space.</p>
<p>&lt;Grid x:Name=&quot;LayoutRoot&quot; Background=&quot;White&quot; ShowGridLines=&quot;True&quot; &gt;<br />
&lt;Grid.RowDefinitions&gt;<br />
&lt;RowDefinition Height=&quot;50&quot; /&gt;<br />
&lt;RowDefinition Height=&quot;30*&quot; MaxHeight=&quot;70&quot; /&gt;<br />
&lt;RowDefinition Height=&quot;40*&quot; MaxHeight=&quot;70&quot; /&gt;<br />
&lt;RowDefinition Height=&quot;*&quot; MinHeight=&quot;30&quot; MaxHeight=&quot;50&quot; /&gt;<br />
&lt;RowDefinition Height=&quot;Auto&quot; MinHeight=&quot;5&quot; MaxHeight=&quot;30&quot; /&gt;<br />
&lt;/Grid.RowDefinitions&gt;</p>
<p>As described above, the RowDefinitions define five rows. The first has a fixed height of 50. The second and third will float, but in a 3:4 proportion with one another, but each with a maximum height of 70. The next row will take all the remaining space, but will never be allowed to shrink to less than 30 nor grow to more than 50. The final row will size itself to the object placed in the row, but yet is constrained to no less than 5 and no more than 30.</p>
<p>After the column definitions we define a TextBlock and a TextBox. We&#8217;ll discuss these controls in more depth later, but the former is typically used as a label and the latter is used to allow the user to put in text.</p>
<p>&lt;TextBlock<br />
x:Name=&quot;FirstNamePrompt &quot;<br />
Grid.Row=&quot;0&quot;<br />
Grid.Column=&quot;0&quot;<br />
Text=&quot;First Name:&quot;<br />
Margin=&quot;5&quot;/&gt;</p>
<p>The TextBlock has five parameters. They can be aligned one below the other, or strung out all in a line, any way you like. The first parameter is the name (FirstNamePrompt) and is used to allow you to address the object in code. If you give an object in Xaml a name, and save the file, that object is available with no further declaration in your methods</p>
<p>Thus, if you save this file, you will be free to write</p>
<p>FirstNamePrompt.Text=”Hello”</p>
<p>From any method of this class, and the compiler will know exactly what you mean!</p>
<p>The Grid.Row and Grid.Column properties are called extended properties and are really &quot;borrowed&quot; from the immediately surrounding grid to position the TextBlock inside the appropriate cell.</p>
<p>The Text property does just what you expect, it fills the TextBlock with that text.</p>
<p>Margin is a fascinating property, and we&#8217;ll return to it a couple times. For now, I&#8217;ll mention that it takes three forms:</p>
<p>A single value, which gives a margin of that value &quot;all around&quot; &#8211; that is left, right, top and bottom</p>
<p>Two values in which case the first is divided evenly among the left and right margin and the second is divided evenly among the top and bottom</p>
<p>Four values, in the order Left, Top, Right, Bottom.</p>
<p>The TextBlock label in the first column is followed by an (input) TextBox in the second column. The properties are very similar except that you must declare the width of your TextBox and we choose here to give the TextBox a background color.</p>
<p>The next pair are much like the first.</p>
<p>The third row is filled by a TextBlock and two CheckBox controls. Note that they are aligned by setting their VerticalAlignment properties and that the first CheckBox has its IsChecked property set to True so it will be checked when the page is first shown.</p>
<p>The fourth row has a TextBlock that displays Hello and the final row has a TextBlock that displays World, but does so setting the FontFamily, FontSize and FontWeight.</p>
<p>StackPanels</p>
<p>StackPanels are typically combined with other layout controls. They allow you to stack objects one on top of the other, or next to each other (like books on a shelf).</p>
<p>One convenience of a StackPanel is that you do not have to provide the position of the objects held by a StackPanel, they are positioned relative to the object declared earlier in the Stack..</p>
<p>In the following example, you will stack a TextBlock on top of a TextBox which in turn will sit on top of a Button that will sit on top of a CheckBox (shades of Yertle the Turtle!)</p>
<p>&lt;StackPanel Background=&quot;Beige&quot; Orientation=&quot;Vertical&quot; &gt;<br />
&lt;TextBlock Text=&quot;Your name?&quot;<br />
HorizontalAlignment=&quot;Left&quot; Margin=&quot;10,2,0,1&quot;/&gt;<br />
&lt;TextBox Width=&quot;150&quot; Height=&quot;30&quot;<br />
HorizontalAlignment=&quot;Left&quot; Margin=&quot;10,2,0,1&quot;/&gt;<br />
&lt;Button Content=&quot;Submit this information&quot;<br />
HorizontalAlignment=&quot;Left&quot;<br />
Margin=&quot;10,2,0,1&quot; Height=&quot;30&quot; Width=&quot;150&quot; /&gt;<br />
&lt;CheckBox Content=&quot;With Zing!&quot; HorizontalAlignment=&quot;Left&quot;<br />
Margin=&quot;10,2,0,1&quot; /&gt;<br />
&lt;/StackPanel&gt;</p>
<p>There is quite a bit of information in this code snippet, so let&#8217;s unpack it piece by piece.</p>
<p>The top and bottom lines show the declaration of the StackPanel in the Xaml file. The StackPanel is declared with two attributes: a BackgroundColor (Beige) and an Orientation (which must be either Vertical or Horizontal).</p>
<p>There are many other attributes you can set, as will be true for nearly all the controls These, along with the methods are conveniently listed in the documentation,</p>
<p><a href="http://www.silverlight.net/content/learn/tutorials/Beta2Tutorial1_7x.png"><a href="http://saadtips.files.wordpress.com/2009/12/image007.png"><img src="http://saadtips.files.wordpress.com/2009/12/image007.png?w=450&#038;h=356" alt="" title="image007" width="450" height="356" class="alignnone size-full wp-image-189" /></a></p>
<p></a></p>
<p>Figure 1-7. Documentation Showing Stack Panel Members <a href="http://www.silverlight.net/content/learn/tutorials/Beta2Tutorial1_7x.png">(Click to view full-size image)</a></p>
<p>By setting the Orientation to Vertical we are stacking its contents one on top of another rather than side by side.</p>
<p>Within the StackPanel, the four objects are declared, and the order of their declaration will determine the order in which they are stacked. Each is set with its TextAlignment property set to Left so that they will align, and each has its Margin property set. Let&#8217;s dig just a bit deeper into the Margin property by looking up its definition in the documentation,</p>
<p>public Thickness Margin { get; set; }</p>
<p>The Margin property is actually an object of type Thickness. As noted earlier, when you are declaring a Thickness object in Xaml you may do so in one of three ways:</p>
<p>First, you may provide a double that will be the margin for the margin on all four sides (left, top, right, and bottom) uniformly around the object. Thus, you might write</p>
<p>&lt;Button Content=&quot;Submit this information&quot;<br />
HorizontalAlignment=&quot;Left&quot;<br />
Margin=&quot;100&quot; Height=&quot;30&quot; Width=&quot;150&quot; /&gt;</p>
<p>Thereby isolating the button with a margin of 100 on either side and above and below,</p>
<p><a href="http://saadtips.files.wordpress.com/2009/12/image008.png"><img src="http://saadtips.files.wordpress.com/2009/12/image008.png?w=426&#038;h=467" alt="" title="image008" width="426" height="467" class="alignnone size-full wp-image-190" /></a></p>
<p>Figure 1-8. Button Margins</p>
<p>Notice that to accommodate the oversided margin, the width of the button was compromised!</p>
<p>The second way to declare a Thickness (and in this case, a Margin) is to provide the sum of the sides and the sum of the top and bottom (thus, the sides must be equal and the top and bottom must be equal,</p>
<p>&lt;Button Content=&quot;Submit this information&quot;<br />
HorizontalAlignment=&quot;Left&quot;<br />
Margin=&quot;50,20&quot; Height=&quot;30&quot; Width=&quot;150&quot; /&gt;</p>
<p>The effect of this declaration is that the left and right margins are 25, and the top and bottom margins are each 10.</p>
<p>Finally, you may declare each independently, as long as you do so in the required order:</p>
<p><a href="http://saadtips.files.wordpress.com/2009/12/image009.png"><img src="http://saadtips.files.wordpress.com/2009/12/image009.png?w=416&#038;h=118" alt="" title="image009" width="416" height="118" class="alignnone size-full wp-image-191" /></a></p>
<p>Figure 1-9. Margins are a Thickness Object</p>
<p>That is: Left, Top, Right, Bottom; or in this case, the Left margin is 10, the Top margin is 2, the Right margin is 0 and the Bottom margin is 1.</p>
<p>Once the four controls are placed in the stack Panel, and aligned, the stack panel is responsible for their placement,</p>
<p><a href="http://saadtips.files.wordpress.com/2009/12/image010.png"><img src="http://saadtips.files.wordpress.com/2009/12/image010.png?w=226&#038;h=181" alt="" title="image010" width="226" height="181" class="alignnone size-full wp-image-192" /></a></p>
<p>Figure 1-10. Stack Panel At Work</p>
<p>Notice that the StackPanel is responsible for its own background color, and for stacking its contents (the four controls) but each control is responsible for its own alignment and margins.</p>
<p>Horizontal Stack Panels</p>
<p>If we want to shift the stack panel to align all the controls into a single row, we&#8217;ll want to make a few additional changes. Not all controls default to aligning in the same way (top, center or bottom) so we&#8217;ll explicitly set their vertical alignment to &quot;Center,&quot; just as we previously set their horizontal alignment to &quot;Left&quot;. Let&#8217;s also set the margins to provide a bit of space between each object as the default is to abut each object.</p>
<p>&lt;StackPanel Background=&quot;Beige&quot; Orientation=&quot;Vertical&quot; &gt;<br />
&lt;TextBlock Text=&quot;Your name?&quot;<br />
HorizontalAlignment=&quot;Left&quot; Margin=&quot;10,2,0,1&quot;/&gt;<br />
&lt;TextBox Width=&quot;150&quot; Height=&quot;30&quot;<br />
HorizontalAlignment=&quot;Left&quot; Margin=&quot;10,2,0,1&quot;/&gt;<br />
&lt;Button Content=&quot;Submit this information&quot;<br />
HorizontalAlignment=&quot;Left&quot;<br />
Margin=&quot;10,2,0,1&quot; Height=&quot;30&quot; Width=&quot;150&quot; /&gt;<br />
&lt;CheckBox Content=&quot;With Zing!&quot; HorizontalAlignment=&quot;Left&quot;<br />
Margin=&quot;10,2,0,1&quot; /&gt;<br />
&lt;/StackPanel&gt;</p>
<p>Note that I set the left margin on the text box to 5 (rather than 10) to bring it a bit closer to the TextBlock that serves as its label.</p>
<p><a href="http://www.silverlight.net/content/learn/tutorials/Beta2Tutorial1_11x.png"><a href="http://saadtips.files.wordpress.com/2009/12/image011.png"><img src="http://saadtips.files.wordpress.com/2009/12/image011.png?w=450&#038;h=148" alt="" title="image011" width="450" height="148" class="alignnone size-full wp-image-193" /></a></p>
<p></a></p>
<p><a href="http://www.silverlight.net/content/learn/tutorials/Beta2Tutorial1_11x.png"></a></p>
<p><a href="http://www.silverlight.net/content/learn/tutorials/Beta2Tutorial1_11x.png"></a></p>
<p><a href="http://www.silverlight.net/content/learn/tutorials/Beta2Tutorial1_11x.png">Figure 1-11. Stack Panel in Horizontal Orientation </a><a href="http://www.silverlight.net/content/learn/tutorials/Beta2Tutorial1_11x.png">(Click to view full-size image)</a></p>
<p><a href="http://www.silverlight.net/content/learn/tutorials/Beta2Tutorial1_11x.png"></a></p>
<p><a href="http://www.silverlight.net/content/learn/tutorials/Beta2Tutorial1_11x.png"></a></p>
<p><a href="http://www.silverlight.net/content/learn/tutorials/Beta2Tutorial1_11x.png"></p>
<p></a></p>
<p><a href="http://www.silverlight.net/content/learn/tutorials/Beta2Tutorial1_11x.png"></a></p>
<p><a href="http://www.silverlight.net/content/learn/tutorials/Beta2Tutorial1_11x.png"></a></p>
<p><a href="http://www.silverlight.net/content/learn/tutorials/Beta2Tutorial1_11x.png">Control Events and Event Handlers</a><a></a></p>
<p><a></a></p>
<p><a></a></p>
<p>In Silverlight each class declares whether it is supported by managed code or not, by including (or not including) the x:Class attribute in its root element. These tutorials will assume you are working in managed code, and that this attribute is therefore present.</p>
<p>When you create a managed code Silverlight application in Visual Studio, the Class attribute is placed for you. Create a new application and call it EventHandler, and then examine the first few lines, as shown here,</p>
<p>&lt;UserControl x:Class=&quot;EventHandler.Page&quot;<br />
xmlns=&quot;<a href="http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;">http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;</a><br />
xmlns:x=&quot;<a href="http://schemas.microsoft.com/winfx/2006/xaml&quot;">http://schemas.microsoft.com/winfx/2006/xaml&quot;</a><br />
Width=&quot;400&quot; Height=&quot;300&quot;&gt;</p>
<p>Declaring Event Handlers</p>
<p>There are two ways to declare event handlers in Silverlight: in the Xaml file or in the code-behind. If you declare event handlers in Xaml you cannot add parameters. A typical event handler declaration in XAMl might look like this</p>
<p>&lt;Canvas Loaded=&quot;Canvas_Loaded&quot;&gt;<br />
&lt;Button x:Name=&quot;myButton&quot; Content=&quot;Hello&quot;<br />
Canvas.Left=&quot;10&quot; Canvas.Top=&quot;10&quot; /&gt;<br />
&lt;/Canvas&gt;</p>
<p>Here I&#8217;ve deleted the Grid created by Visual Studio, and declared a Canvas object. I&#8217;ve also assigned an event handler named &quot;Canvas_Loader&quot; to the Loaded event (a pre-existing event common to all canvases that fires when the Canvas is loaded (created).</p>
<p>I then declare a button in the Xaml and set its content to Hello.</p>
<p>This code appears in Page.xaml. In the code behind file, Page.xaml.cs, I must now implement the event handler with the name I&#8217;ve promised to use,</p>
<p>private void Canvas_Loaded(object sender, RoutedEventArgs e)<br />
{<br />
myButton.Content = &quot;Please Click Me&quot;;<br />
}</p>
<p>The first thing to notice is that the name of the method is identical to that as declared in the Xaml. The second is that this method follows the pattern of all .NET event handlers: it returns void and takes two parameters: the first of type object (and containing a reference to the object that raised the event) and the second of type EventArgs or a type that derives from EventArgs; in this case RoutedEventArgs. We&#8217;ll come back to RoutedEventArgs in just a moment.</p>
<p>The implementation is that when the Canvas is loaded it grabs the button declared in the Xaml file and changes its Content property from &quot;Hello&quot; to &quot;Please push me&quot;,</p>
<p><a href="http://saadtips.files.wordpress.com/2009/12/image012.png"><img src="http://saadtips.files.wordpress.com/2009/12/image012.png?w=234&#038;h=142" alt="" title="image012" width="234" height="142" class="alignnone size-full wp-image-194" /></a></p>
<p>Figure 1-12. Content Property Changed</p>
<p>Even in this incredibly simple example there are two important things to notice:</p>
<p>You did not have to declare myButton in the code behind; it was known simply by declaring it in the Xaml.</p>
<p>The button adjusted its size to accommodate the larger string.</p>
<p>Declaring Event Handlers In Code</p>
<p>I admit it, I have a strong preference for declaring all event handlers in code. I believe it is better encapsulation, making for more scalable and more maintainable code. But this is a personal opinion.</p>
<p>In any case, if you want to declare your event handlers correctly in code, Visual Studio makes it very easy to do so. The most common way is to wire up the event handlers in the OnLoaded event handler, with that event (Loaded) wired up in the Page&#8217;s constructor.</p>
<p>To see this, return to your previous code and remove the event handler from the Xaml. While you&#8217;re there, add a check box as shown here,</p>
<p>&lt;!&#8211; &lt;Canvas Loaded=&quot;Canvas_Loaded&quot;&gt; &#8211;&gt;<br />
&lt;Canvas &gt;<br />
&lt;Button x:Name=&quot;theButton&quot; Content=&quot;I&#8217;m Indented!&quot;<br />
Canvas.Left=&quot;150&quot; Canvas.Top=&quot;20&quot; /&gt;</p>
<p>&lt;CheckBox x:Name=&quot;RushOrder&quot; Content=&quot;Rush&quot;<br />
Canvas.Left=&quot;50&quot; Canvas.Top=&quot;20&quot; FontSize=&quot;18&quot; /&gt;<br />
&lt;/Canvas&gt;</p>
<p>Notice that the original Canvas is commented out, and replaced by a Canvas that does not have an event.</p>
<p>Save the Xaml file and open the code behind.</p>
<p>In the constructor, type Lo. Intellisense will pop up and offer to help you create the EventHandling code, landing on the event Loaded, which is exactly what you want. The tip (next to the Intellisence box) shows the type of the event.</p>
<p><a href="http://www.silverlight.net/content/learn/tutorials/Beta2Tutorial1_13x.png"><a href="http://saadtips.files.wordpress.com/2009/12/image013.png"><img src="http://saadtips.files.wordpress.com/2009/12/image013.png?w=450&#038;h=207" alt="" title="image013" width="450" height="207" class="alignnone size-full wp-image-195" /></a></p>
<p></a></p>
<p>Figure 1-13. Intellisense Helps Create Event Handler <a href="http://www.silverlight.net/content/learn/tutorials/Beta2Tutorial1_13x.png">(Click to view full-size image)</a></p>
<p>We&#8217;ll return to the fact that Loaded is a RoutedEventHandler shortly. Press tab to accept Loaded and type += to begin adding the delegate. (If delegates and events are new to you, you may want to read <a href="http://www.ondotnet.com/pub/a/dotnet/2003/06/23/progCsharp3.html">this article</a>. It&#8217;s a bit old, but still accurate. You can also read extensively about delegates and events in any book on .NET 3.5 or C# or VB.</p>
<p>Intellisense will walk you through each step of wiring up the event handler, and if you let it, will also create the stub of the event handler method, ultimately placing your cursor in the method which it prefills with an exception (in case you forget to add a meaningful implementation.</p>
<p>public Page()<br />
{<br />
InitializeComponent();<br />
Loaded += new RoutedEventHandler(Page_Loaded);</p>
<p>}</p>
<p>void Page_Loaded(object sender, RoutedEventArgs e)<br />
{<br />
throw new NotImplementedException();<br />
}</p>
<p>Delete the exception and register event handlers for the common events for your button (click) and your checkbox (Checked and Unchecked)</p>
<p>void Page_Loaded(object sender, RoutedEventArgs e)<br />
{<br />
myButton.Click += new RoutedEventHandler( myButton_Click );<br />
RushOrder.Checked += new RoutedEventHandler( RushOrder_Changed );<br />
RushOrder.Unchecked += new RoutedEventHandler(RushOrder_Changed);</p>
<p>}</p>
<p>Be careful here, Intellisense will want to name the methods for Checked and Unchecked RushOrder_Checked and RushOrder_Unchecked respectively, but there is no need for two methods. We&#8217;ll override that by typing in the name we want, RushOrder_Changed, which will cause both events to use a shared event handler.</p>
<p>In the shared event handler, we&#8217;ll check the IsChecked status of the checkbox and if it is checked, we&#8217;ll change its text to all upper case (just so we know the event handler is working).</p>
<p>void RushOrder_Changed(object sender, RoutedEventArgs e)<br />
{<br />
if (RushOrder.IsChecked == true)<br />
{<br />
RushOrder.Content = &quot;RUSH&quot;;<br />
}<br />
else<br />
{<br />
RushOrder.Content = &quot;Rush&quot;;<br />
}<br />
}</p>
<p>Note to C# programmers, we must write</p>
<p>if (RushOrder.IsChecked == true)</p>
<p>and not</p>
<p>if (RushOrder.IsChecked)</p>
<p>because IsChecked is of the new C# 3.0 type nullable bollean ( bool?) which indicates that it may have three states, not two: true, false or null.</p>
<p>Creating Controls Dynamically<a></a></p>
<p><a></a></p>
<p><a></a></p>
<p>In Silverlight, all Xaml controls are isomorphic with CLR objects. That is, anything you can create in Xaml you can create in code.</p>
<p>Where you might write,</p>
<p>&lt;Button x:Name=&quot;myButton&quot; Content=&quot;Hello&quot; /&gt;</p>
<p>You can also write</p>
<p>Button myButton = new Button();<br />
myButton.Content = &quot;Hello&quot;;</p>
<p>While it is possible to create all your controls and objects in code, best practices dictate that it is usually better to do so in Xaml. The most compelling reason is that Xaml is highly &quot;toolable&quot; &#8211; that is, it lends itself to round-trip modification in tools such as Visual Studio and Expression and thus is easier to scale, modify and maintain.</p>
<p>On the other hand, there are times that you can&#8217;t know at design time which or how many objects you&#8217;ll need, and the ability to create objects dynamically can be a fundamental requirement.</p>
<p>We can make a minor modification to our existing program to add another button on the user&#8217;s request. Add the following button to the Xaml file (note that we also name the canvas!)</p>
<p>&lt;Canvas x:Name=&quot;myCanvas&quot;&gt;<br />
&lt;Button x:Name=&quot;myButton&quot; Content=&quot;Hello&quot;<br />
Canvas.Left=&quot;10&quot; Canvas.Top=&quot;10&quot;/&gt;<br />
&lt;Button x:Name=&quot;Another&quot; Content=&quot;Add Another&quot;<br />
Canvas.Left=&quot;10&quot; Canvas.Top=&quot;50&quot; /&gt;<br />
&lt;CheckBox x:Name=&quot;rushOrder&quot; Content=&quot;Rush&quot;<br />
Canvas.Left=&quot;50&quot; Canvas.Top=&quot;10&quot; /&gt;</p>
<p>The effect is to add a button to the page with the words &quot;Add Another.&quot; When the user clicks on this button, we want to add a button to the UI and we want that button to have its own size, position and behavior.</p>
<p>We do all of that in the code behind.</p>
<p>Creating a Button Dynamically</p>
<p>Save the .xaml file and open Page.xaml.cs</p>
<p>The first thing to do is to add an event handler for the new button,</p>
<p>Another.Click += new RoutedEventHandler(Another_Click);</p>
<p>And to add its implementation, in which you&#8217;ll create a new button and set its properties,</p>
<p>void Another_Click(object sender, RoutedEventArgs e)<br />
{<br />
Button b = new Button();<br />
b.Content = &quot;I live!&quot;;<br />
b.SetValue(Canvas.LeftProperty, 10.0);<br />
b.SetValue(<br />
Canvas.TopProperty,<br />
this.newButtonPosition);<br />
this.newButtonPosition += 30.0;<br />
b.Width = 100;<br />
b.Height = 20;<br />
b.Click +=new RoutedEventHandler(new_button_click);<br />
myCanvas.Children.Add(b);<br />
}</p>
<p>Because the canvas&#8217;s Left and Top are not actually properties of the Button (but are extended properties) you set them with the SetValue method, which takes two parameters. The first is the actual name of the property you want to set (Canvas.LeftProperty and Canvas.TopProperty) which is not difficult to find as Intellisense will supply it) and the second is the value (in this case a double).</p>
<p>Because I want to be able to click this button more than once, and I don&#8217;t want the new buttons overwriting each other, I need a member variable to keep track of the top value,</p>
<p>private double newButtonPosition = 100.0;</p>
<p>After I set it, I can then increment it so the next button will fall below the previous,</p>
<p>b.SetValue(<br />
Canvas.TopProperty,<br />
this.newButtonPosition);<br />
this.newButtonPosition += 30.0;</p>
<p>The result is very satisfying,</p>
<p><a href="http://saadtips.files.wordpress.com/2009/12/image014.png"><img src="http://saadtips.files.wordpress.com/2009/12/image014.png?w=124&#038;h=146" alt="" title="image014" width="124" height="146" class="alignnone size-full wp-image-196" /></a></p>
<p>Figure 1-14. Adding Dynamic Buttons</p>
<p>The second thing to notice about the Button we are adding is that we are also adding an event handler registration,</p>
<p>b.Click +=new RoutedEventHandler(new_button_click);</p>
<p>This means that every button that is added (each of the three shown in Figure 1-8) is registered to call new_button_click when it is clicked. You&#8217;ll need to write that event handler into your Page.xaml.cs file,</p>
<p>void new_button_click(object sender, RoutedEventArgs e)<br />
{<br />
Button btn = sender as Button;<br />
btn.Content = &quot;Don&#8217;t do that!&quot;;<br />
btn.IsEnabled = false;<br />
}</p>
<p>As the buttons are clicked, they change their message and become disabled,</p>
<p><a href="http://saadtips.files.wordpress.com/2009/12/image015.png"><img src="http://saadtips.files.wordpress.com/2009/12/image015.png?w=124&#038;h=156" alt="" title="image015" width="124" height="156" class="alignnone size-full wp-image-197" /></a></p>
<p>Figure 1-15. Disabled Dynamic Buttons</p>
<p>Finally, none of this will work if you don&#8217;t add the buttons to the page. In this case, however, you don&#8217;t want to add them to LayoutRoot as their positioning is in terms of a specific canvas, so you&#8217;ll add them to that canvas,</p>
<p>myCanvas.Children.Add(b);</p>
<p>When you run the program, they are members of that canvas, just as surely as if you had added them individually in the Xaml file.</p>
<br />Posted in 1  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/saadtips.wordpress.com/182/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/saadtips.wordpress.com/182/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/saadtips.wordpress.com/182/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/saadtips.wordpress.com/182/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/saadtips.wordpress.com/182/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/saadtips.wordpress.com/182/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/saadtips.wordpress.com/182/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/saadtips.wordpress.com/182/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/saadtips.wordpress.com/182/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/saadtips.wordpress.com/182/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/saadtips.wordpress.com/182/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/saadtips.wordpress.com/182/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/saadtips.wordpress.com/182/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/saadtips.wordpress.com/182/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=saadtips.wordpress.com&amp;blog=9673707&amp;post=182&amp;subd=saadtips&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://saadtips.wordpress.com/2009/12/16/silverlight-user-interface-controls/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/16b7fdb6045a11e7ac6f021becbca7bf?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">saadtips</media:title>
		</media:content>

		<media:content url="http://saadtips.files.wordpress.com/2009/12/image0011.png" medium="image">
			<media:title type="html">image0011</media:title>
		</media:content>

		<media:content url="http://saadtips.files.wordpress.com/2009/12/image002.png" medium="image">
			<media:title type="html">image002</media:title>
		</media:content>

		<media:content url="http://saadtips.files.wordpress.com/2009/12/image003.png" medium="image">
			<media:title type="html">image003</media:title>
		</media:content>

		<media:content url="http://saadtips.files.wordpress.com/2009/12/image004.png" medium="image">
			<media:title type="html">image004</media:title>
		</media:content>

		<media:content url="http://saadtips.files.wordpress.com/2009/12/image005.png" medium="image">
			<media:title type="html">image005</media:title>
		</media:content>

		<media:content url="http://saadtips.files.wordpress.com/2009/12/image006.png" medium="image">
			<media:title type="html">image006</media:title>
		</media:content>

		<media:content url="http://saadtips.files.wordpress.com/2009/12/image007.png" medium="image">
			<media:title type="html">image007</media:title>
		</media:content>

		<media:content url="http://saadtips.files.wordpress.com/2009/12/image008.png" medium="image">
			<media:title type="html">image008</media:title>
		</media:content>

		<media:content url="http://saadtips.files.wordpress.com/2009/12/image009.png" medium="image">
			<media:title type="html">image009</media:title>
		</media:content>

		<media:content url="http://saadtips.files.wordpress.com/2009/12/image010.png" medium="image">
			<media:title type="html">image010</media:title>
		</media:content>

		<media:content url="http://saadtips.files.wordpress.com/2009/12/image011.png" medium="image">
			<media:title type="html">image011</media:title>
		</media:content>

		<media:content url="http://saadtips.files.wordpress.com/2009/12/image012.png" medium="image">
			<media:title type="html">image012</media:title>
		</media:content>

		<media:content url="http://saadtips.files.wordpress.com/2009/12/image013.png" medium="image">
			<media:title type="html">image013</media:title>
		</media:content>

		<media:content url="http://saadtips.files.wordpress.com/2009/12/image014.png" medium="image">
			<media:title type="html">image014</media:title>
		</media:content>

		<media:content url="http://saadtips.files.wordpress.com/2009/12/image015.png" medium="image">
			<media:title type="html">image015</media:title>
		</media:content>
	</item>
		<item>
		<title>Javascript to detect if Silverlight is installed</title>
		<link>http://saadtips.wordpress.com/2009/12/15/javascript-to-detect-if-silverlight-is-installed/</link>
		<comments>http://saadtips.wordpress.com/2009/12/15/javascript-to-detect-if-silverlight-is-installed/#comments</comments>
		<pubDate>Tue, 15 Dec 2009 07:37:55 +0000</pubDate>
		<dc:creator>saadtips</dc:creator>
				<category><![CDATA[1]]></category>

		<guid isPermaLink="false">http://saadtips.wordpress.com/?p=181</guid>
		<description><![CDATA[Source: http://www.dotnetspider.com/tutorials/Silverlight-Tutorial-327.aspx The current versions of Internet Explorer consider Silverlight as a kind of ActiveX control. So, in order to determine if Silverlight is installed, we can attempt to create this ActiveX control using Javascript. If it fails to create the ActiveX control, we can assume that Silverlight is not installed. For other browsers like [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=saadtips.wordpress.com&amp;blog=9673707&amp;post=181&amp;subd=saadtips&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Source: <a href="http://www.dotnetspider.com/tutorials/Silverlight-Tutorial-327.aspx">http://www.dotnetspider.com/tutorials/Silverlight-Tutorial-327.aspx</a></p>
<p>The current versions of Internet Explorer consider Silverlight as a kind of ActiveX control. So, in order to determine if Silverlight is installed, we can attempt to create this ActiveX control using Javascript. If it fails to create the ActiveX control, we can assume that Silverlight is not installed.</p>
<p>For other browsers like Google Chrome, Netscape, FireFox, Safari etc, this can be determined by looking in to the Plugin array of the navigator object. The Silverlight plugin is installed with the name &#8216;Silverlight Plug-In&#8217;.</p>
<p>The below sample code shows how to find if Silverlight is installed on the client browser or not.</p>
<pre><code>
&lt;script language=&quot;javascript&quot;&gt;
var browser = navigator.appName; // Get browser
var silverlightInstalled = false;

if (browser == 'Microsoft Internet Explorer')
{
try
{
var slControl = new ActiveXObject('AgControl.AgControl');
silverlightInstalled = true;
}
catch (e)
{
// Error. Silverlight not installed.
}
}
else
{
// Handle Netscape, FireFox, Google chrome etc
try
{
if (navigator.plugins[&quot;Silverlight Plug-In&quot;])
{
silverlightInstalled = true;
}
}
catch (e)
{
// Error. Silverlight not installed.
}
}

alert(silverlightInstalled);
&lt;/script&gt;
</code></pre>
<br />Posted in 1  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/saadtips.wordpress.com/181/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/saadtips.wordpress.com/181/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/saadtips.wordpress.com/181/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/saadtips.wordpress.com/181/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/saadtips.wordpress.com/181/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/saadtips.wordpress.com/181/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/saadtips.wordpress.com/181/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/saadtips.wordpress.com/181/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/saadtips.wordpress.com/181/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/saadtips.wordpress.com/181/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/saadtips.wordpress.com/181/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/saadtips.wordpress.com/181/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/saadtips.wordpress.com/181/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/saadtips.wordpress.com/181/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=saadtips.wordpress.com&amp;blog=9673707&amp;post=181&amp;subd=saadtips&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://saadtips.wordpress.com/2009/12/15/javascript-to-detect-if-silverlight-is-installed/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/16b7fdb6045a11e7ac6f021becbca7bf?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">saadtips</media:title>
		</media:content>
	</item>
		<item>
		<title>How to set a background image for your Sivlerlight control</title>
		<link>http://saadtips.wordpress.com/2009/12/15/how-to-set-a-background-image-for-your-sivlerlight-control/</link>
		<comments>http://saadtips.wordpress.com/2009/12/15/how-to-set-a-background-image-for-your-sivlerlight-control/#comments</comments>
		<pubDate>Tue, 15 Dec 2009 06:23:13 +0000</pubDate>
		<dc:creator>saadtips</dc:creator>
				<category><![CDATA[1]]></category>

		<guid isPermaLink="false">http://saadtips.wordpress.com/?p=180</guid>
		<description><![CDATA[source:http://www.dotnetspider.com/tutorials/Silverlight-Tutorial-325.aspx In Silverlight, the ImageBrush element can be used to fill an area with an image. The area could be various shape elements or the entire Canvas itself. This code sample shows how to use the ImageBrush to set a background image for the Silverlight canvas control. &#60;Canvas x:Name=&#34;SnowCanvas&#34; Width=&#34;600&#34; Height=&#34;480&#34;&#62; &#60;Canvas.Background&#62; &#60;ImageBrush x:Name=&#34;backgroundImageBrush&#34; Stretch=&#34;UniformToFill&#34; [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=saadtips.wordpress.com&amp;blog=9673707&amp;post=180&amp;subd=saadtips&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>source:<a href="http://www.dotnetspider.com/tutorials/Silverlight-Tutorial-325.aspx">http://www.dotnetspider.com/tutorials/Silverlight-Tutorial-325.aspx</a></p>
<p>In Silverlight, the ImageBrush element can be used to fill an area with an image. The area could be various shape elements or the entire Canvas itself.</p>
<p>This code sample shows how to use the ImageBrush to set a background image for the Silverlight canvas control.</p>
<pre><code>
&lt;Canvas x:Name=&quot;SnowCanvas&quot; Width=&quot;600&quot; Height=&quot;480&quot;&gt;
&lt;Canvas.Background&gt;
&lt;ImageBrush x:Name=&quot;backgroundImageBrush&quot;
Stretch=&quot;UniformToFill&quot;
ImageSource=&quot;Images/Background.png&quot;&gt;
&lt;/ImageBrush&gt;
&lt;/Canvas.Background&gt;
&lt;/Canvas&gt;

</code></pre>
<p>The below example shows how to Fill an ellipse area with an image control. In addition, I am using the Mouse Enter and Mouse Leave events to dynamically change the image used to fill the Ellipse shape.</p>
<pre><code>
&lt;Ellipse x:Name=&quot;ellipse1&quot;
MouseEnter=&quot;ellipse1_MouseEnter&quot;
MouseLeave=&quot;ellipse1_MouseLeave&quot;
Width=&quot;100&quot;
Height=&quot;100&quot;&gt;
&lt;Ellipse.Fill&gt;
&lt;ImageBrush x:Name=&quot;imageBrush1&quot;
Stretch=&quot;UniformToFill&quot;
ImageSource=&quot;Images/Flower2.png&quot;&gt;
&lt;/ImageBrush&gt;
&lt;/Ellipse.Fill&gt;
&lt;/Ellipse&gt;
</code></pre>
<p>Here is the C# code to handle the Mouse Enter and Mouse Leave events and dynamically change the image in these events:</p>
<pre><code>
private void ellipse1_MouseEnter(object sender, MouseEventArgs e)
{
ImageBrush brush = new ImageBrush();
brush.ImageSource = new BitmapImage(new Uri(@&quot;Images/Flower1.png&quot;, UriKind.Relative)); ;
ellipse1.Fill = brush;
}

private void ellipse1_MouseLeave(object sender, MouseEventArgs e)
{
</code></pre>
<br />Posted in 1  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/saadtips.wordpress.com/180/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/saadtips.wordpress.com/180/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/saadtips.wordpress.com/180/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/saadtips.wordpress.com/180/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/saadtips.wordpress.com/180/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/saadtips.wordpress.com/180/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/saadtips.wordpress.com/180/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/saadtips.wordpress.com/180/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/saadtips.wordpress.com/180/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/saadtips.wordpress.com/180/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/saadtips.wordpress.com/180/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/saadtips.wordpress.com/180/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/saadtips.wordpress.com/180/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/saadtips.wordpress.com/180/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=saadtips.wordpress.com&amp;blog=9673707&amp;post=180&amp;subd=saadtips&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://saadtips.wordpress.com/2009/12/15/how-to-set-a-background-image-for-your-sivlerlight-control/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/16b7fdb6045a11e7ac6f021becbca7bf?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">saadtips</media:title>
		</media:content>
	</item>
	</channel>
</rss>
