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

<channel>
	<title>Designer Silverlight &#187; How To&#8230;</title>
	<atom:link href="http://www.designersilverlight.com/category/how-to/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.designersilverlight.com</link>
	<description>Matthias Shapiro's Silverlight &#38; WPF Blog - Because Developers Get All The Good Blogs</description>
	<lastBuildDate>Thu, 26 Jan 2012 06:45:32 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>PHP, MySQL, and Silverlight: The Complete Tutorial (Part 3)</title>
		<link>http://www.designersilverlight.com/2010/05/24/php-mysql-and-silverlight-the-complete-tutorial-part-3/</link>
		<comments>http://www.designersilverlight.com/2010/05/24/php-mysql-and-silverlight-the-complete-tutorial-part-3/#comments</comments>
		<pubDate>Mon, 24 May 2010 19:30:58 +0000</pubDate>
		<dc:creator>Matthias Shapiro</dc:creator>
				<category><![CDATA[Binding]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[Data Binding]]></category>
		<category><![CDATA[eventtrigger]]></category>
		<category><![CDATA[How To...]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://www.designersilverlight.com/?p=970</guid>
		<description><![CDATA[This is meant to be the one-stop-shop blog post for creating a very simple web service in PHP that pulls from a MySQL database and displaying the data in Silverlight. Emphasis on the “simple”. Here is an example of the finished product (I reserve the right to clean up the data on a regular basis): [...]]]></description>
			<content:encoded><![CDATA[<p>This is meant to be the one-stop-shop blog post for creating a very simple web service in PHP that pulls from a MySQL database and displaying the data in Silverlight. Emphasis on the “simple”. Here is an example of the finished product (I reserve the right to clean up the data on a regular basis):</p>
<div id="silverlightControlHost">
		<object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="500px" height="300px"><param name="source" value="http://designersilverlight.com/Silverlight/ToDo_List_Tutorial.xap"/><param name="onerror" value="onSilverlightError" /><param name="background" value="white" /><param name="minRuntimeVersion" value="3.0.40818.0" /><param name="autoUpgrade" value="true" /><a href="http://go.microsoft.com/fwlink/?LinkID=149156&#038;v=3.0.40818.0" style="text-decoration: none;"><br />
				<img src="http://go.microsoft.com/fwlink/?LinkID=161376" alt="Get Microsoft Silverlight" style="border-style: none"/><br />
			</a><br />
		</object><iframe id='_sl_historyFrame' style='visibility:hidden;height:0;width:0;border:0px'></iframe></div>
<p><a href="http://www.designersilverlight.com/2010/05/22/php-mysql-and-silverlight-the-complete-tutorial-part-1/">Part 1: MySQL</a></p>
<p><a href="http://www.designersilverlight.com/2010/05/23/php-mysql-and-silverlight-the-complete-tutorial-part-2/">Part 2: PHP</a></p>
<p><a href="http://www.designersilverlight.com/wp-content/uploads/2010/05/AllFiles_PHP_and_Silverlight.zip">Download all files (PHP &#038; Silverlight)</a><br />
<a href="http://www.designersilverlight.com/wp-content/uploads/2010/05/PHP_Tutorial_Files.zip">Download PHP files only</a><br />
<a href="http://www.designersilverlight.com/wp-content/uploads/2010/05/ToDo_List_Tutorial.zip">Download Silverlight project only</a></p>
<p>In Part 1, we created the MySQL tables necessary to store data for a simple to-do list. In Part 2, we wrote a PHP service to deliver the items in our to-do list in JSON format. In Part 3, we’ll create a Silverlight application that can utilize this web service to retrieve, display, and edit the to-do list.</p>
<h2>Part 3: Connecting Silverlight To Our PHP Web Service</h2>
<p>First, let’s start a new Silverlight project. (You can download the full project here.) In the interest of time, I’m not going to go into the details of the “ideal” implementation for this. I’m just going to show the parts necessary to retrieve, display and interact with the to-do data.</p>
<p>Before we start with the UI, let’s build a model so that we can appropriately bind our data. Add a new folder to the Silverlight project and name it “Models”. Add a new class to it and name the class “ToDoItem.cs”. In this instance, we’re just going to make the model look just like our MySQL table.</p>
<p><strong>ToDoItem.cs</strong></p>
<p><span style="color: #0000ff; font-size: small;"> </span></p>
<p><span style="color: #0000ff; font-size: small;"><span style="font-family: Consolas;">p<span style="font-size: small;">ublic </span></span><span style="font-size: small;"><span style="font-family: Consolas;"><span style="color: #0000ff;">class</span><span style="color: #000000;"> </span><span style="color: #2b91af;">ToDoItem</span></span></span><br />
<span style="font-family: Consolas; font-size: small;">{<br />
</span><span style="font-size: small;"><span style="font-family: Consolas;"><span style="color: #0000ff;">public</span><span style="color: #000000;"> </span><span style="color: #0000ff;">bool</span><span style="color: #000000;"> isDone { </span><span style="color: #0000ff;">get</span><span style="color: #000000;">; </span><span style="color: #0000ff;">set</span></span></span><span style="color: #000000;"><span style="font-family: Consolas; font-size: small;">; }</span></span><br />
<span style="font-size: small;"><span style="font-family: Consolas;"><span style="color: #0000ff;"> public</span><span style="color: #000000;"> </span><span style="color: #0000ff;">string</span><span style="color: #000000;"> toDoDescription {</span><span style="color: #0000ff;">get</span><span style="color: #000000;">; </span><span style="color: #0000ff;">set</span></span></span><span style="color: #000000;"><span style="font-family: Consolas; font-size: small;">;}</span></span><br />
<span style="font-size: small;"><span style="font-family: Consolas;"><span style="color: #0000ff;"> public</span><span style="color: #000000;"> </span><span style="color: #0000ff;">int</span><span style="color: #000000;"> toDoID {</span><span style="color: #0000ff;">get</span><span style="color: #000000;">; </span><span style="color: #0000ff;">set</span></span></span><span style="color: #000000;"><span style="font-family: Consolas; font-size: small;">;}</span></span><br />
<span style="font-family: Consolas; color: #0000ff; font-size: small;"><br />
public</span><span style="color: #000000;"><span style="font-family: Consolas; font-size: small;"> ToDoItem()</span></span> <span style="font-family: Consolas; font-size: small;">{ </span><span style="font-family: Consolas; font-size: small;">}<br />
</span><span style="font-family: Consolas; font-size: small;">}</span></span></p>
<p><span style="color: #0000ff; font-size: small;"><span style="font-family: Consolas; font-size: small;"> </span></span></p>
<p><span style="color: #0000ff; font-size: small;"> </span></p>
<p>Now, we’ll add to our MainPage.xaml a ListBox named “ToDoList” that will hold the to-do items and a Grid to house the UI to add a new to-do. We’ll work on gathering and displaying our items first.</p>
<p>Right-click on the ListBox and go to “<strong>Edit Additional Templates –&gt; Edit Generated Items (ItemTemplate) –&gt; Create Empty…</strong>”<br />
<a href="http://www.designersilverlight.com/wp-content/uploads/2010/05/clip_image0012.png"><img style="display: inline; border-width: 0px;" title="clip_image001" src="http://www.designersilverlight.com/wp-content/uploads/2010/05/clip_image001_thumb2.png" border="0" alt="clip_image001" width="634" height="94" /></a><br />
You’ll love this part… Just add a checkbox to it. That’s all we’ll need, so that’s all we’ll add. Then, go into the XAML and make the checkbox look like this:</p>
<p><span style="color: #0000ff; font-size: small;"> </span></p>
<p><span style="color: #0000ff; font-size: small;"><span style="font-family: Consolas; font-size: small;">&lt;</span><span style="font-size: small;"><span style="font-family: Consolas;"><span style="color: #a31515;">CheckBox</span><span style="color: #ff0000;"> Content</span><span style="color: #0000ff;">=&#8221;{</span><span style="color: #a31515;">Binding</span><span style="color: #ff0000;"> toDoDescription</span><span style="color: #0000ff;">}&#8221;<br />
</span></span></span><span style="font-size: small;"><span style="font-family: Consolas;"><span style="color: #ff0000;"> IsChecked</span><span style="color: #0000ff;">=&#8221;{</span><span style="color: #a31515;">Binding</span><span style="color: #ff0000;"> isDone</span><span style="color: #0000ff;">}&#8221;</span></span></span><span style="color: #000000;"> </span><br />
<span style="font-size: small;"><span style="font-family: Consolas;"><span style="color: #ff0000;"> Tag</span><span style="color: #0000ff;">=&#8221;{</span><span style="color: #a31515;">Binding</span><span style="color: #ff0000;"> toDoID</span><span style="color: #0000ff;">}&#8221; /&gt;</span></span></span></span></p>
<p><span style="color: #0000ff; font-size: small;"> </span></p>
<p><span style="font-family: Consolas; color: #0000ff; font-size: small;"> </span></p>
<p>This binding is all we’ll need once we gather our to-dos from the web service and attach it to the ListBox. Let’s go ahead and get that data into this ListBox.</p>
<p>Open MainPage.xaml.cs and, at the top of the class, add:</p>
<p><span style="font-size: small;"><span style="font-family: Consolas;"><span style="color: #2b91af;">WebClient</span><span style="color: #000000;"> wc = </span><span style="color: #0000ff;">new</span><span style="color: #000000;"> </span><span style="color: #2b91af;">WebClient</span></span></span><span style="font-size: small;"><span style="font-family: Consolas;"><span style="color: #000000;">();<br />
</span><span style="color: #2b91af;">ObservableCollection</span><span style="color: #000000;">&lt;</span><span style="color: #2b91af;">ToDoItem</span><span style="color: #000000;">&gt; myToDoList = </span><span style="color: #0000ff;">new</span><span style="color: #000000;"> </span><span style="color: #2b91af;">ObservableCollection</span><span style="color: #000000;">&lt;</span><span style="color: #2b91af;">ToDoItem</span></span></span><span style="font-size: small;"><span style="font-family: Consolas;"><span style="color: #000000;">&gt;();<br />
</span><span style="color: #0000ff;">string</span><span style="color: #000000;"> baseURI = </span><span style="color: #a31515;">&#8220;http://&lt;Web_address_holding_your_php_files&gt;&#8221;</span><span style="color: #000000;">;</span></span></span></p>
<p>You may have to add “using System.Net;” and “using System.Collections.ObjectModel;” to the top of the file. While we’re adding references, right-click on the “References” folder and find the “System.Json” component and add it to the project. Then add “using System.Json;” to the references section in the top.  It’ll come in handy in a minute.</p>
<p>In the MainPage() method under InitializeComponent(), type “wc.DownloadStringCompleted += “ and hit TAB twice. This will add an event handler for when the WebClient has finished connecting to the web service we wrote.</p>
<p>The resulting event handler (which should be named “wc_DownloadStringCompleted”), is the code that our application will go to whenever it makes a call to our web service and gets a result. In it, we will do the following things:</p>
<ol>
<li>Check to make sure we got a result without error</li>
<li>Check to see what kind of result we got (did we get all to-do items? or add a new to-do item?)</li>
<li>Walk through the result, extracting the data we need</li>
<li>Apply that data to the UI</li>
</ol>
<p>Let’s add the code to do that for getting all the items. Make your event handler look like this:</p>
<div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:7934bf62-c08c-435e-980b-d18700e35c2b" class="wlWriterEditableSmartContent" style="margin: 0px; display: inline; float: none; padding: 0px;">
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt;">
<div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px;">wc_DownloadStringCompleted</div>
<div style="background: #ddd; max-height: 400px; overflow: auto;">
<ol style="background: #ffffff; margin: 0 0 0 2.5em; padding: 0 0 0 5px;">
<li><span style="color: #0000ff;">void</span> wc_DownloadStringCompleted(<span style="color: #0000ff;">object</span> sender, <span style="color: #2b91af;">DownloadStringCompletedEventArgs</span> e)</li>
<li style="background: #f3f3f3;"> {</li>
<li> <span style="color: #0000ff;">if</span> (e.Error == <span style="color: #0000ff;">null</span> &amp;&amp; e.Result!= <span style="color: #a31515;">&#8220;&#8221;</span>)</li>
<li style="background: #f3f3f3;"> {</li>
<li> <span style="color: #2b91af;">JsonValue</span> completeResult = <span style="color: #2b91af;">JsonPrimitive</span>.Parse(e.Result);</li>
<li style="background: #f3f3f3;"> <span style="color: #0000ff;">string</span> resultType = completeResult[<span style="color: #a31515;">"returnType"</span>].ToString().Replace(<span style="color: #a31515;">&#8216;&#8221;&#8216;</span>, <span style="color: #a31515;">&#8216; &#8216;</span>).Trim();</li>
<li> <span style="color: #0000ff;">if</span> (resultType == <span style="color: #a31515;">&#8220;todoItems&#8221;</span>)</li>
<li style="background: #f3f3f3;"> {</li>
<li> myToDoList.Clear();</li>
<li style="background: #f3f3f3;"></li>
<li> <span style="color: #2b91af;">JsonArray</span> toDoItemsJson = (<span style="color: #2b91af;">JsonArray</span>)completeResult[<span style="color: #a31515;">"results"</span>];</li>
<li style="background: #f3f3f3;"> <span style="color: #0000ff;">foreach</span> (<span style="color: #2b91af;">JsonValue</span> todoItemJson <span style="color: #0000ff;">in</span> toDoItemsJson)</li>
<li> {</li>
<li style="background: #f3f3f3;"> <span style="color: #2b91af;">ToDoItem</span> thisTodo = <span style="color: #0000ff;">new</span> <span style="color: #2b91af;">ToDoItem</span>();</li>
<li></li>
<li style="background: #f3f3f3;"> <span style="color: #0000ff;">if</span> (todoItemJson[<span style="color: #a31515;">"ToDoIndex"</span>] != <span style="color: #0000ff;">null</span>)</li>
<li> thisTodo.toDoID = <span style="color: #2b91af;">Convert</span>.ToInt32(todoItemJson[<span style="color: #a31515;">"ToDoIndex"</span>].ToString().Replace(<span style="color: #a31515;">&#8216;&#8221;&#8216;</span>, <span style="color: #a31515;">&#8216; &#8216;</span>).Trim());</li>
<li style="background: #f3f3f3;"> <span style="color: #0000ff;">if</span> (todoItemJson[<span style="color: #a31515;">"TodoText"</span>] != <span style="color: #0000ff;">null</span>)</li>
<li> thisTodo.toDoDescription = todoItemJson[<span style="color: #a31515;">"TodoText"</span>].ToString().Replace(<span style="color: #a31515;">&#8216;&#8221;&#8216;</span>, <span style="color: #a31515;">&#8216; &#8216;</span>).Trim();</li>
<li style="background: #f3f3f3;"> <span style="color: #0000ff;">if</span> (todoItemJson[<span style="color: #a31515;">"IsDone"</span>] != <span style="color: #0000ff;">null</span>)</li>
<li> {</li>
<li style="background: #f3f3f3;"> <span style="color: #0000ff;">int</span> isDoneInt =  <span style="color: #2b91af;">Convert</span>.ToInt32(todoItemJson[<span style="color: #a31515;">"IsDone"</span>].ToString().Replace(<span style="color: #a31515;">&#8216;&#8221;&#8216;</span>, <span style="color: #a31515;">&#8216; &#8216;</span>).Trim());</li>
<li> <span style="color: #0000ff;">if</span>(isDoneInt == 0){</li>
<li style="background: #f3f3f3;"> thisTodo.isDone = <span style="color: #0000ff;">false</span>;</li>
<li> } <span style="color: #0000ff;">else</span> <span style="color: #0000ff;">if</span> (isDoneInt == 1){</li>
<li style="background: #f3f3f3;"> thisTodo.isDone = <span style="color: #0000ff;">true</span>;</li>
<li> }</li>
<li style="background: #f3f3f3;"> }</li>
<li> myToDoList.Add(thisTodo);</li>
<li style="background: #f3f3f3;"> }</li>
<li> ToDoList.ItemsSource = myToDoList;</li>
<li style="background: #f3f3f3;"> }</li>
<li> }</li>
<li style="background: #f3f3f3;"> }</li>
</ol>
</div>
</div>
</div>
<p>With this in place, all we need to do is make a call to the get_todo_items.php, which we can do by adding this code just below the wc.DownloadStringCompleted line in the MainPage() method.</p>
<p><span style="font-size: small;"><span style="font-family: Consolas;"><span style="color: #000000;">wc.DownloadStringAsync(</span><span style="color: #0000ff;">new</span><span style="color: #000000;"> </span><span style="color: #2b91af;">Uri</span><span style="color: #000000;">(baseURI + </span><span style="color: #a31515;">&#8220;get_todo_items.php&#8221;</span><span style="color: #000000;">));</span></span></span></p>
<p>When we run the project, we should get all objects from our database and the results should show up just the way we want in our Silverlight application. We will follow the exact same model to add new to-do items and update the to-do items we already have.</p>
<p>I’m in the process of separating out the final part of this tutorial (adding and updating the items) into a supplemental post so that I can wrap this post up. I encourage anyone walking through this to try to complete those parts by yourself and refer to the last bit only if you get stuck.</p>
<p>Finally, a little bit of warning. I structured this project to get it working in as straightforward a manner as possible. It is not in any way the ideal architectural example for a data-driven Silverlight application. It’s just a good way to get started using Silverlight in an environment that isn’t 100% Microsoft technologies.</p>
<iframe src="http://www.facebook.com/plugins/like.php?href=http://www.designersilverlight.com/2010/05/24/php-mysql-and-silverlight-the-complete-tutorial-part-3/&amp;layout=standard&amp;show_faces=1&amp;width=450&amp;action=like&amp;colorscheme=light&amp;font=" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:25px"></iframe><div class="tweetthis" style="text-align:left;"><p> <a target="_blank" rel="nofollow" class="tt" href="http://twitter.com/intent/tweet?text=PHP%2C+MySQL%2C+and+Silverlight%3A+The+Complete+Tutorial+%28Part+3%29+http%3A%2F%2Fdesignersilverlight.com%2F%3Fp%3D970" title="Post to Twitter"><img class="nothumb" src="http://www.designersilverlight.com/wp-content/plugins/tweet-this/icons/en/twitter/tt-twitter.png" alt="Post to Twitter" /></a> <a target="_blank" rel="nofollow" class="tt" href="http://twitter.com/intent/tweet?text=PHP%2C+MySQL%2C+and+Silverlight%3A+The+Complete+Tutorial+%28Part+3%29+http%3A%2F%2Fdesignersilverlight.com%2F%3Fp%3D970" title="Post to Twitter">Tweet This Post</a></p></div>]]></content:encoded>
			<wfw:commentRss>http://www.designersilverlight.com/2010/05/24/php-mysql-and-silverlight-the-complete-tutorial-part-3/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>New Silverlight Posts at Veracity Blogs</title>
		<link>http://www.designersilverlight.com/2009/08/19/new-silverlight-posts-at-veracity-blogs/</link>
		<comments>http://www.designersilverlight.com/2009/08/19/new-silverlight-posts-at-veracity-blogs/#comments</comments>
		<pubDate>Wed, 19 Aug 2009 16:09:27 +0000</pubDate>
		<dc:creator>Matthias Shapiro</dc:creator>
				<category><![CDATA[How To...]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[styles]]></category>
		<category><![CDATA[templates]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://www.designersilverlight.com/?p=732</guid>
		<description><![CDATA[I&#8217;ve started a series of posts on Silverlight and other topics over at the Veracity Solutions Blog. Veracity Solutions is the software consulting firm where I work and we&#8217;ve decided that it would be a good idea to do some sponsored posting there. Blog posts up so far are: Styling a ComboBox in Silverlight 3 [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve started a series of posts on Silverlight and other topics over at the Veracity Solutions Blog.</p>
<p>Veracity Solutions is the software consulting firm where I work and we&#8217;ve decided that it would be a good idea to do some sponsored posting there.</p>
<p>Blog posts up so far are:</p>
<ul>
<li><a href="http://blogs.veracitysolutions.com/styling-a-combobox-in-silverlight-3/">Styling a ComboBox in Silverlight 3</a></li>
<li><a href="http://blogs.veracitysolutions.com/how-to-wrap-text-in-a-silverlight-3-combobox/">How To Wrap Text In a Silverlight 3 ComboBox</a></li>
<li><a href="http://blogs.veracitysolutions.com/how-to-get-a-silverlight-3-autocompletebox-to-show-sample-data-in-blend-3/">How To Get a Silverlight 3 AutoCompleteBox to Show Sample Data In Blend 3</a></li>
<li><a href="http://blogs.veracitysolutions.com/how-to-create-a-listbox-with-checkboxes-or-radiobuttons-in-silverlight-3/">How To Create A ListBox with CheckBoxes (or RadioButtons) In Silverlight 3</a></li>
</ul>
<p>More are coming, including tutorials on behaviors and paths.</p>
<iframe src="http://www.facebook.com/plugins/like.php?href=http://www.designersilverlight.com/2009/08/19/new-silverlight-posts-at-veracity-blogs/&amp;layout=standard&amp;show_faces=1&amp;width=450&amp;action=like&amp;colorscheme=light&amp;font=" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:25px"></iframe><div class="tweetthis" style="text-align:left;"><p> <a target="_blank" rel="nofollow" class="tt" href="http://twitter.com/intent/tweet?text=New+Silverlight+Posts+at+Veracity+Blogs+http%3A%2F%2Fdesignersilverlight.com%2F%3Fp%3D732" title="Post to Twitter"><img class="nothumb" src="http://www.designersilverlight.com/wp-content/plugins/tweet-this/icons/en/twitter/tt-twitter.png" alt="Post to Twitter" /></a> <a target="_blank" rel="nofollow" class="tt" href="http://twitter.com/intent/tweet?text=New+Silverlight+Posts+at+Veracity+Blogs+http%3A%2F%2Fdesignersilverlight.com%2F%3Fp%3D732" title="Post to Twitter">Tweet This Post</a></p></div>]]></content:encoded>
			<wfw:commentRss>http://www.designersilverlight.com/2009/08/19/new-silverlight-posts-at-veracity-blogs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How To Create An Animated ScrollViewer (or ListBox) in WPF</title>
		<link>http://www.designersilverlight.com/2009/05/06/how-to-create-an-animated-scrollviewer-or-listbox-in-wpf/</link>
		<comments>http://www.designersilverlight.com/2009/05/06/how-to-create-an-animated-scrollviewer-or-listbox-in-wpf/#comments</comments>
		<pubDate>Wed, 06 May 2009 22:38:53 +0000</pubDate>
		<dc:creator>Matthias Shapiro</dc:creator>
				<category><![CDATA[Advanced Tutorial]]></category>
		<category><![CDATA[Binding]]></category>
		<category><![CDATA[Blend]]></category>
		<category><![CDATA[How To...]]></category>
		<category><![CDATA[ScrollViewer]]></category>
		<category><![CDATA[styles]]></category>
		<category><![CDATA[templates]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[XAML]]></category>

		<guid isPermaLink="false">http://www.designersilverlight.com/2009/05/06/how-to-create-an-animated-scrollviewer-or-listbox-in-wpf/</guid>
		<description><![CDATA[UPDATED 05/22/09 In the comments, someone mentioned that the project wasn&#8217;t working properly for keyed scrolling. I&#8217;ve updated the project with: Key scrolling (left, right, up, down, page up, page down) CanKeyboardScroll property on the AnimatedScrollViewer so that keyboard scrolling can be turned off ScrollToSelectedItem property on the AnimatedListBox so that the user can have [...]]]></description>
			<content:encoded><![CDATA[<p><b>UPDATED 05/22/09</b></p>
<p>In the comments, someone mentioned that the project wasn&#8217;t working properly for keyed scrolling. I&#8217;ve updated the project with:</p>
<ul>
<li>Key scrolling (left, right, up, down, page up, page down)</li>
<li>CanKeyboardScroll property on the AnimatedScrollViewer so that keyboard scrolling can be turned off</li>
<li>ScrollToSelectedItem property on the AnimatedListBox so that the user can have it automatically scroll to a ListBoxItem</li>
</ul>
<p>That last one is a little hacky&#8230; I use the ListBox ItemContainerGenerator to get the heights of all the items up to the one you want and then scroll it that. I&#8217;m almost positive there is a better way and if anyone knows what it is, I&#8217;d love to hear it. </p>
<p>First things first, here are the project files. </p>
<p><a href='http://www.designersilverlight.com/wp-content/uploads/2009/05/animatedscrollviewersource.zip'>Animated ScrollViewer and ListBox Project Files (Updated 5/22/09)</a> – Contains the AnimatedScrollViewer control library with AnimatedScrollViewer and AnimatedListBox</p>
<p><a href='http://www.designersilverlight.com/wp-content/uploads/2009/05/animatedscrollviewerdll.zip'>Animated ScrollViewer and ListBox DLL (Updated 5/22/09)</a> – For those of you who don’t care how it works and just want it to work</p>
<p>OK… this is going to be something of a whirlwind since I’ve never written a post this in-depth before… it will strain the limits of my ADD. </p>
<h3>Problem:</h3>
<p>The Listbox/ScrollViewer not only doesn’t animate, but it seems impossible to tweak it so that it animates.</p>
<h3>The Reason:</h3>
<p>The reason has everything to do with the ScrollViewer. Basically, the ScrollContainer and the ScrollBars are very tightly intertwined. There is a lot of code that does all the scrolling calculations and that code needs to apply to the scrolled content as well as the UI for the ScrollBars. If you dig deep enough, you’ll see the reasons. Reasons which I assume for the moment you don’t care about… you’re probably in more of a “make the @#&amp;($ thing work!” mood. I know I was.</p>
<h3>The Solution:</h3>
<p>My solution was basically to completely bypass the built-in ScrollBars and put in new ScrollBars with new logic. They look and act just like normal ScrollBars, so you should be able to style them just you would any normal ScrollViewer.</p>
<p>OK… how I did it. (I’m going to use both Blend 2 and Visual Studio 2008)</p>
<p>First, create a new custom control for WPF. This can be done by going into Visual Studio and creating a new Project. Select “WPF Custom Control Library”</p>
<p><a href="http://www.designersilverlight.com/wp-content/uploads/2009/05/clip-image0017.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="clip_image001[7]" border="0" alt="clip_image001[7]" src="http://www.designersilverlight.com/wp-content/uploads/2009/05/clip-image0017-thumb.png" width="498" height="163" /></a></p>
<p> In Blend: </p>
<p>&#160;<a href="http://www.designersilverlight.com/wp-content/uploads/2009/05/clip-image0019.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="clip_image001[9]" border="0" alt="clip_image001[9]" src="http://www.designersilverlight.com/wp-content/uploads/2009/05/clip-image0019-thumb.png" width="492" height="321" /></a></p>
<p> Add a WPF application to the project too so you have something to test. In the WPF application, get Blend to generate the default template for a normal ScrollViewer, accessible (in Blend) by putting a ScrollViewer into the project and right-clicking on it and selecting “Edit Control Parts (Template) –&gt; Edit a Copy…” </p>
<p><a href="http://www.designersilverlight.com/wp-content/uploads/2009/05/clip-image001.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="clip_image001" border="0" alt="clip_image001" src="http://www.designersilverlight.com/wp-content/uploads/2009/05/clip-image001-thumb.png" width="323" height="96" /></a></p>
<p>Once have the default ScrollViewer template, select the “PART_VerticalScrollBar” and the “PART_HorizontalScrollBar” and copy and paste them. Rename your new ScrollBars something you like… I used “PART_AniVerticalScrollBar” and “PART&quot;_AniHorizontalScrollBar”. Now, set the Visibility of the original ScrollBars to “Collapsed”. (We can’t get rid of them, because the ScrollViewer will be looking for them and will throw a conniption if it can’t find them.) </p>
<p>Also, change the Value of your new ScrollBars to 0. You’ll probably have to click on the orange box next to Value and select “Reset”.</p>
<p><a href="http://www.designersilverlight.com/wp-content/uploads/2009/05/clip-image00111.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="clip_image001[11]" border="0" alt="clip_image001[11]" src="http://www.designersilverlight.com/wp-content/uploads/2009/05/clip-image00111-thumb.png" width="219" height="66" /></a></p>
<p>In Visual Studio, right-click on your WPF Custom Control project and go to “Add –&gt; New Item…” . Then select “Custom Control (WPF)” and name it something you like (mine is named AnimatedScrollViewer). This should add a class to your project as well as a basic template to your Generic.xaml file.</p>
<p>Copy the ScrollViewer template that we just made and paste it into the Generic.xaml. The only change we need to make is to change:</p>
<p><span style="color: red">TargetType</span><span style="color: blue">=&quot;{</span><span style="color: #a31515">x</span><span style="color: blue">:</span><span style="color: #a31515">Type </span><span style="color: red">ScrollViewer</span><span style="color: blue">}&quot;</span></p>
<p> <a href="http://11011.net/software/vspaste"></a>
<p>to</p>
<p><span style="color: red">TargetType</span><span style="color: blue">=&quot;{</span><span style="color: #a31515">x</span><span style="color: blue">:</span><span style="color: #a31515">Type </span><span style="color: red">local</span><span style="color: blue">:</span><span style="color: red">AnimatedScrollViewer</span><span style="color: blue">}&quot;</span></p>
<p>in the Style and the ControlTemplate.</p>
<p>OK… that’s pretty much it with the XAML. Now we get to move into the code.</p>
<p>Right now, our class inherits from Control, but we want it to inherit from ScrollViewer like so:</p>
<p><span style="color: blue">public class </span><span style="color: #2b91af">AnimatedScrollViewer </span>: <span style="color: #2b91af">ScrollViewer</span></p>
<p> <a href="http://11011.net/software/vspaste"></a>
<p>Next get some containers for our new spiffy ScrollBars so that we can access them from the custom control code. Type the following before the class:</p>
<p>[<span style="color: #2b91af">TemplatePart</span>(Name = <span style="color: #a31515">&quot;PART_AniVerticalScrollBar&quot;</span>, Type = <span style="color: blue">typeof</span>(<span style="color: #2b91af">ScrollBar</span>))]     <br />[<span style="color: #2b91af">TemplatePart</span>(Name = <span style="color: #a31515">&quot;PART_AniHorizontalScrollBar&quot;</span>, Type = <span style="color: blue">typeof</span>(<span style="color: #2b91af">ScrollBar</span>))]</p>
<p>and the following just inside the class:</p>
<p><span style="color: #2b91af">ScrollBar </span>_aniVerticalScrollBar;     <br /><span style="color: #2b91af">ScrollBar </span>_aniHorizontalScrollBar;</p>
<p> <a href="http://11011.net/software/vspaste"></a>
<p>Now, we’ll override the OnApplyTemplate and make the connection between the template scrollBars and our class ScrollBars:</p>
<p><span style="color: blue">public override void</span>OnApplyTemplate()    <br />{    <br />&#160;&#160;&#160; <span style="color: blue">base</span>.OnApplyTemplate();    </p>
<p>&#160;&#160;&#160; <span style="color: #2b91af">ScrollBar </span>aniVScroll = <span style="color: blue">base</span>.GetTemplateChild(<span style="color: #a31515">&quot;PART_AniVerticalScrollBar&quot;</span>) <span style="color: blue">as</span><span style="color: #2b91af">ScrollBar</span>;    <br />&#160;&#160;&#160; <span style="color: blue">if</span>(aniVScroll != <span style="color: blue">null</span>)    <br />&#160;&#160;&#160; {    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; _aniVerticalScrollBar = aniVScroll;    <br />&#160;&#160;&#160; }    <br />&#160;&#160;&#160; _aniVerticalScrollBar.ValueChanged += <span style="color: blue">new</span><span style="color: #2b91af">RoutedPropertyChangedEventHandler</span>&lt;<span style="color: blue">double</span>&gt;(_aniVerticalScrollBar_ValueChanged);    </p>
<p>&#160;&#160;&#160; <span style="color: #2b91af">ScrollBar </span>aniHScroll = <span style="color: blue">base</span>.GetTemplateChild(<span style="color: #a31515">&quot;PART_AniHorizontalScrollBar&quot;</span>) <span style="color: blue">as</span><span style="color: #2b91af">ScrollBar</span>;    <br />&#160;&#160;&#160; <span style="color: blue">if</span>(aniHScroll != <span style="color: blue">null</span>)    <br />&#160;&#160;&#160; {    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; _aniHorizontalScrollBar = aniHScroll;    <br />&#160;&#160;&#160; }    <br />&#160;&#160;&#160; _aniHorizontalScrollBar.ValueChanged += <span style="color: blue">new</span><span style="color: #2b91af">RoutedPropertyChangedEventHandler</span>&lt;<span style="color: blue">double</span>&gt;(_aniHorizontalScrollBar_ValueChanged);    </p>
<p>&#160;&#160;&#160; <span style="color: blue">this</span>.PreviewMouseWheel += <span style="color: blue">new</span><span style="color: #2b91af">MouseWheelEventHandler</span>(AnimatedScrollViewer_PreviewMouseWheel);    <br />}<a href="http://11011.net/software/vspaste"></a></p>
<p>Before we address the three event handlers we added, we need to create the Dependency Properties with which they will be futzing.</p>
<p>(We’re going start going a little bit faster. Please download the code for the excruciating detail.) We need to add the following Dependency Properties. I’m using a “PropertyName (type)”. </p>
<h3>Dependency Properties</h3>
<p><strong>ScrollingTime (TimeSpan)</strong> – This will be an easy way to change the speed of the scrolling. I created mine to default at half a second, but if you changed it to 0 seconds, it would act just like any normal ScrollViewer.</p>
<p><strong>ScrollingSpline (KeySpline)</strong> – This property along with the ScrollingTime property is meant to give designers and developers the easiest control possible over the animation. This property describes the spline along which the scrolling will animate. If you don’t know what this means, just leave it alone, you’ll be fine. </p>
<p><strong>TargetVerticalOffset (double)</strong> and <strong>TargetHorizontalOffset (double)</strong> – These are properties that tell the ScrollViewer where it will be animating to. In the PropertyChangedCallback, they kick off a method that starts the animation.</p>
<p><strong>VerticalScrollOffset (double)</strong> and <strong>HorizontalScrollOffset (double)</strong> – For some reason the normal VerticalOffset and HorizontalOffset properties in a ScrollViewer are not capable of animation. So I wrote these properties that can be animated using standard storyboard procedures. If you use them to animate, make sure you also change the TargetVerticalOffset and TargetHorizontalOffset stuff as well… otherwise there will be a disconnect between the two. </p>
<h3>Event Handlers</h3>
<p><strong>CustomPreviewMouseWheel</strong> event handler – This grabs any mouse wheel spinning and uses it to change the TargetVerticalOffset so that the ScrollViewer will still animate the scrolling when the mouse wheel spins.</p>
<p><strong>VScrollBar_ValueChanged</strong> and <strong>HScrollBar_ValueChanged</strong> event handlers – These are called whenever the the ScrollBars are interacted with. There was a really weird problem with some of the interaction (the arrow keys and fast-scrolling buttons weren’t working properly), so these handlers hold logic to try to translate the weirdness into something viable. They then set the Target_Offset properties appropriately.</p>
<h3>Methods</h3>
<p><strong>animateScroller</strong> – This method builds the animation programmatically based off of the appropriate properties and runs it. </p>
<p> And that’s really about it. Once you have the AnimatedScrollViewer working, you can just add use it inside your ListBox templates and it should work. (For those who are averse to doing such a thing, I’ve added extremely simple AnimatedListBox.) </p>
<iframe src="http://www.facebook.com/plugins/like.php?href=http://www.designersilverlight.com/2009/05/06/how-to-create-an-animated-scrollviewer-or-listbox-in-wpf/&amp;layout=standard&amp;show_faces=1&amp;width=450&amp;action=like&amp;colorscheme=light&amp;font=" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:25px"></iframe><div class="tweetthis" style="text-align:left;"><p> <a target="_blank" rel="nofollow" class="tt" href="http://twitter.com/intent/tweet?text=How+To+Create+An+Animated+ScrollViewer+%28or+ListBox%29+in+WPF+http%3A%2F%2Fdesignersilverlight.com%2F%3Fp%3D653" title="Post to Twitter"><img class="nothumb" src="http://www.designersilverlight.com/wp-content/plugins/tweet-this/icons/en/twitter/tt-twitter.png" alt="Post to Twitter" /></a> <a target="_blank" rel="nofollow" class="tt" href="http://twitter.com/intent/tweet?text=How+To+Create+An+Animated+ScrollViewer+%28or+ListBox%29+in+WPF+http%3A%2F%2Fdesignersilverlight.com%2F%3Fp%3D653" title="Post to Twitter">Tweet This Post</a></p></div>]]></content:encoded>
			<wfw:commentRss>http://www.designersilverlight.com/2009/05/06/how-to-create-an-animated-scrollviewer-or-listbox-in-wpf/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>INotifyPropertyChanged Snippets (And Why You Should Use These Instead of DependencyProperties)</title>
		<link>http://www.designersilverlight.com/2009/04/30/inotifypropertychanged-snippets-and-why-you-should-use-these-instead-of-dependencyproperties/</link>
		<comments>http://www.designersilverlight.com/2009/04/30/inotifypropertychanged-snippets-and-why-you-should-use-these-instead-of-dependencyproperties/#comments</comments>
		<pubDate>Fri, 01 May 2009 01:53:56 +0000</pubDate>
		<dc:creator>Matthias Shapiro</dc:creator>
				<category><![CDATA[Advanced Tutorial]]></category>
		<category><![CDATA[Binding]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[How To...]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://www.designersilverlight.com/2009/04/30/inotifypropertychanged-snippets-and-why-you-should-use-these-instead-of-dependencyproperties/</guid>
		<description><![CDATA[First things first, here are my INotifyPropertyChanged snippets. INotifyPropertyChanged snippet (PropertyChangedEventHandler and RaisePropertyChanged method) INotifyPropertyChanged Property snippet Just download them into your &#34;Visual Studio 2008CodeSnippetsVisual C#My CodeSnippets&#34; folder and they should work. Just type &#34;notify&#34; and intellisense should show you &#34;notifyo&#34; (for NotifyObject) and &#34;notifyp&#34; (for NotifyProperty). Hit tab twice and the code should dump [...]]]></description>
			<content:encoded><![CDATA[<p>First things first, here are my INotifyPropertyChanged snippets. </p>
<p><a href="http://www.designersilverlight.com/wp-content/uploads/2009/04/notifyo.snippet">INotifyPropertyChanged snippet (PropertyChangedEventHandler and RaisePropertyChanged method)</a></p>
<p><a href="http://www.designersilverlight.com/wp-content/uploads/2009/04/notify_p.snippet">INotifyPropertyChanged Property snippet</a></p>
<p>Just download them into your &quot;Visual Studio 2008CodeSnippetsVisual C#My CodeSnippets&quot; folder and they should work. Just type &quot;notify&quot; and intellisense should show you &quot;notifyo&quot; (for NotifyObject) and &quot;notifyp&quot; (for NotifyProperty). Hit tab twice and the code should dump into your project.</p>
<p>This is definitely a &quot;use at your own risk&quot; project. </p>
<p>You see, there I was, minding my own business and trying to build some data to use with some XAML comps I was playing with and I was having some of the strangest things happen with my data. I had a DependecyProperty ObservableCollection in my ViewModel and I put a couple different views in my screen. (I was using an MVVM pattern, because that&#8217;s what all the kool kids are doing.) </p>
<p>Then, it suddenly seemed as if all my Views were sharing the same ObservableCollection, even though every other DependencyProperty they were bound to had unique values. So I did what I always do when I have problems like this&#8230; I ask <a href="http://xamlcoder.com/cs/blogs/joe/default.aspx">Joe McBride</a>.</p>
<p>It turns out I had gotten confused. I understood that DependencyProperties were good for the following:</p>
<ul>
<li>Providing callbacks when the property is changed</li>
<li>Binding to stuff</li>
<li>Animations</li>
</ul>
<p>I figured that this is the kind of behavior I wanted from my data. I was wrong. As it turns out that is the kind of behavior I want out of the properties that I use in my <em>WPF and Silverlight controls</em>. It seems that DependencyProperties are meant to be <em>used with controls and not for stand-alone data</em>. </p>
<p>For stand-alone data, I should have used INotifyPropertyChanged, which is an interface for&#8230; well&#8230; notifying things when a property changes. I already had handy snippets for creating DependencyProperties (thanks to <a href="http://labs.nerdplusart.com/">Robby Ingebretsen</a>). So I tweaked his snippets so that they work for INotifyPropertyChanged properties.</p>
<p>Because it seems silly to implement the PropertyChangedEventHandler in every class that needs notify-able properties, I like to create a &quot;NotifyObject&quot; class:</p>
<p><span style="color: blue">class </span><span style="color: #2b91af">NotifyObject </span>: <span style="color: #2b91af">INotifyPropertyChanged     <br /></span>{    <br />&#160;&#160;&#160; <span style="color: blue">public event </span><span style="color: #2b91af">PropertyChangedEventHandler </span>PropertyChanged;    </p>
<p>&#160;&#160;&#160; <span style="color: blue">protected void </span>RaisePropertyChanged(<span style="color: blue">string </span>propertyName)    <br />&#160;&#160;&#160; {    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">var </span>handler = PropertyChanged;    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">if</span>(handler != <span style="color: blue">null</span>)    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; {    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; handler(<span style="color: blue">this</span>, <span style="color: blue">new </span><span style="color: #2b91af">PropertyChangedEventArgs</span>(propertyName));    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; }    <br />&#160;&#160;&#160; }&#160;&#160;&#160;&#160;&#160;&#160;&#160; <br />}</p>
<p>Then, I can make my new class inherit from NotifyObject and away I go creating my bindable, notify-able data:</p>
<p><span style="color: blue">public class </span><span style="color: #2b91af">MyNotifyableData </span>: <span style="color: #2b91af">NotifyObject     <br /></span>{    <br />&#160;&#160;&#160; <span style="color: blue">public </span>MyNotifyableData()    <br />&#160;&#160;&#160; {    <br />&#160;&#160;&#160; }    </p>
<p>&#160;&#160;&#160; <span style="color: blue">#region </span>MyProperty (INotifyPropertyChanged Property)    <br />&#160;&#160;&#160; <span style="color: blue">private string </span>_myProperty;    </p>
<p>&#160;&#160;&#160; <span style="color: blue">public string </span>MyProperty    <br />&#160;&#160;&#160; {    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">get </span>{ <span style="color: blue">return </span>_myProperty; }    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">set     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span>{    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; _myProperty = <span style="color: blue">value</span>;    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; RaisePropertyChanged(<span style="color: #a31515">&quot;MyProperty&quot;</span>);    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; }    <br />&#160;&#160;&#160; }    <br />&#160;&#160;&#160; <span style="color: blue">#endregion     <br /></span>}</p>
<p>This property was created using my snippet above. Hope it helps.</p>
<iframe src="http://www.facebook.com/plugins/like.php?href=http://www.designersilverlight.com/2009/04/30/inotifypropertychanged-snippets-and-why-you-should-use-these-instead-of-dependencyproperties/&amp;layout=standard&amp;show_faces=1&amp;width=450&amp;action=like&amp;colorscheme=light&amp;font=" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:25px"></iframe><div class="tweetthis" style="text-align:left;"><p> <a target="_blank" rel="nofollow" class="tt" href="http://twitter.com/intent/tweet?text=INotifyPropertyChanged+Snippets+%28And+Why+You+Should+Use+These+Instead+of+DependencyProperties%29+http%3A%2F%2Fdesignersilverlight.com%2F%3Fp%3D640" title="Post to Twitter"><img class="nothumb" src="http://www.designersilverlight.com/wp-content/plugins/tweet-this/icons/en/twitter/tt-twitter.png" alt="Post to Twitter" /></a> <a target="_blank" rel="nofollow" class="tt" href="http://twitter.com/intent/tweet?text=INotifyPropertyChanged+Snippets+%28And+Why+You+Should+Use+These+Instead+of+DependencyProperties%29+http%3A%2F%2Fdesignersilverlight.com%2F%3Fp%3D640" title="Post to Twitter">Tweet This Post</a></p></div>]]></content:encoded>
			<wfw:commentRss>http://www.designersilverlight.com/2009/04/30/inotifypropertychanged-snippets-and-why-you-should-use-these-instead-of-dependencyproperties/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Using the &quot;Tag&quot; Field And Triggers To Avoid Writing a Value Converter in WPF</title>
		<link>http://www.designersilverlight.com/2009/03/08/using-the-tag-field-and-triggers-to-avoid-writing-a-value-converter-in-wpf/</link>
		<comments>http://www.designersilverlight.com/2009/03/08/using-the-tag-field-and-triggers-to-avoid-writing-a-value-converter-in-wpf/#comments</comments>
		<pubDate>Mon, 09 Mar 2009 04:50:04 +0000</pubDate>
		<dc:creator>Matthias Shapiro</dc:creator>
				<category><![CDATA[Binding]]></category>
		<category><![CDATA[Blend]]></category>
		<category><![CDATA[How To...]]></category>
		<category><![CDATA[styles]]></category>
		<category><![CDATA[Triggers]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[XAML]]></category>

		<guid isPermaLink="false">http://www.designersilverlight.com/2009/03/08/using-the-tag-field-and-triggers-to-avoid-writing-a-value-converter-in-wpf/</guid>
		<description><![CDATA[I was working on a project recently and I wanted one of my layout controls to have a different margin based on a certain piece of data. (It&#8217;s a long story&#8230; let&#8217;s just say that this is a good post if you want to change properties of a control based on a piece of data [...]]]></description>
			<content:encoded><![CDATA[<p>I was working on a project recently and I wanted one of my layout controls to have a different margin based on a certain piece of data.</p>
<p>(It&#8217;s a long story&#8230; let&#8217;s just say that this is a good post if you want to change properties of a control based on a piece of data of a different type.)</p>
<p>So&#8230; for the sake of the argument, let&#8217;s say that I want my control to have a margin of &#8220;4,4,4,4&#8243; if my data returns &#8220;dog&#8221; and I want it to have a margin of &#8220;2,2,2,2&#8243; if my data returns &#8220;cat&#8221; and a margin of &#8220;0,0,0,0&#8243; if the data is anything else.</p>
<p>Normally, I would use a value converter for this. My problem was that I was sick of using value converters for things so specific and using them only a couple times in my application. So I decided I wanted to do this one with styles and triggers.</p>
<p>First thing I did was bind my data to the “Tag” field.</p>
<p><span style="color: blue">&lt;</span><span style="color: #a31515">Border </span><span style="color: red">Style</span><span style="color: blue">=&#8221;{</span><span style="color: #a31515">DynamicResource </span><span style="color: red">MyBorderWithTriggers</span><span style="color: blue">}&#8221; </span><span style="color: red">Tag</span><span style="color: blue">=&#8221;{</span><span style="color: #a31515">Binding </span><span style="color: red">MySpecialData</span><span style="color: blue">}&#8221; &gt;</span></p>
<p>Then, I created a style for my Border layout control. If you’re in Blend, go to Object –&gt; Edit Style –&gt; Create Empty…</p>
<p><a href="http://www.designersilverlight.com/wp-content/uploads/2009/03/clip-image001.png"><img style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" title="clip_image001" src="http://www.designersilverlight.com/wp-content/uploads/2009/03/clip-image001-thumb.png" border="0" alt="clip_image001" width="368" height="320" /></a></p>
<p>Create a new property trigger by clicking on the “+ Property” button and change the property to “Tag”.</p>
<p><a href="http://www.designersilverlight.com/wp-content/uploads/2009/03/clip-image0015.png"><img style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" title="clip_image001[5]" src="http://www.designersilverlight.com/wp-content/uploads/2009/03/clip-image0015-thumb.png" border="0" alt="clip_image001[5]" width="314" height="185" /></a></p>
<p>I couldn’t find a way to type “dog” into the field value, so I did it in the XAML (full XAML sample below, for those of you who want to cut to the chase… you know who you are).</p>
<p>With the property trigger highlighted, you’ll see a “Trigger recording is on” sign in the corner of your canvas.</p>
<p><a href="http://www.designersilverlight.com/wp-content/uploads/2009/03/clip-image0017.png"><img style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" title="clip_image001[7]" src="http://www.designersilverlight.com/wp-content/uploads/2009/03/clip-image0017-thumb.png" border="0" alt="clip_image001[7]" width="170" height="39" /></a></p>
<p>Just change all the properties you want. Of course, in this case, I’m just going to change the Margin property. If we do the same thing for the “Cat” contingency, we get the following style.</p>
<p><span style="color: blue">&lt;</span><span style="color: #a31515">Style </span><span style="color: red">x</span><span style="color: blue">:</span><span style="color: red">Key</span><span style="color: blue">=&#8221;MyBorderWithTriggers&#8221; </span><span style="color: red">TargetType</span><span style="color: blue">=&#8221;{</span><span style="color: #a31515">x</span><span style="color: blue">:</span><span style="color: #a31515">Type </span><span style="color: red">Border</span><span style="color: blue">}&#8221;&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;</span><span style="color: #a31515">Setter </span><span style="color: red">Property</span><span style="color: blue">=&#8221;Margin&#8221; </span><span style="color: red">Value</span><span style="color: blue">=&#8221;0,0,0,0&#8243;/&gt;</span>&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: blue">&lt;</span><span style="color: #a31515">Style.Triggers</span><span style="color: blue">&gt;<br />
</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: blue"> &lt;</span><span style="color: #a31515">Trigger </span><span style="color: red">Property</span><span style="color: blue">=&#8221;Tag&#8221; </span><span style="color: red">Value</span><span style="color: blue">=&#8221;Dog&#8221;&gt;<br />
</span><span style="color: blue"> </span><span style="color: blue"> </span><span style="color: blue"> </span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: blue">&lt;</span><span style="color: #a31515">Setter </span><span style="color: red">Property</span><span style="color: blue">=&#8221;Margin&#8221; </span><span style="color: red">Value</span><span style="color: blue">=&#8221;4,4,4,4&#8243;/&gt;</span><span style="color: blue"> </span><span style="color: blue"> </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: blue"> &lt;/</span><span style="color: #a31515">Trigger</span><span style="color: blue">&gt;<br />
</span><span style="color: blue"> </span><span style="color: blue"> </span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: blue">&lt;</span><span style="color: #a31515">Trigger </span><span style="color: red">Property</span><span style="color: blue">=&#8221;Tag&#8221; </span><span style="color: red">Value</span><span style="color: blue">=&#8221;Cat&#8221;&gt;<br />
</span><span style="color: blue"> </span><span style="color: blue"> </span><span style="color: blue"> </span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: blue">&lt;</span><span style="color: #a31515">Setter </span><span style="color: red">Property</span><span style="color: blue">=&#8221;Margin&#8221; </span><span style="color: red">Value</span><span style="color: blue">=&#8221;2,2,2,2&#8243;/&gt;<br />
</span><span style="color: blue"> </span><span style="color: blue"> </span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: blue">&lt;/</span><span style="color: #a31515">Trigger</span><span style="color: blue">&gt;<br />
</span><span style="color: blue"> </span>&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: blue"> &lt;/</span><span style="color: #a31515">Style.Triggers</span><span style="color: blue">&gt;<br />
&lt;/</span><span style="color: #a31515">Style</span><span style="color: blue">&gt;</span></p>
<p>And we end up with a layout that changes its properties based on a bound value. And we don’t have to write endless value converters.  Pretty handy… or at least I thought so.</p>
<iframe src="http://www.facebook.com/plugins/like.php?href=http://www.designersilverlight.com/2009/03/08/using-the-tag-field-and-triggers-to-avoid-writing-a-value-converter-in-wpf/&amp;layout=standard&amp;show_faces=1&amp;width=450&amp;action=like&amp;colorscheme=light&amp;font=" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:25px"></iframe><div class="tweetthis" style="text-align:left;"><p> <a target="_blank" rel="nofollow" class="tt" href="http://twitter.com/intent/tweet?text=Using+the+%22Tag%22+Field+And+Triggers+To+Avoid+Writing+a+Value+Converter+in+WPF+http%3A%2F%2Fdesignersilverlight.com%2F%3Fp%3D604" title="Post to Twitter"><img class="nothumb" src="http://www.designersilverlight.com/wp-content/plugins/tweet-this/icons/en/twitter/tt-twitter.png" alt="Post to Twitter" /></a> <a target="_blank" rel="nofollow" class="tt" href="http://twitter.com/intent/tweet?text=Using+the+%22Tag%22+Field+And+Triggers+To+Avoid+Writing+a+Value+Converter+in+WPF+http%3A%2F%2Fdesignersilverlight.com%2F%3Fp%3D604" title="Post to Twitter">Tweet This Post</a></p></div>]]></content:encoded>
			<wfw:commentRss>http://www.designersilverlight.com/2009/03/08/using-the-tag-field-and-triggers-to-avoid-writing-a-value-converter-in-wpf/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Using Silverlight to Display JSON Data (Collected From The New York Times API)</title>
		<link>http://www.designersilverlight.com/2009/02/25/using-silverlight-to-display-json-data-collected-from-the-new-york-times-api/</link>
		<comments>http://www.designersilverlight.com/2009/02/25/using-silverlight-to-display-json-data-collected-from-the-new-york-times-api/#comments</comments>
		<pubDate>Thu, 26 Feb 2009 07:36:00 +0000</pubDate>
		<dc:creator>Matthias Shapiro</dc:creator>
				<category><![CDATA[Binding]]></category>
		<category><![CDATA[Blend]]></category>
		<category><![CDATA[How To...]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[without a line of code]]></category>
		<category><![CDATA[XAML]]></category>

		<guid isPermaLink="false">http://www.designersilverlight.com/2009/02/25/using-silverlight-to-display-json-data-collected-from-the-new-york-times-api/</guid>
		<description><![CDATA[In this post, you’ll either need to walk through this tutorial on how to call and prepare JSON data gathered from the New York Times API or, if you’re not particularly interested in doing that, you can just download the final project here. This tutorial pretty much assumes that you’re starting from the end of [...]]]></description>
			<content:encoded><![CDATA[<p>In this post, you’ll either need to walk through this tutorial on <a href="http://www.designersilverlight.com/2009/02/25/adventures-with-json-and-silverlight-and-the-new-york-times/">how to call and prepare JSON data gathered from the New York Times API</a> or, if you’re not particularly interested in doing that, <a href="http://www.designersilverlight.com/wp-content/uploads/2009/02/jsonnewyorktimestutorial_part_1.zip">you can just download the final project here</a>. This tutorial pretty much assumes that you’re starting from the end of that tutorial.</p>
<p>Fortunately for everyone involved (especially me), this tutorial is much shorter. It is also another in my “without a line of code” series in which you can do everything without even touching the code. Let’s open up our project in Blend and get started. (To see an example what this tutorial makes, scroll to the bottom of this post.)</p>
<p>First of all, I lied. You do have to touch one line of code because <a href="http://developer.nytimes.com/apps/register">you need to get your NYT API key</a> and plug it into the myApiKey variable in the Page constructor (line 26 in the project available for download). The line should look like this:</p>
<p>myApiKey = <span style="color: #a31515">&#8220;&amp;api-key=your_api_key_here&#8221;</span>;</p>
<p>Now, right click on the project solution and select “Build Solution” (in Visual Studio or Blend, it doesn’t matter).</p>
<p><a href="http://www.designersilverlight.com/wp-content/uploads/2009/02/clip-image0011.png"><img style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" title="clip_image001" src="http://www.designersilverlight.com/wp-content/uploads/2009/02/clip-image001-thumb1.png" border="0" alt="clip_image001" width="349" height="149" /></a></p>
<p>This should build the assemblies so that Blend can do a really neat trick. In the Project tab in Blend, you should see a Data panel in the bottom half. Click on the &#8220;+ CLR Object” button.</p>
<p><a href="http://www.designersilverlight.com/wp-content/uploads/2009/02/clip-image00151.png"><img style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" title="clip_image001[5]" src="http://www.designersilverlight.com/wp-content/uploads/2009/02/clip-image0015-thumb1.png" border="0" alt="clip_image001[5]" width="298" height="60" /></a></p>
<p>A pop-up will gently encourage you to name your new data source and choose from a list of available data sources. Select “NYTResult” and hit OK.</p>
<p><a href="http://www.designersilverlight.com/wp-content/uploads/2009/02/clip-image00171.png"><img style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" title="clip_image001[7]" src="http://www.designersilverlight.com/wp-content/uploads/2009/02/clip-image0017-thumb1.png" border="0" alt="clip_image001[7]" width="398" height="228" /></a></p>
<p>You will now have your NYTResult data source show up in your Data pane. Before we start building a nice slick looking interface, select your ListBox (named “ResultsDisplay”) and, in the Properties pane, find the “Display Member Path” and reset it by clicking on the little gray box to the right.</p>
<p><a href="http://www.designersilverlight.com/wp-content/uploads/2009/02/clip-image001131.png"><img style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" title="clip_image001[13]" src="http://www.designersilverlight.com/wp-content/uploads/2009/02/clip-image00113-thumb1.png" border="0" alt="clip_image001[13]" width="298" height="170" /></a></p>
<p>Now, right-click on the ListBox  in your “Objects and Timeline” panel and select “Bind ItemsSource to Data…”</p>
<p><a href="http://www.designersilverlight.com/wp-content/uploads/2009/02/clip-image00191.png"><img style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" title="clip_image001[9]" src="http://www.designersilverlight.com/wp-content/uploads/2009/02/clip-image0019-thumb1.png" border="0" alt="clip_image001[9]" width="269" height="263" /></a></p>
<p>Select the data source you just created and select “NYTResult”. Then click on “Define DataTemplate” at the bottom. This will take you to the “Create Data Template” panel, where the fun happens. You will see “New Data Template and Display Fields” automatically selected. We like this. This lets us select all the data we want and give it some basic structure and Blend will do all the bindings for us.</p>
<p>Let’s make a few changes from the standard Data Template setup. Expand the Date field and check Day, DayOfWeek, Month, and Year and change the order with the up and down buttons to something you like. Then, change the Url from “StackPanel” to “TextBlock”. I reordered the data a little bit, so my template looks like this:</p>
<p><a href="http://www.designersilverlight.com/wp-content/uploads/2009/02/clip-image001151.png"><img style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" title="clip_image001[15]" src="http://www.designersilverlight.com/wp-content/uploads/2009/02/clip-image00115-thumb1.png" border="0" alt="clip_image001[15]" width="332" height="321" /></a></p>
<p>Hit OK. The point of that whole exercise was so that Blend would build our data template for us. We don’t actually want the data source and we don’t want our ListBox bound to it. So reset the “ItemSource” property on the ListBox and remove the NYTResult data source. If you run the project now, you should get something like this:</p>
<p><a href="http://www.designersilverlight.com/wp-content/uploads/2009/02/clip-image00117.png"><img style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" title="clip_image001[17]" src="http://www.designersilverlight.com/wp-content/uploads/2009/02/clip-image00117-thumb.png" border="0" alt="clip_image001[17]" width="411" height="309" /></a></p>
<p>At least we’re getting more data now. Doesn’t look that great, but we’re getting there. Go back to your project in Blend and right-click on your ListBox and go to “Edit Other Templates –&gt; Edit Generated Items (ItemTemplate) –&gt; Edit Template”</p>
<p><a href="http://www.designersilverlight.com/wp-content/uploads/2009/02/clip-image00119.png"><img style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" title="clip_image001[19]" src="http://www.designersilverlight.com/wp-content/uploads/2009/02/clip-image00119-thumb.png" border="0" alt="clip_image001[19]" width="555" height="344" /></a></p>
<p>We’re now in the DataTemplate but we sadly have no visible data, which makes manipulating it a tad difficult. What I have found works best for me is just to build my desired layout with static data and then translate the bindings. (I haven’t mentioned this, but <a href="http://www.designersilverlight.com/2009/02/04/6-tips-for-designers-for-translating-your-comps-into-xaml/">you should be working in Split mode as a general rule</a>, so you should be able to see the bindings in the XAML.)</p>
<p>So… long story short (it’s getting really late here): I changed the layout to replicate the NYT story design… the Title is a hyperlink button that takes us to the full story, followed by a small byline, the beginning of the story and the date on which the story appeared. If you’d like to look at the design itself in more detail, download the project at the end of this post.</p>
<p>I do want to mention one issue… the issue of getting your text to wrap. With my current redesigned DataTemplate, my project looks like this:</p>
<p><a href="http://www.designersilverlight.com/wp-content/uploads/2009/02/clip-image00121.png"><img style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" title="clip_image001[21]" src="http://www.designersilverlight.com/wp-content/uploads/2009/02/clip-image00121-thumb.png" border="0" alt="clip_image001[21]" width="411" height="311" /></a></p>
<p>It scrolls horizontally to a degree that is certainly unhealthy. What is happening is that the TextBlock in the DataTemplate is making a request for space and when it hits a limit, it will start wrapping. Unfortunately for us, when the ScrollViewer in the ListBox has the HorizontalScrollBarVisibility set to “Auto”, it is telling the TextBlock that it has all the room in the world and that it doesn’t need to wrap. So, let’s just change the HorizontalScrollBarVisibility on the ListBox to “Disabled”.</p>
<p>And we’re done.</p>
<p><iframe src="http://silverlight.services.live.com/invoke/77530/JSON_NYT_Tutorial_Part_2/iframe.html" scrolling="no" frameborder="0" style="width:400px; height:500px"></iframe></p>
<p>You can download the source here</p>
<p><a href="http://www.designersilverlight.com/wp-content/uploads/2009/02/jsonnewyorktimestutorial_part_2.zip">JSON &#8211; Silverlight &#8211; New York Times Tutorial (Part 2) Project Files</a></p>
<p>Questions and comments are always welcome.</p>
<iframe src="http://www.facebook.com/plugins/like.php?href=http://www.designersilverlight.com/2009/02/25/using-silverlight-to-display-json-data-collected-from-the-new-york-times-api/&amp;layout=standard&amp;show_faces=1&amp;width=450&amp;action=like&amp;colorscheme=light&amp;font=" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:25px"></iframe><div class="tweetthis" style="text-align:left;"><p> <a target="_blank" rel="nofollow" class="tt" href="http://twitter.com/intent/tweet?text=Using+Silverlight+to+Display+JSON+Data+%28Collected+From+The+New+York+Times+API%29+http%3A%2F%2Fdesignersilverlight.com%2F%3Fp%3D579" title="Post to Twitter"><img class="nothumb" src="http://www.designersilverlight.com/wp-content/plugins/tweet-this/icons/en/twitter/tt-twitter.png" alt="Post to Twitter" /></a> <a target="_blank" rel="nofollow" class="tt" href="http://twitter.com/intent/tweet?text=Using+Silverlight+to+Display+JSON+Data+%28Collected+From+The+New+York+Times+API%29+http%3A%2F%2Fdesignersilverlight.com%2F%3Fp%3D579" title="Post to Twitter">Tweet This Post</a></p></div>]]></content:encoded>
			<wfw:commentRss>http://www.designersilverlight.com/2009/02/25/using-silverlight-to-display-json-data-collected-from-the-new-york-times-api/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Adventures with JSON and Silverlight (and the New York Times)</title>
		<link>http://www.designersilverlight.com/2009/02/25/adventures-with-json-and-silverlight-and-the-new-york-times/</link>
		<comments>http://www.designersilverlight.com/2009/02/25/adventures-with-json-and-silverlight-and-the-new-york-times/#comments</comments>
		<pubDate>Thu, 26 Feb 2009 00:17:56 +0000</pubDate>
		<dc:creator>Matthias Shapiro</dc:creator>
				<category><![CDATA[Advanced Tutorial]]></category>
		<category><![CDATA[Blend]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[How To...]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[New York Times API]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://www.designersilverlight.com/2009/02/25/adventures-with-json-and-silverlight-and-the-new-york-times/</guid>
		<description><![CDATA[Summary: In this post, I walk through the basics of using Silverlight to query the New York Times Article API and display the results of the query. You can see the final result below. You can also download source code for this project here. JSON/Silverlight/New York Times project files Huge thanks to Josh Holmes, whose [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Summary:</strong> In this post, I walk through the basics of using Silverlight to query the New York Times Article API and display the results of the query. You can see the final result below.</p>
<p><iframe src="http://silverlight.services.live.com/invoke/77530/JSON_NYT_Tutorial_Part_1/iframe.html" scrolling="no" frameborder="0" style="width:400px; height:300px"></iframe></p>
<p>You can also download source code for this project here.</p>
<p><a href="http://www.designersilverlight.com/wp-content/uploads/2009/02/jsonnewyorktimestutorial_part_1.zip">JSON/Silverlight/New York Times project files </a></p>
<p>Huge thanks to Josh Holmes, whose <a href="http://www.joshholmes.com/blog/2009/01/20/PlayingWithJSON.aspx">JSON/Silverlight tutorial</a> was the base of much of this project.</p>
<p>This project is somewhat code-intensive (and kind of long, expect 30-60 minutes), so if you just want the utility provided here without any of the work, you can skip over to <a href="http://www.designersilverlight.com/2009/02/25/using-silverlight-to-display-json-data-collected-from-the-new-york-times-api/">my post on displaying the results</a>, which is strictly a Blend tutorial.</p>
<p>However, I recommend walking through this one since it will help get you to a point of pulling real data from an API, which I’ve found to be a wonderful help as I practice putting together data-based designs. One of the things I&#8217;ve been wanting to be able to do as a designer is to explore a data set easily and quickly so that I can have data to play with in my interfaces. I found exactly what I wanted in the New York Times API, but then I found out I had to learn JSON.</p>
<p>&#8220;Oh great,&#8221; I said to myself, &#8220;another technology for me to learn.&#8221; But it turned out that I didn&#8217;t actually have to learn that much, because Visual Studio does nearly all the work for me.</p>
<h3>Super Quick Introduction to JSON</h3>
<p>If you&#8217;re not interested and you want to get to the business of grabbing New York Times data, you can skip it . It is helpful, but not strictly necessary.</p>
<p>JSON stands for JavaScript Object Notation and is basically just a really handy way to pass data along in a web service. It is very simple&#8230; within a set of curly brackets, you will have name/value pairs separated by a colon with each piece of data.<br />
Example:<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;FirstName : &#8220;Matthias&#8221;,<br />
&nbsp;&nbsp;&nbsp;&nbsp;LastName : &#8220;Shapiro&#8221;,<br />
&nbsp;&nbsp;&nbsp;&nbsp;Blog : &#8220;Designer WPF&#8221;<br />
}</p>
<p>This is a JSON object. Arrays are created by using square brackets and JSON obejcts can be placed into a Javascript var. These things are not really related in anyway, but putting them in the same sentence allows me to only write one more example instead of two</p>
<p>Example:<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;FirstName: “Matthias”,<br />
&nbsp;&nbsp;&nbsp;&nbsp;LastName: “Shapiro”,<br />
&nbsp;&nbsp;&nbsp;&nbsp;Siblings : [<br />
&nbsp;&nbsp;&nbsp;&nbsp;{Name : “Abby”},<br />
&nbsp;&nbsp;&nbsp;&nbsp;{Name : “Joel”},<br />
&nbsp;&nbsp;&nbsp;&nbsp;{Name : “Anna”},<br />
&nbsp;&nbsp;&nbsp;&nbsp;{Name : “John”},<br />
&nbsp;&nbsp;&nbsp;&nbsp;{Name : “Nate”}<br />
&nbsp;&nbsp;&nbsp;&nbsp;]<br />
}</p>
<p>And there we have the basics of JSON.</p>
<h3>End of Super Quick Introduction to JSON</h3>
<p>What is so awesome about JSON and Silverlight is that Visual Studio 2008 has a set of JSON-friendly classes that make working with JSON a breeze. Which is really handy because the New York Times, which is a dream come true for the new data-gatherer, delivers JSON results. So let’s walk through making a call to the New York Times Article API, handling the data we get back, and putting it into a Listbox for viewing.</p>
<p>First, <a href="http://developer.nytimes.com/">go to the New York Times Developer site</a>, log in (or register) and get your API key.</p>
<p>Next, start a new Silverlight project in Visual Studio 2008. I named mine “JSONNewYorkTimesTutorial”.</p>
<p><a href="http://www.designersilverlight.com/wp-content/uploads/2009/02/clip-image0019.png"><img style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" title="clip_image001[9]" src="http://www.designersilverlight.com/wp-content/uploads/2009/02/clip-image0019-thumb.png" border="0" alt="clip_image001[9]" width="659" height="424" /></a></p>
<p>Open your new project in Blend, pull up Page.xaml and add a TextBlock, ListBox, a TextBox and a Button. Name the ListBox “ResultsDisplay” and the TextBox “SearchText”.</p>
<p><a href="http://www.designersilverlight.com/wp-content/uploads/2009/02/clip-image00113.png"><img style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" title="clip_image001[13]" src="http://www.designersilverlight.com/wp-content/uploads/2009/02/clip-image00113-thumb.png" border="0" alt="clip_image001[13]" width="299" height="105" /></a></p>
<p>Now, my Page.xaml looks like this.</p>
<p><a href="http://www.designersilverlight.com/wp-content/uploads/2009/02/clip-image00111.png"><img style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" title="clip_image001[11]" src="http://www.designersilverlight.com/wp-content/uploads/2009/02/clip-image00111-thumb.png" border="0" alt="clip_image001[11]" width="457" height="346" /></a></p>
<p>OK… now let’s go to the code-behind for our project go to the event section of the button in Blend and type “PerformQuery” into the “Click” event.</p>
<p><a href="http://www.designersilverlight.com/wp-content/uploads/2009/02/clip-image00115.png"><img style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" title="clip_image001[15]" src="http://www.designersilverlight.com/wp-content/uploads/2009/02/clip-image00115-thumb.png" border="0" alt="clip_image001[15]" width="264" height="104" /></a></p>
<p>This will automatically insert the necessary code into the code-behind, so pull up Visual Studio. Before we implement a call to the NYT API, lets add some useful stuff. If you have not yet gone to <a href="http://developer.nytimes.com/apps/register?authChecked=1">get your Developer key, do so now</a>.</p>
<p><span style="color: blue">private string </span>myApiKey;<br />
<span style="color: blue">private </span><span style="color: #2b91af">WebClient </span>callNYT;</p>
<p><span style="color: blue">public </span>Page()<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;InitializeComponent();<br />
&nbsp;&nbsp;&nbsp;&nbsp;myApiKey = <span style="color: #a31515">&#8220;&amp;api-key=(put your api key here. No, you may not have mine)&#8221;</span>;<br />
&nbsp;&nbsp;&nbsp;&nbsp;callNYT = <span style="color: blue">new </span><span style="color: #2b91af">WebClient</span>();<br />
&nbsp;&nbsp;&nbsp;&nbsp;callNYT.OpenReadCompleted += <span style="color: blue">new </span><span style="color: #2b91af">OpenReadCompletedEventHandler</span>(callNYT_OpenReadCompleted);<br />
}</p>
<p>In the code above, we’ve created a string that we can use to apply our unique NYT API key and we’ve created an instance of WebClient to call and receive information from the NYT API. When an object from the NYT API has been received , it will call the OpenReadCompleted event, which will be handled by our callNYT_OpenReadCompleted method.</p>
<p>(By the way, if you’re not getting the proper intellisense for the “Web Client” part, add “<span style="color: blue">using </span>System.Net;&#8221; to the top of your file.)</p>
<p>Now on to our button method. There are tons of things we can add to our query to find the exact information we want. But in the interest of simplicity, this post will deal only with a simple text search. To that end, let’s go to our PerformQuery method and turn it into this:</p>
<p><span style="color: blue">private void </span>PerformQuery(<span style="color: blue">object </span>sender, <span style="color: #2b91af">RoutedEventArgs </span>e)<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: blue">string </span>NYTQueryBase = <span style="color: #a31515">&#8220;http://api.nytimes.com/svc/search/v1/article&#8221;</span>;<br />
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: blue">string </span>SearchTerm = <span style="color: #a31515">&#8220;?query=&#8221;</span>+ SearchText.Text;<br />
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #2b91af">Uri </span>queryUri = <span style="color: blue">new </span><span style="color: #2b91af">Uri</span>(NYTQueryBase + SearchTerm + myApiKey);</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;callNYT.OpenReadAsync(queryUri);<br />
}</p>
<p>We’ve done two things here. The first is that we built our search query using the query base, the query string and our API key. That was simple enough.</p>
<p>Next, we’ve going to use the WebClient we created to call our new query. When the query has been completed, our program will run the callNYT_OpenReadCompleted method with its result, which will be a JSON object constructed by the NYT servers. We will get back a JSON object with the following:</p>
<ul>
<li>offset – We will get 10 results per page. The offset tells us which page of the results we’re on. The default is 0, which gives us results 0 – 9.</li>
<li>tokens – this is a array of our search terms.</li>
<li>total – this is an integer indicating of how many results there were for our search.</li>
<li>results – this is an array of results with the following format
<ul>
<li>body – a portion of the beginning of the article</li>
<li>byline – the article byline, usually including the author name</li>
<li>date – the date the article appeared, in a “yyyymmdd” format. For example, today would be “20090225”.</li>
<li>title – the article title</li>
<li>url – a url link to the article</li>
</ul>
</li>
</ul>
<p>A quick note: The NYT API is extremely flexible and we can actually define how we want our results to come back. This is just the default result format for the purposes of demonstration.</p>
<p>Before we handle this object, we want to create a class for the results. Right click on your project and go to “Add –&gt; Class…”. Name your new class “NYTResult.cs” and make sure it looks like this:</p>
<p><span style="color: blue">public class </span><span style="color: #2b91af">NYTResult </span>{<br />
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: blue">public string </span>Body { <span style="color: blue">get</span>; <span style="color: blue">set</span>; }<br />
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: blue">public string </span>Byline { <span style="color: blue">get</span>; <span style="color: blue">set</span>; }<br />
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: blue">public </span><span style="color: #2b91af">DateTime </span>Date { <span style="color: blue">get</span>; <span style="color: blue">set</span>; }<br />
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: blue">public string </span>Title { <span style="color: blue">get</span>; <span style="color: blue">set</span>; }<br />
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: blue">public </span><span style="color: #2b91af">Uri </span>Url { <span style="color: blue">get</span>; <span style="color: blue">set</span>; }<br />
}</p>
<p>I added the following method to the class to handle the date conversion from the NYT format to a .NET DateTime object.</p>
<p><span style="color: blue">public </span><span style="color: #2b91af">DateTime </span>formattedDateTime(<span style="color: blue">string </span>NYT_Time)<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: blue"><span style="color: #444444;"> </span>int </span>year = <span style="color: #2b91af">Convert</span>.ToInt32(NYT_Time.Substring(0, 4));<br />
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: blue">int </span>month = <span style="color: #2b91af">Convert</span>.ToInt32(NYT_Time.Substring(4, 2));<br />
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: blue">int </span>day = <span style="color: #2b91af">Convert</span>.ToInt32(NYT_Time.Substring(6, 2));<br />
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #2b91af">DateTime </span>finalDateTime = <span style="color: blue">new </span><span style="color: #2b91af">DateTime</span>(year, month, day);<br />
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: blue">return </span>finalDateTime;<br />
}</p>
<p>OK… now we’re really ready to handle the JSON object. Right click on the references in your project and select “Add Reference…”</p>
<p><a href="http://www.designersilverlight.com/wp-content/uploads/2009/02/clip-image001.png"><img style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" title="clip_image001" src="http://www.designersilverlight.com/wp-content/uploads/2009/02/clip-image001-thumb.png" border="0" alt="clip_image001" width="287" height="81" /></a></p>
<p>In  your “Add References” box, select “System.Json” and click “OK”.</p>
<p><a href="http://www.designersilverlight.com/wp-content/uploads/2009/02/clip-image0015.png"><img style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" title="clip_image001[5]" src="http://www.designersilverlight.com/wp-content/uploads/2009/02/clip-image0015-thumb.png" border="0" alt="clip_image001[5]" width="481" height="408" /></a></p>
<p>Add “<span style="color: blue">using </span>System.Json;” to the references in your Page.xaml.cs file. And, just for good measure, add “<span style="color: blue">using </span>System.Collections.ObjectModel;” as well.</p>
<p>Go to the callNYT_OpenReadCompleted method and enter the following. I’ve tried to comment the code so that I don’t need to further explain it. Side note: I’m not always the best at understanding what is self-explanatory and what I need to elaborate on. If there are any additional questions, post them in the comments and I’ll answer as quickly as I can.</p>
<p><span style="color: blue">void </span>callNYT_OpenReadCompleted(<span style="color: blue">object </span>sender, <span style="color: #2b91af">OpenReadCompletedEventArgs </span>e)<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: green">//grab our result and make a JSON Object out of it<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span> <span style="color: green">//    then extract the results array from that object<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span> <span style="color: #2b91af">JsonObject </span>completeResult = (<span style="color: #2b91af">JsonObject</span>)<span style="color: #2b91af">JsonObject</span>.Load(e.Result);<br />
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #2b91af">JsonArray </span>resultsArray = (<span style="color: #2b91af">JsonArray</span>)completeResult[<span style="color: #a31515">"results"</span>];</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: green">//an observable collection to hold the data and attach it to our ListBox<br />
</span><br />
&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: #2b91af">ObservableCollection</span>&lt;<span style="color: #2b91af">NYTResult</span>&gt; resultCollection = <span style="color: blue">new </span><span style="color: #2b91af">ObservableCollection</span>&lt;<span style="color: #2b91af">NYTResult</span>&gt;();</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: green">//iterate through the results and transfer the data from a<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span> <span style="color: green">//   JSON object into our nice pretty .NET object<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span> <span style="color: blue">foreach </span>(<span style="color: #2b91af">JsonObject </span>NYTRawResult <span style="color: blue">in </span>resultsArray)<br />
&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #2b91af">NYTResult </span>singleResult = <span style="color: blue">new </span><span style="color: #2b91af">NYTResult</span>();</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: green">//don&#8217;t forget to check your results&#8230; an article might not have a<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span> <span style="color: green">//  byline or a link<br />
</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue">if </span>(NYTRawResult.Keys.Contains(<span style="color: #a31515">&#8220;body&#8221;</span>))<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;singleResult.Body = NYTRawResult[<span style="color: #a31515">"body"</span>];<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: blue">if</span>(NYTRawResult.Keys.Contains(<span style="color: #a31515">&#8220;byline&#8221;</span>))<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;singleResult.Byline = NYTRawResult[<span style="color: #a31515">"byline"</span>];<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: blue">if </span>(NYTRawResult.Keys.Contains(<span style="color: #a31515">&#8220;date&#8221;</span>))<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;singleResult.Date = singleResult.formattedDateTime(NYTRawResult[<span style="color: #a31515">"date"</span>]);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: blue">if </span>(NYTRawResult.Keys.Contains(<span style="color: #a31515">&#8220;title&#8221;</span>))<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;singleResult.Title = NYTRawResult[<span style="color: #a31515">"title"</span>];<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: blue">if </span>(NYTRawResult.Keys.Contains(<span style="color: #a31515">&#8220;url&#8221;</span>))<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;singleResult.Url = <span style="color: blue">new </span><span style="color: #2b91af">Uri</span>(NYTRawResult[<span style="color: #a31515">"url"</span>]);</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: green">//add our new result to the collection<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span> resultCollection.Add(singleResult);<br />
&nbsp;&nbsp;&nbsp;&nbsp;}</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: green">//assign the result as the source for our ListBox<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span> ResultsDisplay.ItemsSource = resultCollection;</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: green">//take the overall article count and display it<br />
</span>&nbsp;&nbsp;&nbsp;&nbsp; resultCount.Text = <span style="color: #a31515">&#8220;Number of articles: &#8221; </span>+ completeResult[<span style="color: #a31515">"total"</span>].ToString();<br />
}</p>
<p>Now, we can run our project. Type something into the TextBox and hit the button and we get this:<br />
<a href="http://www.designersilverlight.com/wp-content/uploads/2009/02/clip-image0017.png"><img style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" title="clip_image001[7]" src="http://www.designersilverlight.com/wp-content/uploads/2009/02/clip-image0017-thumb.png" border="0" alt="clip_image001[7]" width="404" height="303" /></a></p>
<p>Not exactly the most readable thing ever. So let’s add the following to the ListBox XAML:</p>
<p><span style="color: red">DisplayMemberPath</span><span style="color: blue">=&#8221;Title&#8221;</span></p>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>Now we get something a little more like this (go ahead and give it a whirl):</p>
<p><iframe src="http://silverlight.services.live.com/invoke/77530/JSON_NYT_Tutorial_Part_1/iframe.html" scrolling="no" frameborder="0" style="width:400px; height:300px"></iframe></p>
<p>Much better. Remember, this is a simple query, so it’s only looking for items that have that word in the article… it might not be in the title.</p>
<p><a href="http://www.designersilverlight.com/2009/02/25/using-silverlight-to-display-json-data-collected-from-the-new-york-times-api/">My next post builds on this one</a> and I walk through building a more useful display for our results. It will be far less code intensive and far more designer centric.</p>
<p>I’ve made the source available for this project. I’ve taken out my NYT API key, so it will not run unless you get your own and put it in.</p>
<p><a href="http://www.designersilverlight.com/wp-content/uploads/2009/02/jsonnewyorktimestutorial_part_1.zip">JSON &#8211; Silverlight &#8211; New York Times Tutorial Part 1 project files</a></p>
<iframe src="http://www.facebook.com/plugins/like.php?href=http://www.designersilverlight.com/2009/02/25/adventures-with-json-and-silverlight-and-the-new-york-times/&amp;layout=standard&amp;show_faces=1&amp;width=450&amp;action=like&amp;colorscheme=light&amp;font=" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:25px"></iframe><div class="tweetthis" style="text-align:left;"><p> <a target="_blank" rel="nofollow" class="tt" href="http://twitter.com/intent/tweet?text=Adventures+with+JSON+and+Silverlight+%28and+the+New+York+Times%29+http%3A%2F%2Fdesignersilverlight.com%2F%3Fp%3D550" title="Post to Twitter"><img class="nothumb" src="http://www.designersilverlight.com/wp-content/plugins/tweet-this/icons/en/twitter/tt-twitter.png" alt="Post to Twitter" /></a> <a target="_blank" rel="nofollow" class="tt" href="http://twitter.com/intent/tweet?text=Adventures+with+JSON+and+Silverlight+%28and+the+New+York+Times%29+http%3A%2F%2Fdesignersilverlight.com%2F%3Fp%3D550" title="Post to Twitter">Tweet This Post</a></p></div>]]></content:encoded>
			<wfw:commentRss>http://www.designersilverlight.com/2009/02/25/adventures-with-json-and-silverlight-and-the-new-york-times/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Mask Animations (Clipping Path Animations) In Silverlight Without a Line of Code</title>
		<link>http://www.designersilverlight.com/2009/01/15/mask-animations-clipping-path-animations-in-silverlight-without-a-line-of-code/</link>
		<comments>http://www.designersilverlight.com/2009/01/15/mask-animations-clipping-path-animations-in-silverlight-without-a-line-of-code/#comments</comments>
		<pubDate>Thu, 15 Jan 2009 17:14:46 +0000</pubDate>
		<dc:creator>Matthias Shapiro</dc:creator>
				<category><![CDATA[Blend]]></category>
		<category><![CDATA[How To...]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[without a line of code]]></category>

		<guid isPermaLink="false">http://www.designersilverlight.com/?p=472</guid>
		<description><![CDATA[Last night I submitted my MIX 10K Challenge piece, so I’m just killing time while I wait for it to get accepted. Please keep me in mind if you plan on voting. OK… I’ve been excited about this for some time now. I found out (almost completely by accident) that you can animate a mask [...]]]></description>
			<content:encoded><![CDATA[<p>Last night I submitted my MIX 10K Challenge piece, so I’m just killing time while I wait for it to get accepted. Please keep me in mind if you plan on voting.</p>
<p>OK… I’ve been excited about this for some time now. I found out (almost completely by accident) that you can animate a mask (also known as a clipping path) in Silverlight without writing code or even typing (much). This is exciting because I think it’s something that might interest our Flash friends who, late at night and in the privacy of their own homes, take a peek to see if Silverlight is worth looking into. When I worked with Flash, mask animations were my bread and butter and they seemed so hard to do in Silverlight.</p>
<p>But they’re not.</p>
<p>First open up your project in Blend. (I always create my project in Visual Studio and then open it in Blend because visual Studio has so much better project debugging and makes testing a breeze.)</p>
<p>Find the item you want to clip (in my case this is an image) and select the pen tool from the toolbar.</p>
<p><a href="http://www.designersilverlight.com/wp-content/uploads/2009/01/clip-image001.png"><img style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" title="clip_image001" src="http://www.designersilverlight.com/wp-content/uploads/2009/01/clip-image001-thumb.png" border="0" alt="clip_image001" width="44" height="46" /></a></p>
<p>And start drawing.I’m a poor artist, so the star I drew looks pretty bad. If you need to change any of the points, use the direct selection tool (the light arrow, second from the top).</p>
<p><a href="http://www.designersilverlight.com/wp-content/uploads/2009/01/clip-image0014.png"><img style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" title="clip_image001[4]" src="http://www.designersilverlight.com/wp-content/uploads/2009/01/clip-image0014-thumb.png" border="0" alt="clip_image001[4]" width="42" height="114" /></a></p>
<p>OK… now the fun part. Add a storyboard to your project</p>
<p><a href="http://www.designersilverlight.com/wp-content/uploads/2009/01/clip-image0016.png"><img style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" title="clip_image001[6]" src="http://www.designersilverlight.com/wp-content/uploads/2009/01/clip-image0016-thumb.png" border="0" alt="clip_image001[6]" width="332" height="141" /></a></p>
<p>and you can animate the clipping mask using all the normal animation tools. Use the direct selection tool above to animate the vertices. You’ll get something like this:</p>
<p><iframe src="http://silverlight.services.live.com/invoke/77530/pathAnimation_Part1/iframe.html" scrolling="no" frameborder="0" style="width:400px; height:300px"></iframe></p>
<p>Now… if you’re not interested in the details, just skip ahead a little bit. Something important happened the moment we started animating the path. Normally, path data is kept in a single string format that looks something like this:</p>
<p><span style="color: red;">Data</span><span style="color: blue;">=&#8221;M159.67175,104.26108 L177.91812,28.328932 L195.51648,104.43327 L255.0802,102.6104 L206.86984,151.82758 L225.8029,226.56477 L179.0616,179.17046 L129.73396,229.29906 L147.97842,150.63879 L98.650803,101.53297 z&#8221;</span></p>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>This is actually a “<a href="http://msdn.microsoft.com/en-us/library/cc189041(VS.95).aspx">powerful and complex mini-language</a> that that you can use to describe geometric paths in XAML.” Microsoft uses it by default to handle path data. But it doesn’t work very well for animating paths, so the second you animate a single vertex in your path, it changes the format you see above to the format you see below:</p>
<p><span style="color: blue;">&lt;</span><span style="color: #a31515;">Path.Data</span><span style="color: blue;">&gt;<br />
</span><span style="color: blue;">&lt;</span><span style="color: #a31515;">PathGeometry</span><span style="color: blue;">&gt;<br />
&lt;</span><span style="color: #a31515;">PathFigure </span><span style="color: red;">IsClosed</span><span style="color: blue;">=&#8221;True&#8221; </span><span style="color: red;">StartPoint</span><span style="color: blue;">=&#8221;91.0527648925781,84.0121078491211&#8243;&gt;<br />
&lt;</span><span style="color: #a31515;">LineSegment </span><span style="color: red;">Point</span><span style="color: blue;">=&#8221;118.057907104492,0.549586236476898&#8243;/&gt;<br />
&lt;</span><span style="color: #a31515;">LineSegment </span><span style="color: red;">Point</span><span style="color: blue;">=&#8221;144.103973388672,84.2013778686523&#8243;/&gt;<br />
&lt;</span><span style="color: #a31515;">LineSegment </span><span style="color: red;">Point</span><span style="color: blue;">=&#8221;232.259979248047,82.1977386474609&#8243;/&gt;<br />
&lt;</span><span style="color: #a31515;">LineSegment </span><span style="color: red;">Point</span><span style="color: blue;">=&#8221;160.907287597656,136.2958984375&#8243;/&gt;<br />
&lt;</span><span style="color: #a31515;">LineSegment </span><span style="color: red;">Point</span><span style="color: blue;">=&#8221;188.928756713867,218.444961547852&#8243;/&gt;<br />
&lt;</span><span style="color: #a31515;">LineSegment </span><span style="color: red;">Point</span><span style="color: blue;">=&#8221;119.750289916992,166.350433349609&#8243;/&gt;<br />
&lt;</span><span style="color: #a31515;">LineSegment </span><span style="color: red;">Point</span><span style="color: blue;">=&#8221;46.7439804077148,221.450408935547&#8243;/&gt;<br />
&lt;</span><span style="color: #a31515;">LineSegment </span><span style="color: red;">Point</span><span style="color: blue;">=&#8221;73.7462997436523,134.989212036133&#8243;/&gt;<br />
&lt;</span><span style="color: #a31515;">LineSegment </span><span style="color: red;">Point</span><span style="color: blue;">=&#8221;0.740016639232636,81.0134506225586&#8243;/&gt;<br />
&lt;/</span><span style="color: #a31515;">PathFigure</span><span style="color: blue;">&gt;<br />
&lt;/</span><span style="color: #a31515;">PathGeometry</span><span style="color: blue;">&gt;<br />
&lt;/</span><span style="color: #a31515;">Path.Data</span><span style="color: blue;">&gt;</span></p>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>Same data, but only this latter format is appropriate for animation. Remember this, it will come in handy in a second.</p>
<p>OK… now right click on your path and go to “Path –&gt; Make Clipping Path”</p>
<p><a href="http://www.designersilverlight.com/wp-content/uploads/2009/01/clip-image00110.png"><img style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" title="clip_image001[10]" src="http://www.designersilverlight.com/wp-content/uploads/2009/01/clip-image00110-thumb.png" border="0" alt="clip_image001[10]" width="367" height="52" /></a></p>
<p>You’ll get a dialog pop-up that will ask you which item in the visual tree you would like to clip. I chose my image, but it will work with anything.</p>
<p><a href="http://www.designersilverlight.com/wp-content/uploads/2009/01/clip-image00112.png"><img style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" title="clip_image001[12]" src="http://www.designersilverlight.com/wp-content/uploads/2009/01/clip-image00112-thumb.png" border="0" alt="clip_image001[12]" width="297" height="158" /></a></p>
<p>And… poof! You have clipping animation.</p>
<p><iframe src="http://silverlight.services.live.com/invoke/77530/PathAnimation_Part2/iframe.html" scrolling="no" frameborder="0" style="width:400px; height:300px"></iframe></p>
<p>LIMITATIONS: Here are the limitations to this method:</p>
<ol>
<li><strong>You need to animate before you make your path into a clipping path. – </strong>Remember that little bit above about the data string format vs. path geometry? If you don’t animate before hand, Blend will convert all your beautiful line segments into the un-animate-able data string. Animating the path tells Blend to leave your formatting alone.</li>
<li><strong>Once you make your path a clipping  path, animation gets <em>a lot</em> harder</strong> – Basically, you can change the time by dragging the key frames around and change the easing. Any other alterations require entering values by hand. So do all your animation first before setting the path. The easiest work around to this is to copy and paste your path out of the Control.Clip section and back into your main XAML and tweak animation from there. But your best option is to just take the time to make your clipping animation perfect before you make it a clipping path.</li>
</ol>
<iframe src="http://www.facebook.com/plugins/like.php?href=http://www.designersilverlight.com/2009/01/15/mask-animations-clipping-path-animations-in-silverlight-without-a-line-of-code/&amp;layout=standard&amp;show_faces=1&amp;width=450&amp;action=like&amp;colorscheme=light&amp;font=" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:25px"></iframe><div class="tweetthis" style="text-align:left;"><p> <a target="_blank" rel="nofollow" class="tt" href="http://twitter.com/intent/tweet?text=Mask+Animations+%28Clipping+Path+Animations%29+In+Silverlight+Without+a+Line+of+Code+http%3A%2F%2Fdesignersilverlight.com%2F%3Fp%3D472" title="Post to Twitter"><img class="nothumb" src="http://www.designersilverlight.com/wp-content/plugins/tweet-this/icons/en/twitter/tt-twitter.png" alt="Post to Twitter" /></a> <a target="_blank" rel="nofollow" class="tt" href="http://twitter.com/intent/tweet?text=Mask+Animations+%28Clipping+Path+Animations%29+In+Silverlight+Without+a+Line+of+Code+http%3A%2F%2Fdesignersilverlight.com%2F%3Fp%3D472" title="Post to Twitter">Tweet This Post</a></p></div>]]></content:encoded>
			<wfw:commentRss>http://www.designersilverlight.com/2009/01/15/mask-animations-clipping-path-animations-in-silverlight-without-a-line-of-code/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Swapping Content In the Code Behind in Silverlight</title>
		<link>http://www.designersilverlight.com/2008/10/23/swapping-content-in-the-code-behind-in-silverlight/</link>
		<comments>http://www.designersilverlight.com/2008/10/23/swapping-content-in-the-code-behind-in-silverlight/#comments</comments>
		<pubDate>Fri, 24 Oct 2008 03:20:57 +0000</pubDate>
		<dc:creator>Matthias Shapiro</dc:creator>
				<category><![CDATA[Advanced Tutorial]]></category>
		<category><![CDATA[How To...]]></category>
		<category><![CDATA[Silverlight]]></category>

		<guid isPermaLink="false">http://www.designersilverlight.com/2008/10/23/swapping-content-in-the-code-behind-in-silverlight/</guid>
		<description><![CDATA[I fought with this for a while today, so I thought I would toss it up as a solution. I was trying to create a transition between two screens for a project I&#8217;m working on. I created the two ContentControls in my XAML like so: &#60;ContentControl x:Name=&#8221;OldContent&#8221;&#62;       &#60;!&#8211; My Old Content –&#62; &#60;/ContentControl&#62; &#60;ContentControl [...]]]></description>
			<content:encoded><![CDATA[<p>I fought with this for a while today, so I thought I would toss it up as a solution.</p>
<p>I was trying to create a transition between two screens for a project I&#8217;m working on. I created the two ContentControls in my XAML like so:</p>
<p><span style="color: #0000ff;">&lt;</span><span style="color: #a31515;">ContentControl </span><span style="color: #ff0000;">x</span><span style="color: #0000ff;">:</span><span style="color: #ff0000;">Name</span><span style="color: #0000ff;">=&#8221;OldContent&#8221;&gt;<br />
      </span><span style="color: #008000;">&lt;!&#8211; My Old Content –&gt;<br />
</span><span style="color: #0000ff;">&lt;/</span><span style="color: #a31515;">ContentControl</span><span style="color: #0000ff;">&gt;<br />
&lt;</span><span style="color: #a31515;">ContentControl </span><span style="color: #ff0000;">x</span><span style="color: #0000ff;">:</span><span style="color: #ff0000;">Name</span><span style="color: #0000ff;">=&#8221;NewContent&#8221; </span><span style="color: #ff0000;">Opacity</span><span style="color: #0000ff;">=&#8221;0&#8243;&gt;<br />
      </span><span style="color: #008000;">&lt;!&#8211; My New Content &#8211;&gt;<br />
</span><span style="color: #0000ff;">&lt;/</span><span style="color: #a31515;">ContentControl</span><span style="color: #0000ff;">&gt;</span></p>
<p>Let’s say for the sake of this post that I was trying to animate the top content as a fade in and then, after the animation is done,  put the top content into the bottom content so that I could fill the NewContent with something else and have it ready for the next transition.</p>
<p>So… I’m using the following animation.</p>
<p><span style="color: #0000ff;">&lt;</span><span style="color: #a31515;">Storyboard </span><span style="color: #ff0000;">x</span><span style="color: #0000ff;">:</span><span style="color: #ff0000;">Name</span><span style="color: #0000ff;">=&#8221;TransitionContent&#8221;&gt;<br />
   &lt;</span><span style="color: #a31515;">DoubleAnimationUsingKeyFrames </span><span style="color: #ff0000;">BeginTime</span><span style="color: #0000ff;">=&#8221;00:00:00&#8243;<br />
</span><span style="color: #ff0000;">         Storyboard.TargetName</span><span style="color: #0000ff;">=&#8221;NewContent&#8221;<br />
</span><span style="color: #ff0000;">         Storyboard.TargetProperty</span><span style="color: #0000ff;">=&#8221;Opacity&#8221;&gt;<br />
                &lt;</span><span style="color: #a31515;">SplineDoubleKeyFrame </span><span style="color: #ff0000;">KeyTime</span><span style="color: #0000ff;">=&#8221;00:00:00.03&#8243; </span><span style="color: #ff0000;">Value</span><span style="color: #0000ff;">=&#8221;1&#8243; /&gt;<br />
</span><span style="color: #0000ff;">   &lt;/</span><span style="color: #a31515;">DoubleAnimationUsingKeyFrames</span><span style="color: #0000ff;">&gt;<br />
&lt;/</span><span style="color: #a31515;">Storyboard</span><span style="color: #0000ff;">&gt;</span><a href="http://11011.net/software/vspaste"></a></p>
<p>(No Blend stuff today because I’m going a mile a minute for the sake of my looming project deadline.)</p>
<p>I add a “Completed” event handler to my Storyboard so that I can swap the content when the animation is over.</p>
<p><span style="color: #0000ff;">&lt;</span><span style="color: #a31515;">Storyboard </span><span style="color: #ff0000;">x</span><span style="color: #0000ff;">:</span><span style="color: #ff0000;">Name</span><span style="color: #0000ff;">=&#8221;TransitionContent&#8221; </span><span style="color: #ff0000;">Completed</span><span style="color: #0000ff;">=&#8221;TransitionContent_Completed&#8221;&gt;</span></p>
<p>In the C# code behind, I first wrote my content swapping like this:</p>
<p><span style="color: #0000ff;">this</span>.OldContent.Content = <span style="color: #0000ff;">this</span>.NewContent.Content;<br />
<span style="color: #0000ff;">this</span>.NewContent.Content = <span style="color: #0000ff;">null</span>;</p>
<p>And I got the following exception:</p>
<p><em>&#8220;System.ArgumentException was unhandled by user code<br />
      Value does not fall within the expected range.&#8221;</em></p>
<p>I’m putting this in because it took me quite some time to figure out what the problem was. Simply put… Silverlight was yelling at me because I was trying to put the same stuff in the visual tree twice. This would have meant two copies of anything with a x:Name attribute… which would have been made it really hard for me to find anything. So it threw an exception.</p>
<p>Ultimately, I had to create an object to store the value of the NewContent  and then trash the NewContent.Content before I could put it into the OldContent.Content. I’ve re-written the code in such a way that if you wanted to swap the two contents, it will do just that.</p>
<p><span style="color: #0000ff;">private void </span>Storyboard2_Completed(<span style="color: #0000ff;">object </span>sender, <span style="color: #2b91af;">EventArgs </span>e)       <br />
{<br />
            <span style="color: #0000ff;">object </span>oldStuff = <span style="color: #0000ff;">this</span>.OldContent.Content <span style="color: #0000ff;">as object</span>;<br />
            <span style="color: #0000ff;">object </span>newStuff = <span style="color: #0000ff;">this</span>.NewContent.Content <span style="color: #0000ff;">as object</span>;</p>
<p>            <span style="color: #0000ff;">this</span>.OldContent.Content = <span style="color: #0000ff;">null</span>;<br />
            <span style="color: #0000ff;">this</span>.NewContent.Content = <span style="color: #0000ff;">null</span>;</p>
<p>            <span style="color: #0000ff;">this</span>.OldContent.Content = newStuff;<br />
            <span style="color: #0000ff;">this</span>.NewContent.Content = oldStuff;</p>
<p>            <span style="color: #0000ff;">this</span>.NewContent.Opacity = 0;<br />
}</p>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>That last little bit is to reset the NewContent so that it is ready for the next transition.</p>
<p>And that’s all there is to it.</p>
<iframe src="http://www.facebook.com/plugins/like.php?href=http://www.designersilverlight.com/2008/10/23/swapping-content-in-the-code-behind-in-silverlight/&amp;layout=standard&amp;show_faces=1&amp;width=450&amp;action=like&amp;colorscheme=light&amp;font=" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:25px"></iframe><div class="tweetthis" style="text-align:left;"><p> <a target="_blank" rel="nofollow" class="tt" href="http://twitter.com/intent/tweet?text=Swapping+Content+In+the+Code+Behind+in+Silverlight+http%3A%2F%2Fdesignersilverlight.com%2F%3Fp%3D372" title="Post to Twitter"><img class="nothumb" src="http://www.designersilverlight.com/wp-content/plugins/tweet-this/icons/en/twitter/tt-twitter.png" alt="Post to Twitter" /></a> <a target="_blank" rel="nofollow" class="tt" href="http://twitter.com/intent/tweet?text=Swapping+Content+In+the+Code+Behind+in+Silverlight+http%3A%2F%2Fdesignersilverlight.com%2F%3Fp%3D372" title="Post to Twitter">Tweet This Post</a></p></div>]]></content:encoded>
			<wfw:commentRss>http://www.designersilverlight.com/2008/10/23/swapping-content-in-the-code-behind-in-silverlight/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Create a Zooming Button Style In Silverlight Without Code</title>
		<link>http://www.designersilverlight.com/2008/09/19/create-a-zooming-button-style-in-silverlight-without-code/</link>
		<comments>http://www.designersilverlight.com/2008/09/19/create-a-zooming-button-style-in-silverlight-without-code/#comments</comments>
		<pubDate>Fri, 19 Sep 2008 14:29:37 +0000</pubDate>
		<dc:creator>Matthias Shapiro</dc:creator>
				<category><![CDATA[Blend]]></category>
		<category><![CDATA[Helpful Links]]></category>
		<category><![CDATA[How To...]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[styles]]></category>
		<category><![CDATA[templates]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.designersilverlight.com/2008/09/19/create-a-zooming-button-style-in-silverlight-without-code/</guid>
		<description><![CDATA[Download code for this sample (updated for RCW) I was reading Mike Snow&#8217;s blog and he had a recent Silverlight tutorial on creating a Zooming toolbar. I looked at it and said to myself, &#8220;I think I can do that without code in Blend!&#8221; So here&#8217;s a tutorial on exactly that. End product : Big [...]]]></description>
			<content:encoded><![CDATA[<p><a href='http://www.designersilverlight.com/wp-content/uploads/2008/11/rcw_zooming_button.zip'>Download code for this sample (updated for RCW)</a></p>
<p>I was reading Mike Snow&#8217;s blog and he had a recent <a href="http://silverlight.net/blogs/msnow/archive/2008/09/10/silverlight-tip-of-the-day-39-how-to-create-a-zoom-toolbar.aspx">Silverlight tutorial on creating a Zooming toolbar</a>. I looked at it and said to myself, &#8220;I think I can do that without code in Blend!&#8221; So here&#8217;s a tutorial on exactly that.</p>
<p>End product :</p>
<p><iframe src="http://silverlight.services.live.com/invoke/77530/ZoomBtnRCW/iframe.html" scrolling="no" frameborder="0" style="width:450px; height:400px"></iframe></p>
<p>Big bonuses to this XAML-only method include:</p>
<ul>
<li>Much smoother animation</li>
<li>Midway animation (if you fly over a button, it doesn&#8217;t need to animate all the way up before it starts to animate back down)</li>
<li>Really low overhead</li>
<li>Can be done and maintained entirely by a designer in Blend without any code</li>
</ul>
<p>1) create a new Silverlight project in either Visual Studio 2008 or Blend 2.5.</p>
<p>2) In Blend, add a new folder for our images by right-clicking on the project and selecting &#8220;Add New Folder&#8221;</p>
<p><a href="http://www.designersilverlight.com/wp-content/uploads/2008/09/clip-image001.png"><img style="border-width: 0px" src="http://www.designersilverlight.com/wp-content/uploads/2008/09/clip-image001-thumb.png" border="0" alt="clip_image001" width="207" height="72" /></a></p>
<p>3) Pull in our images by right-clicking on our new folder and selecting &#8220;Add Existing Item&#8230;&#8221; Navigate to the images you want to use and select &#8220;OK&#8221; to bring them into the project.</p>
<p><a href="http://www.designersilverlight.com/wp-content/uploads/2008/09/clip-image0014.png"><img style="border-width: 0px" src="http://www.designersilverlight.com/wp-content/uploads/2008/09/clip-image0014-thumb.png" border="0" alt="clip_image001[4]" width="273" height="63" /></a></p>
<p>4) Create the button to which you want to add the image and then double-click it in the Obejcts and Timeline pane so that it has a yellow outline around it.</p>
<p><a href="http://www.designersilverlight.com/wp-content/uploads/2008/09/clip-image0016.png"><img style="border-width: 0px" src="http://www.designersilverlight.com/wp-content/uploads/2008/09/clip-image0016-thumb.png" border="0" alt="clip_image001[6]" width="314" height="180" /></a></p>
<p>5) Now, go to the image you want to insert (in the Project panel), right click on it and select &#8220;Insert&#8221;</p>
<p><a href="http://www.designersilverlight.com/wp-content/uploads/2008/09/clip-image0018.png"><img style="border-width: 0px" src="http://www.designersilverlight.com/wp-content/uploads/2008/09/clip-image0018-thumb.png" border="0" alt="clip_image001[8]" width="317" height="188" /></a></p>
<p>OK&#8230; so now we have a button with an image in it. Now it&#8217;s time to make the sucker zoom.</p>
<p>6) Right click on the button and select &#8220;Edit Control Parts (Template) -&gt; Edit a Copy&#8230;&#8221;</p>
<p><a href="http://www.designersilverlight.com/wp-content/uploads/2008/09/clip-image00110.png"><img style="border-width: 0px" src="http://www.designersilverlight.com/wp-content/uploads/2008/09/clip-image00110-thumb.png" border="0" alt="clip_image001[10]" width="338" height="86" /></a></p>
<p>Name your custom Template and hit OK</p>
<p><a href="http://www.designersilverlight.com/wp-content/uploads/2008/09/clip-image00112.png"><img style="border-width: 0px" src="http://www.designersilverlight.com/wp-content/uploads/2008/09/clip-image00112-thumb.png" border="0" alt="clip_image001[12]" width="382" height="88" /></a></p>
<p>7) In the &#8220;States&#8221; pane, you see a set of &#8220;CommonStates&#8221; (Normal, MouseOver, Pressed, and Disabled). Click on the MouseOver state and a red box will surround your composition, indicating that any changes made will be changes to the &#8220;Mouse Over&#8221; state, not to the default control.</p>
<p><a href="http://www.designersilverlight.com/wp-content/uploads/2008/09/clip-image00114.png"><img style="border-width: 0px" src="http://www.designersilverlight.com/wp-content/uploads/2008/09/clip-image00114-thumb.png" border="0" alt="clip_image001[14]" width="255" height="156" /></a></p>
<p>Recording state:</p>
<p><a href="http://www.designersilverlight.com/wp-content/uploads/2008/09/clip-image00116.png"><img style="border-width: 0px" src="http://www.designersilverlight.com/wp-content/uploads/2008/09/clip-image00116-thumb.png" border="0" alt="clip_image001[16]" width="160" height="40" /></a></p>
<p>8] Click on the highest level item in the template (in my case, it is a &#8220;Grid&#8221;) and go to the &#8220;Transform&#8221; section in the &#8220;Properties&#8221; pane and select the &#8220;Scale&#8221; transformation tab. Change the X and Y scales to &#8220;1.5&#8243;</p>
<p><a href="http://www.designersilverlight.com/wp-content/uploads/2008/09/clip-image00118.png"><img style="border-width: 0px" src="http://www.designersilverlight.com/wp-content/uploads/2008/09/clip-image00118-thumb.png" border="0" alt="clip_image001[18]" width="281" height="309" /></a></p>
<p>If you run the project now, you&#8217;ll notice that we get a cool zoom in effect on the mouse over, but our zoom out when the mouse leaves the button is basically a snap back to the original size. Let&#8217;s fix that now.</p>
<p>9) Click on the the arrow icon in the MouseOver state in the States pane and select the &#8220;MouseOver -&gt; Normal&#8221;</p>
<p><a href="http://www.designersilverlight.com/wp-content/uploads/2008/09/clip-image00120.png"><img style="border-width: 0px" src="http://www.designersilverlight.com/wp-content/uploads/2008/09/clip-image00120-thumb.png" border="0" alt="clip_image001[20]" width="380" height="109" /></a></p>
<p>In the &#8220;Transition Duration&#8221; box, type &#8220;.2&#8243;</p>
<p><a href="http://www.designersilverlight.com/wp-content/uploads/2008/09/clip-image00124.png"><img style="border-width: 0px" src="http://www.designersilverlight.com/wp-content/uploads/2008/09/clip-image00124-thumb.png" border="0" alt="clip_image001[24]" width="243" height="74" /></a></p>
<p>10) Extra Designer Happiness Bonus Step! &#8211; If you&#8217;d like to have a zoom effect that isn&#8217;t strictly linear, open up the timeline view with the button on the right hand of the state recording box (seen below).</p>
<p><a href="http://www.designersilverlight.com/wp-content/uploads/2008/09/clip-image00126.png"><img style="border-width: 0px" src="http://www.designersilverlight.com/wp-content/uploads/2008/09/clip-image00126-thumb.png" border="0" alt="clip_image001[26]" width="255" height="54" /></a></p>
<p>Click and drag the keyframe (the light gray oval below) to the point you want it. I put mine at .3 seconds.</p>
<p><a href="http://www.designersilverlight.com/wp-content/uploads/2008/09/clip-image00128.png"><img style="border-width: 0px" src="http://www.designersilverlight.com/wp-content/uploads/2008/09/clip-image00128-thumb.png" border="0" alt="clip_image001[28]" width="276" height="136" /></a></p>
<p>With the keyframe selected, you should see an &#8220;Easing&#8221; pane on the right. The default easing is linear (aka. no easing), but you can change the easing curve by just dragging the yellow dots. Here is the easing curve I&#8217;ve found works pretty well for my apps.</p>
<p><a href="http://www.designersilverlight.com/wp-content/uploads/2008/09/clip-image00130.png"><img style="border-width: 0px" src="http://www.designersilverlight.com/wp-content/uploads/2008/09/clip-image00130-thumb.png" border="0" alt="clip_image001[30]" width="282" height="326" /></a></p>
<p>That&#8217;s it. Now you can just assign this template to a button and you&#8217;ll have this zooming functionality all set up.<a href="http://www.designersilverlight.com/wp-content/uploads/2008/11/rcw_zooming_button.xap">rcw_zooming_button</a></p>
<iframe src="http://www.facebook.com/plugins/like.php?href=http://www.designersilverlight.com/2008/09/19/create-a-zooming-button-style-in-silverlight-without-code/&amp;layout=standard&amp;show_faces=1&amp;width=450&amp;action=like&amp;colorscheme=light&amp;font=" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:25px"></iframe><div class="tweetthis" style="text-align:left;"><p> <a target="_blank" rel="nofollow" class="tt" href="http://twitter.com/intent/tweet?text=Create+a+Zooming+Button+Style+In+Silverlight+Without+Code+http%3A%2F%2Fdesignersilverlight.com%2F%3Fp%3D331" title="Post to Twitter"><img class="nothumb" src="http://www.designersilverlight.com/wp-content/plugins/tweet-this/icons/en/twitter/tt-twitter.png" alt="Post to Twitter" /></a> <a target="_blank" rel="nofollow" class="tt" href="http://twitter.com/intent/tweet?text=Create+a+Zooming+Button+Style+In+Silverlight+Without+Code+http%3A%2F%2Fdesignersilverlight.com%2F%3Fp%3D331" title="Post to Twitter">Tweet This Post</a></p></div>]]></content:encoded>
			<wfw:commentRss>http://www.designersilverlight.com/2008/09/19/create-a-zooming-button-style-in-silverlight-without-code/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>

