<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>Adam Kinney posts tagged with 'tutorial'</title><description>Adam Kinney blog posts filtered by a specific tag</description><link>http://adamkinney.com/blog/tags/tutorial/default.aspx</link><language>en-us</language><pubDate>Sat, 11 Oct 2008 09:52:50 GMT</pubDate><generator>Oxite</generator><item><title>WPF Effects and Transitions Library Applied</title><description>&lt;div style="border-right: #ccc 1px solid; padding-right: 10px; border-top: #ccc 1px solid; padding-left: 10px; float: right; padding-bottom: 10px; margin: 10px 0px 10px 10px; border-left: #ccc 1px solid; padding-top: 10px; border-bottom: #ccc 1px solid; background-color: #f9f9f9"&gt;&lt;img src="http://adamkinney.com/images/blog/wpffxinterviewindemo.jpg" /&gt;     &lt;br /&gt;&lt;a href="http://bit.ly/24HwXa"&gt;WPF Effects Interview&lt;/a&gt; (8:46)     &lt;br /&gt;&lt;a href="http://bit.ly/1nGm1w"&gt;WPF Effects Interview - Essential&lt;/a&gt; (5:35)     &lt;br /&gt;    &lt;br /&gt;&lt;a href="http://bit.ly/4rMjvG"&gt;WPF Effects Demo&lt;/a&gt; (5:35)     &lt;br /&gt;&lt;a href="http://bit.ly/3VTq1i"&gt;WPF Effects Demo - Just Effects&lt;/a&gt; (3:36)     &lt;br /&gt;&lt;a href="http://bit.ly/14YaBa"&gt;WPF Effects Demo - Just Transitions&lt;/a&gt; (2:32) &lt;/div&gt;  &lt;p&gt;Last week we posted the &lt;a href="http://www.codeplex.com/wpffx"&gt;WPF Effects Library&lt;/a&gt; on Codeplex along with an &lt;a href="http://channel9.msdn.com/shows/Continuum/WPFFX/"&gt;David Teitlebaum interview&lt;/a&gt; and &lt;a href="http://channel9.msdn.com/shows/Continuum/WPFFXDemo/"&gt;a demo video&lt;/a&gt; showing the library in action.&lt;/p&gt;  &lt;p&gt;The library includes 23 Effects using the new PixelShader class ShaderEffect available in WPF 3.5 SP1.&amp;#160; Effects range from BandedSwirl, ZoomBlur, InvertColor and my favorite to say, GrowablePoissonDisk.&lt;/p&gt;  &lt;p&gt;I have a few &lt;a href="http://flickr.com/photos/adamkinney/tags/effects/"&gt;Effects screenshots on Flickr&lt;/a&gt;, if you'd like to see them.&amp;#160; Greg Schechter has a great &lt;a href="http://blogs.msdn.com/greg_schechter/archive/2008/05/12/gpu-accelerated-custom-effects-for-wpf.aspx"&gt;blog post talking about Effects in WPF&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;The library also includes 33 Transitions in addition to the Effects.&amp;#160;&amp;#160; Transitions range from familiar concepts like BandedSwirl, Pixelate and Slide to more exotic types like Crumble, MostBright and Water.&lt;/p&gt;  &lt;p&gt;All of the Transitions are based on the abstract TransitionEffect class, which builds on the framework ShaderEffect class adding the concept of two inputs and a progress animation.&amp;#160; This now allows you to use an Effect in a very applicable way.&amp;#160; The Effect is not only applied to an element but you can use the Effect as a way to animate between two elements.&amp;#160; And the animation itself is handled by a WPF Storyboard demonstrating the tight integration between the WPF Framework and Pixel Shaders.&amp;#160; The more you dig into this architecture the more you find out how much work has been done by the WPF team to make using Shaders simple.&lt;/p&gt;  &lt;h2&gt;Using the WPF Effects Library&lt;/h2&gt;  &lt;p&gt;In order to start using the WPF Effects Library for your WPF Applications, there are a few simple steps involved listed below:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Ensure you have VS2008 and .NET Framework 3.5 SP1 installed &lt;/li&gt;    &lt;li&gt;Install the &lt;a href="http://www.codeplex.com/wpf/Release/ProjectReleases.aspx?ReleaseId=14962"&gt;Shader Effects BuildTask and Templates&lt;/a&gt; available on Codeplex.&amp;#160; Grab the .ZIP file and follow the steps in the readme.txt &lt;/li&gt;    &lt;li&gt;Download the &lt;a href="http://www.codeplex.com/wpffx"&gt;WPF Effects Library&lt;/a&gt; and open the ShaderDemoApp. &lt;/li&gt;    &lt;li&gt;You will see &amp;quot;custombuild&amp;quot; warnings when opening the projects. This is due to the Shader Effects Build Task being hooked up.&amp;#160; No worries here, click Load Normally. &lt;/li&gt;    &lt;li&gt;Now try to run the ShaderDemoApp and if it looks like it did in the &lt;a href="http://channel9.msdn.com/shows/Continuum/WPFFXDemo/"&gt;demo video&lt;/a&gt;, you're all set. &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;Now that you're up and running you can start using the Effects.&amp;#160; One thing about the ShaderDemoApp that comes with the library is that its great to demo with, but as a starter application it can be a little complex.&lt;/p&gt;  &lt;p&gt;Let's walkthrough a very simple application called TransitioningImages that makes use of a TransitionEffect to navigate images in a folder.&lt;/p&gt; &lt;a title="TransitioningImages Screenshot by adKinn, on Flickr" href="http://www.flickr.com/photos/adamkinney/2927902142/"&gt;&lt;img height="313" alt="TransitioningImages Screenshot" src="http://farm4.static.flickr.com/3211/2927902142_e29f182696.jpg" width="500" /&gt;&lt;/a&gt;   &lt;p&gt;This is a very simple application where all of the action happens within the Window1 class.&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;strong&gt;Choose a Folder&lt;/strong&gt; - After the user selects a folder using the OpenFileDialog, the code retrieves all of the .jpg images from the folder and instantiates a new collection of BitmapSources for the custom PhotoSlideShow class.&amp;#160; The initial image is then loaded into an Image element.&lt;/li&gt;    &lt;li&gt;&lt;strong&gt;Navigating the Images&lt;/strong&gt; - Hitting the Next or Previous buttons then cycle through the PhotoSlideShow image collection and cue a Transition to move from one image to the next.&lt;/li&gt;    &lt;li&gt;&lt;strong&gt;Transition Applied&lt;/strong&gt; - A new Transition Effect is instantiated (the default is a RadialWiggle (pictured above)) along with a DoubleAnimation that animates the Progress of the Transition until completion.&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;One of the very cool things to point out here is that we are Transitioning between images which is an obvious choice.&amp;#160; But as the ShaderDemoApp shows the multiple inputs for the Transition are Brushes and in WPF we have an array of Brushes to choose from.&amp;#160; One of those Brushes is the VisualBrush which allows you to take any Visual element including Buttons, MediaElements and the like allowing you to create some really interesting applications using these Effects.&lt;/p&gt;  &lt;p&gt;Below is a link to the source code for the TransitioningImages application.&amp;#160; The executable will run with WPF 3.5 SP1 installed, but in order to modify and build the application you'll need to follow the installation steps above.&lt;/p&gt;  &lt;p&gt;If you use the Effects Library in your own application, let us know.&amp;#160; We'd love to hear about how well they worked for you and see what kind of applications you've come up with.&lt;/p&gt; &lt;iframe style="border-right: #dde5e9 1px solid; padding-right: 0px; border-top: #dde5e9 1px solid; padding-left: 0px; padding-bottom: 0px; margin: 3px; border-left: #dde5e9 1px solid; width: 240px; padding-top: 0px; border-bottom: #dde5e9 1px solid; height: 66px; background-color: #ffffff" marginwidth="0" marginheight="0" src="http://cid-1e3310e77ddfeb1b.skydrive.live.com/embedrowdetail.aspx/Public/TransitioningImages.zip" frameborder="0" scrolling="no"&gt;&lt;/iframe&gt;&lt;img src="http://adamkinney.com/blog/370/aggviewbug/default.aspx" alt="" /&gt;</description><comments>http://adamkinney.com/blog/370/default.aspx</comments><link>http://adamkinney.com/blog/370/default.aspx</link><pubDate>Thu, 09 Oct 2008 22:35:00 GMT</pubDate><guid isPermaLink="true">http://adamkinney.com/blog/370/default.aspx</guid><dc:creator>Adam Kinney</dc:creator><slash:comments>0</slash:comments><trackback:ping>http://adamkinney.com/blog/370/trackback/default.aspx</trackback:ping><category>animation</category><category>The Continuum Show</category><category>tutorial</category><category>visualization</category><category>WPF</category></item><item><title>Catching up with Silverlight 2</title><description>&lt;p style="float: right; margin-bottom: 10px; margin-left: 10px"&gt;&lt;a href="http://www.flickr.com/photos/funkysurfer/2321025077/in/photostream/"&gt;&lt;img alt="" src="http://farm3.static.flickr.com/2037/2321025077_cf22538d44_m.jpg" /&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Starting last week on March 5th after &lt;a href="http://visitmix.com/blogs/Joshua/Day-1-Keynote/"&gt;Silverlight 2 Beta 1 was announced,&lt;/a&gt; a lot has been said about Silverlight 2.&amp;nbsp; Presentations have been given, demos have been shown, bits have been released, tutorials have been posted and many conversations have been had.&amp;nbsp; As an attempt to catalog some of the more interesting and useful content, I'm posting my list of highlights since SL2B1 day.&lt;/p&gt; &lt;h2&gt;Overview&lt;/h2&gt; &lt;p&gt;In the unlikely event you haven't found where yet, you can grab the &lt;a href="http://silverlight.net/GetStarted/#betajump"&gt;runtime and tools for Silverlight 2 Beta 1&lt;/a&gt; on Silverlight.net.&amp;nbsp; &lt;/p&gt; &lt;p&gt;Other links to help you get started include:&lt;/p&gt; &lt;ul&gt; &lt;li&gt;&lt;a href="http://visitmix.com/blogs/2008Sessions/CT01/"&gt;Building Rich Internet Applications using Silverlight 2&lt;/a&gt; - MIX session presented by &lt;a href="http://blogs.msdn.com/jstegman/"&gt;Joe Stegmen&lt;/a&gt; and &lt;a href="http://blogs.msdn.com/mharsh/"&gt;Mike Harsh&lt;/a&gt;, &lt;a href="http://visitmix.com/blogs/2008Sessions/CT01/"&gt;Part 1&lt;/a&gt;, &lt;a href="http://visitmix.com/blogs/2008Sessions/CT02/"&gt;Part 2&lt;/a&gt;  &lt;li&gt;&lt;a href="http://silverlight.net/learn/tutorials/roadmap.aspx"&gt;A Whirlwind Tour&lt;/a&gt; - Jesse Liberty's introduction to Silverlight 2  &lt;li&gt;&lt;a href="http://download.microsoft.com/download/9/4/e/94e080c7-d462-4118-b07a-55578d64bc43/Silverlight%202%20Beta%201%20-%20Fundamentals.zip"&gt;Fundamentals Lab&lt;/a&gt; - This lab explores the fundamental tools and features that underpin any Silverlight application.  &lt;li&gt;&lt;a href="http://msdn2.microsoft.com/en-us/library/cc189007(VS.95).aspx"&gt;Breaking Changes in Silverlight 2&lt;/a&gt; - This topic discusses the changes made to the Silverlight runtime and Silverlight tools between the Microsoft Silverlight 1.1 Alpha September Refresh and the MIX 2008 release.  &lt;li&gt;&lt;a href="http://community.irritatedvowel.com/blogs/pete_browns_blog/archive/2008/03/05/Xap_2100_-App_2100_-Pow_2100_-Packaging-and-Application-Startup-in-Silverlight-2-Beta-1-_2D00_-Part-1.aspx"&gt;Packaging and Application Startup&lt;/a&gt; - Pete Brown explores the new application model, read &lt;a href="http://community.irritatedvowel.com/blogs/pete_browns_blog/archive/2008/03/05/Xap_2100_-App_2100_-Pow_2100_-Packaging-and-Application-Startup-in-Silverlight-2-Beta-1-_2D00_-Part-1.aspx"&gt;Part 1&lt;/a&gt; and &lt;a href="http://community.irritatedvowel.com/blogs/pete_browns_blog/archive/2008/03/05/Xap_2100_-App_2100_-Pow_2100_-Packaging-and-Application-Startup-in-Silverlight-2-Beta-1-_2D00_-Part-2.aspx"&gt;Part 2&lt;/a&gt;  &lt;li&gt;&lt;a href="http://download.microsoft.com/download/9/4/e/94e080c7-d462-4118-b07a-55578d64bc43/Silverlight%202%20Beta%201%20-%20Dynamic%20Animations.zip"&gt;Dynamic Animation Lab&lt;/a&gt; - This is a simple lawn mowing simulation that exposes different techniques of leveraging the managed Animation API in Silverlight 2.&lt;/li&gt;&lt;/ul&gt; &lt;h2&gt;Demos&lt;/h2&gt; &lt;ul&gt; &lt;li&gt;&lt;a href="http://memorabilia.hardrock.com/"&gt;Hard Rock Memorabilia&lt;/a&gt; - One of the most talked about demos at MIX08, welcome Deep Zoom!  &lt;li&gt;&lt;a href="http://pulse.sxsw.com/"&gt;Pulse at SXSW&lt;/a&gt; - mashes up twitter, del.icio.us, Technorati and flickr in a very visual and useful way  &lt;li&gt;&lt;a href="http://ria.mail.aol.com"&gt;AOL email client&lt;/a&gt; - a full email client written in Silverlight 2  &lt;li&gt;NBC Olympics - can be seen in the first &lt;a href="http://visitmix.com/blogs/2008Sessions/KYN0801/"&gt;keynote&lt;/a&gt; at MIX08 around 1:17:00, an &lt;a href="http://www.visitmix.com/blogs/News/NBC/"&gt;interview&lt;/a&gt; with Perkins Miller is also available  &lt;li&gt;&lt;a href="http://www.textglow.net/"&gt;TextGlow&lt;/a&gt; - read Word 2007 documents online with Silverlight 2  &lt;li&gt;&lt;a href="http://silverlight.net/community/gallerydetail.aspx?cat=5"&gt;Silverlight.net Community Gallery&lt;/a&gt; - controls demo, RSS reader, SOAP Weather Widget and more  &lt;li&gt;&lt;a href="http://www.miniclip.com/games/tunnel-trouble/en/"&gt;Tunnel Trouble&lt;/a&gt; - a new Silverlight-based game from &lt;a href="http://www.terralever.com/"&gt;Terralever&lt;/a&gt; &lt;li&gt;&lt;a href="http://sl.weatherbug.com/?zip=98052"&gt;WeatherBug&lt;/a&gt; - designed for Silverlight Mobile, you can test the app running on the web.&lt;/li&gt;&lt;/ul&gt; &lt;h2&gt;Controls&lt;/h2&gt; &lt;ul&gt; &lt;li&gt;&lt;a href="http://silverlight.net/Samples/2b1/SilverlightControls/run/default.html"&gt;Control Demo Page&lt;/a&gt; - see the controls in action  &lt;li&gt;&lt;a href="http://www.microsoft.com/downloads/details.aspx?familyid=EA93DD89-3AF2-4ACB-9CF4-BFE01B3F02D4&amp;amp;displaylang=en"&gt;Source code and Unit Tests for controls&lt;/a&gt; - download the code  &lt;li&gt;&lt;a href="http://visitmix.com/blogs/2008Sessions/T20/"&gt;Creating Rich Dynamic User interfaces with Silverlight 2&lt;/a&gt; - MIX session presented by &lt;a href="http://scorbs.com/"&gt;Karen Corby&lt;/a&gt;  &lt;li&gt;&lt;a href="http://silverlight.net/learn/tutorials/controls.aspx"&gt;Controls Tutorial&lt;/a&gt; - Another Jesse Liberty tutorial  &lt;li&gt;&lt;a href="http://blogs.msdn.com/delay/archive/2008/03/05/lb-sv-faq-examples-notes-tips-and-more-for-silverlight-2-beta-1-s-listbox-and-scrollviewer-controls.aspx"&gt;ListBox and ScrollViewer FAQs&lt;/a&gt; - all you ever wanted to know about them and more  &lt;li&gt;&lt;a href="http://wilcoding.xs4all.nl/Wilco/View.aspx?NewsID=212 "&gt;File Upload Component&lt;/a&gt; - Wilco Bauwer builds a File upload and control and shares the source  &lt;li&gt;&lt;a href="http://download.microsoft.com/download/9/4/e/94e080c7-d462-4118-b07a-55578d64bc43/Silverlight%202%20Beta%201%20-%20User%20Controls.zip"&gt;User Controls Lab&lt;/a&gt; - Building Reusable Controls in Silverlight 2  &lt;li&gt;&lt;a href="http://silverlight.net/learn/learnvideo.aspx?video=33677"&gt;Using the Silverlight 2 Canvas&lt;/a&gt; - a screencast by Jesse Liberty  &lt;li&gt;&lt;a href="http://silverlight.net/learn/learnvideo.aspx?video=33733"&gt;Using Silverlight 2 Grids and Stack Panels&lt;/a&gt; - another great screencast by Jesse Liberty  &lt;li&gt;&lt;a href="http://silverlight.net/learn/tutorials/stylestemplates.aspx"&gt;Styling Controls&lt;/a&gt; - another tutorial by Jesse Liberty (he's been very busy)&lt;/li&gt;&lt;/ul&gt; &lt;h2&gt;Deep Zoom&lt;/h2&gt; &lt;ul&gt; &lt;li&gt;&lt;a href="http://visitmix.com/blogs/2008Sessions/CT06/"&gt;Applications = Designers + Developers&lt;/a&gt; - MIX session presented by &lt;a href="http://nibblestutorials.net/"&gt;Celso Gomes&lt;/a&gt; and &lt;a href="http://www.kirupa.com/"&gt;Kirupa Chinnathambi&lt;/a&gt; , Deep Zoom heatured in the second part &lt;li&gt;&lt;a href="http://visitmix.com/blogs/2008Sessions/T23/"&gt;Hard Rock: Behind the Music with Deep Zoom&lt;/a&gt; - MIX Session presented by &lt;a href="http://www.microsoftregionaldirectors.com/profile.aspx?rd=1089"&gt;Scott Stanfield&lt;/a&gt;  &lt;li&gt;&lt;a title="Silverlight 2 - First Attempt with MultiScaleImage" href="http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/2008/03/05/10217.aspx"&gt;First Attempt with MultiScaleImage&lt;/a&gt; - Mike Taulty shows how to implement control over Deep Zoom, followed by &lt;a href="http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/2008/03/08/10231.aspx"&gt;an update&lt;/a&gt;  &lt;li&gt;&lt;a href="http://blogs.msdn.com/mikeormond/archive/2008/03/07/silverlight-2-deep-zoom-demo.aspx"&gt;Deep Zoom Demo&lt;/a&gt; - Mike Ormond shares Deep Zoom code and then &lt;a href="http://blogs.msdn.com/mikeormond/archive/2008/03/07/deep-zoom-demo-now-with-mouse-wheel-support.aspx"&gt;adds mouse wheel support&lt;/a&gt; in part 2  &lt;li&gt;&lt;a href="http://blogs.msdn.com/expression/archive/2008/03/05/download-the-preview-of-the-deep-zoom-composer.aspx"&gt;Deep Zoom Composer Preview&lt;/a&gt;  &lt;li&gt;&lt;a href="http://blogs.msdn.com/expression/archive/2008/03/05/deep-zoom-composer-user-guide.aspx"&gt;Deep Zoom Composer Preview - User Guide&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt; &lt;h2&gt;Mobile&lt;/h2&gt; &lt;ul&gt; &lt;li&gt;&lt;a href="http://visitmix.com/blogs/2008Sessions/T12/"&gt;Mobile Devices and Microsoft Silverlight&lt;/a&gt; - MIX session presented by &lt;a href="http://blogs.msdn.com/amit_chopra/"&gt;Amit Chopra&lt;/a&gt; and &lt;a href="http://blogs.msdn.com/davidklinems/"&gt;David Kline&lt;/a&gt;  &lt;li&gt;&lt;a href="http://visitmix.com/blogs/2008Sessions/C02/"&gt;Using Microsoft Silverlight for Creating Rich Mobile User Experiences&lt;/a&gt; - MIX session presented by &lt;a href="http://www.giorgiosardo.com/"&gt;Giorgio Sardo&lt;/a&gt;  &lt;li&gt;&lt;a href="http://www.allaboutsymbian.com/media/item/AAS_Videocast_28_AAS_talks_to_Microsoft_and_developers_about_Silverlight_Mobile.php"&gt;Brad Becker interview&lt;/a&gt; - about the recent announcement about Silverlight Mobile.  &lt;li&gt;&lt;a href="http://www.visitmix.com/blogs/Joshua/WeatherBug/"&gt;WeatherBug demo&lt;/a&gt;  &lt;li&gt;&lt;a href="http://visitmix.com/blogs/OpenSpace/MIXr-Silverlight-Mobile-Application-Demo/"&gt;MIXr demo&lt;/a&gt;  &lt;li&gt;&lt;a title="Silverlight for Mobile primer session at MIX08" href="http://adamkinney.com/blog/315/default.aspx"&gt;Silverlight for Mobile primer session at MIX08&lt;/a&gt; - my notes from the first mobile session at MIX&lt;/li&gt;&lt;/ul&gt; &lt;h2&gt;Dynamic Language Runtime&lt;/h2&gt; &lt;ul&gt; &lt;li&gt;&lt;a href="http://visitmix.com/blogs/2008Sessions/T28/"&gt;Microsoft Silverlight and Dynamic Languages&lt;/a&gt; - MIX session presented by &lt;a href="http://www.iunknown.com/"&gt;John Lam&lt;/a&gt; and &lt;a href="http://jimmy.schementi.com/blog/"&gt;Jimmy Schementi&lt;/a&gt;  &lt;li&gt;&lt;a href="http://www.iunknown.com/2008/03/dynamic-silverl.html"&gt;Hello World! demo&lt;/a&gt; - demo from MIX session  &lt;li&gt;&lt;a href="http://www.iunknown.com/2008/03/dynamic-silve-1.html"&gt;Managed JScript and flickr&lt;/a&gt; -demo from MIX session  &lt;li&gt;&lt;a href="http://www.iunknown.com/2008/03/dynamic-silve-2.html"&gt;Integrating Silverlight and ASP.NET MVC&lt;/a&gt; - demo from MIX session  &lt;li&gt;&lt;a href="http://msdn2.microsoft.com/pl-pl/magazine/cc300810(en-us).aspx"&gt;Iron Python&lt;/a&gt; - Jimmy Schementi's MSDN article  &lt;li&gt;&lt;a href="http://msdn2.microsoft.com/en-us/magazine/cc163344.aspx"&gt;Iron Python and the DLR&lt;/a&gt; - Bill Chiles's MSDN Article  &lt;li&gt;&lt;a href="http://visitmix.com/blogs/OpenSpace/John-Lam-on-Ruby-Ruby-Ruby/"&gt;John Lam on Ruby, Ruby, Ruby&lt;/a&gt; - Open Space session at MIX08&lt;/li&gt;&lt;/ul&gt; &lt;h2&gt;Moonlight&lt;/h2&gt; &lt;ul&gt; &lt;li&gt;&lt;a href="http://visitmix.com/blogs/2008Sessions/T31/"&gt;Exploring Moonlight : Novell's Implementation of Silverlight on Linux&lt;/a&gt; - MIX session presented by &lt;a href="http://tirania.org/blog/"&gt;Miguel de Icaza&lt;/a&gt;  &lt;li&gt;&lt;a title="http://tirania.org/blog/archive/2008/Mar-03.html" href="http://tirania.org/blog/archive/2008/Mar-03.html"&gt;Pre-Mix 08: Moonlight Updates&lt;/a&gt;  &lt;li&gt;&lt;a href="http://tirania.org/blog/archive/2008/Mar-08.html"&gt;Channel9 works with Moonlight!&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt; &lt;h2&gt;Physics&lt;/h2&gt; &lt;ul&gt; &lt;li&gt;&lt;a href="http://www.farseergames.com/blog/post/New-Farseer-Physics-Engine-Release-for-Silverlight-20-Beta-1.aspx"&gt;Farseer Physics Engine&lt;/a&gt; - an open source physics engine for Silverlight 2  &lt;li&gt;&lt;a href="http://www.andybeaulieu.com/silverlight/2.0/polygondemo/testpage.html"&gt;Polygon Demo&lt;/a&gt; - Andy Beaulieu's recent demo using Farseer  &lt;li&gt;&lt;a href="http://chriscavanagh.wordpress.com/2008/03/06/silverlight-2-2d-physics-revisited/"&gt;Heads Will Roll demo&lt;/a&gt; - Chris Cavanagh updates his sample, click "move platforms" to make the wheels/heads go flying&lt;/li&gt;&lt;/ul&gt; &lt;h2&gt;Networking and Data&lt;/h2&gt; &lt;ul&gt; &lt;li&gt;&lt;a href="http://download.microsoft.com/download/9/4/e/94e080c7-d462-4118-b07a-55578d64bc43/Silverlight%202%20Beta%201%20-%20Networking%20and%20Data.zip"&gt;Networking and Data Lab&lt;/a&gt; - In this hands-on lab, you will look at using a variety of remote data sources and communication techniques to retrieve data for a Silverlight application.  &lt;li&gt;&lt;a href="http://visitmix.com/blogs/2008Sessions/T13/"&gt;Working with Data and Web Services in Microsoft Silverlight 2&lt;/a&gt; - MIX Session presented by &lt;a href="http://blogs.msdn.com/eugeneos/default.aspx"&gt;Eugene Osovetsky&lt;/a&gt;  &lt;li&gt;&lt;a href="http://weblogs.asp.net/mschwarz/archive/2008/03/07/silverlight-2-and-sockets.aspx"&gt;Sockets Sample&lt;/a&gt;  &lt;li&gt;&lt;a href="http://silverlight.net/learn/tutorials/databinding.aspx"&gt;Data Binding Tutorial&lt;/a&gt; - A Jesse Liberty tutorial&lt;/li&gt;&lt;/ul&gt; &lt;h2&gt;Browser Integration&lt;/h2&gt; &lt;ul&gt; &lt;li&gt;&lt;a href="http://download.microsoft.com/download/9/4/e/94e080c7-d462-4118-b07a-55578d64bc43/Silverlight%202%20Beta%201%20-%20Browser%20Integration.zip"&gt;Browser Integration Lab&lt;/a&gt; - In this hands-on lab, you will look at the places where DHTML and Silverlight meet.  &lt;li&gt;&lt;a href="http://timheuer.com/blog/archive/2008/03/09/calling-javascript-functions-from-silverlight-2.aspx"&gt;Calling JavaScript functions&lt;/a&gt; - Tim Heuer tutorial&lt;/li&gt;&lt;/ul&gt; &lt;h2&gt;Tools&lt;/h2&gt; &lt;ul&gt; &lt;li&gt;&lt;a href="http://www.ssblueprints.net/sharepoint/"&gt;Silverlight Blueprint for Sharepoint&lt;/a&gt; -&amp;nbsp; This is the answer to "how do you use Silverlight in Sharepoint?", Micheal Lehman has an &lt;a href="http://channel9.msdn.com/Showpost.aspx?postid=388339"&gt;interview&lt;/a&gt; live on Ch9  &lt;li&gt;&lt;a href="http://photozoom.mslivelabs.com"&gt;PhotoZoom&lt;/a&gt; - Want a Deep Zoom Album of your own? try this site.&amp;nbsp; Look for the "processing" notification when attempting to view your albums, the site is rather busy right now  &lt;li&gt;&lt;a href="http://www.flawlesscode.com/post/2008/03/Blogengine-NET-extension-for-embedding-a-Silverlight-plugin.aspx"&gt;BlogEngine.NET Silverlight Extension&lt;/a&gt; - I would expect to see more of these start cropping up  &lt;li&gt;&lt;a href="http://silverlight.net/blogs/jesseliberty/archive/2008/03/09/tip-of-the-day-great-silverlight-programmer-utilities.aspx"&gt;Programmer Utilities&lt;/a&gt; - Jesse Liberty's suggested "other" tools  &lt;li&gt;&lt;a href="http://www.telerik.com/products/silverlight/overview.aspx"&gt;Telerik Controls&lt;/a&gt; - There are lot of cool examples under the Online demos section.&amp;nbsp; Very cool to see the Animations framework in there.  &lt;li&gt;&lt;a href="http://www.accusoft.com/news/pressreleases/030408.asp"&gt;ImageGear for Silverlight&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt; &lt;h2&gt;Fountains of Information&lt;/h2&gt; &lt;ul&gt; &lt;li&gt;&lt;a href="http://weblogs.asp.net/scottgu/"&gt;Scott Guthrie&lt;/a&gt; - great tutorials and source of breaking news  &lt;li&gt;&lt;a href="http://blogs.msdn.com/tims/"&gt;Tim Sneath&lt;/a&gt; - next best place for breaking news and clarity of information  &lt;li&gt;&lt;a href="http://silverlight.net/blogs/jesseliberty/"&gt;Jesse Liberty&lt;/a&gt; - The Silverlight Developers best friend  &lt;li&gt;&lt;a href="http://www.iunknown.com/"&gt;John Lam&lt;/a&gt; - Dynamic Language Runtime  &lt;li&gt;&lt;a title="http://www.cynergysystems.com/blogs/page/josefajardo" href="http://www.cynergysystems.com/blogs/page/josefajardo"&gt;Jose Fajardo&lt;/a&gt; - User Experience and Design  &lt;li&gt;&lt;a href="http://www.andybeaulieu.com/"&gt;Andy Beaulieu&lt;/a&gt; - games and physics  &lt;li&gt;&lt;a href="http://www.sparklingclient.com/"&gt;Sparkling Client&lt;/a&gt; - a podcast about Silverlight and other RIA technologies.  &lt;li&gt;&lt;a href="http://www.thecodetrip.com/"&gt;Code Trip&lt;/a&gt; - driving around the west coast, check to see if they're coming to your neighborhood&lt;/li&gt;&lt;/ul&gt;&lt;img src="http://adamkinney.com/blog/316/aggviewbug/default.aspx" alt="" /&gt;</description><comments>http://adamkinney.com/blog/316/default.aspx</comments><link>http://adamkinney.com/blog/316/default.aspx</link><pubDate>Mon, 10 Mar 2008 23:24:00 GMT</pubDate><guid isPermaLink="true">http://adamkinney.com/blog/316/default.aspx</guid><dc:creator>Adam Kinney</dc:creator><slash:comments>2</slash:comments><trackback:ping>http://adamkinney.com/blog/316/trackback/default.aspx</trackback:ping><category>animation</category><category>conferences</category><category>demo</category><category>MIX</category><category>MIX08</category><category>Moonlight</category><category>Silverlight</category><category>Telerik</category><category>tutorial</category><category>web development</category></item><item><title>Silverlight 1.0 Bar Chart Tutorial</title><description>&lt;div style="float: right; margin-bottom: 10px; margin-left: 10px"&gt;&lt;img src="http://adamkinney.com/images/blog/sl_chart_200.jpg" alt="" /&gt; &lt;/div&gt; &lt;p&gt;I've seen this request many times:&lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;How do I make a Chart in Silverlight?&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;I'm going to show you that with some simple math and a little bit Silverlight knowledge, you too, can enjoy the clarity of a chart on your web page.&amp;nbsp; &lt;/p&gt; &lt;p&gt;Technically, the goal is to build a simple reusable horizontal bar chart using Silverlight 1.0 and dynamic data.&amp;nbsp; The code will be written in XAML and JavaScript and I will be using Visual Studio 2008 as my editor.&amp;nbsp; How you get the data to the app is up to you, but to keep this simple, I will be using local JSON formatted data.&lt;/p&gt; &lt;p&gt;&lt;strong&gt;Creating the Application&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;The first step is the application creation.&amp;nbsp; I will base my project on the Silverlight Script Web template that comes with the &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=25144C27-6514-4AD4-8BCB-E2E051416E03&amp;amp;displaylang=en"&gt;Silverlight Tools Alpha for Visual Studio 2008&lt;/a&gt;.&amp;nbsp; The majority of the project will remain relatively unchanged and most of the work will be done in the Chart Control files to be added.&lt;/p&gt; &lt;ul&gt; &lt;li&gt;File -&amp;gt; New -&amp;gt; Web Site...  &lt;li&gt;Choose the Silverlight Script Web template  &lt;li&gt;Give the project a name, Let's use &lt;em&gt;SilverlightBarChart&lt;/em&gt;  &lt;li&gt;Hit OK&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;Now we need to clear the template XAML and JavaScript:&lt;/p&gt; &lt;ul&gt; &lt;li&gt;Open Scene.xaml  &lt;li&gt;Clear the contents of the root Canvas, only the opening and closing Canvas elements should remain.  &lt;li&gt;Set the x:Name property of the root Canvas to &lt;em&gt;mainCanvas&lt;/em&gt;  &lt;li&gt;Open Scene.js  &lt;li&gt;Remove all event handler methods, except&lt;strong&gt; &lt;/strong&gt;&lt;em&gt;handleLoad&lt;/em&gt;  &lt;li&gt;Make sure you remove the comma after the &lt;em&gt;handleLoad&lt;/em&gt; method  &lt;li&gt;Clear the contents of the &lt;em&gt;handleLoad&lt;/em&gt; method&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;We've created a clean slate.&amp;nbsp; If you hit Run, you will see a stark white page.&amp;nbsp; A chart is more than a white page, though, so let's start adding the components.&lt;/p&gt; &lt;p&gt;&lt;strong&gt;Adding the Background and Container&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;The first piece we need is the background.&amp;nbsp; Not only does it serve the purpose of a contrasting color, but also it acts as the container for the bars.&lt;/p&gt; &lt;ul&gt; &lt;li&gt;File -&amp;gt; New -&amp;gt; File...  &lt;li&gt;Choose the Silverlight JScript Page template  &lt;li&gt;Name the file Chart.xaml  &lt;li&gt;In the root Canvas of the Chart.xaml file add the following XAML:&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;&lt;code&gt;&amp;lt;Rectangle Width="640" Height="480" Fill="#0f0f0f" Stroke="#2b2b2b" StrokeThickness="1" /&amp;gt;&lt;br&gt;&amp;lt;Canvas x:Name="barContainer"&amp;gt;&lt;br&gt;&amp;lt;/Canvas&amp;gt;&lt;/code&gt;&lt;/p&gt; &lt;p&gt;The Rectangle is used to style the background and the Canvas is a named container for us to reference in the code to dynamically add bars.&lt;/p&gt; &lt;ul&gt; &lt;li&gt;Return to Scene.js  &lt;li&gt;Add the following code in the &lt;em&gt;handleLoad&lt;/em&gt; method:&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;&lt;code&gt;this.plugIn = plugIn;&lt;br&gt;this.mainCanvas = plugIn.content.findName("mainCanvas");&lt;br&gt;this.downloader = this.plugIn.createObject("downloader");&lt;br&gt;this.downloader.addEventListener("completed", Silverlight.createDelegate(this, this.onCompleted));&lt;br&gt;this.downloader.open("GET", "Chart.xaml");&lt;br&gt;this.downloader.send();&lt;/code&gt;&lt;/p&gt; &lt;p&gt;The first two lines are setting variables for later use.&amp;nbsp; &lt;em&gt;this.plugIn&lt;/em&gt; refers to the Silverlight application instance.&amp;nbsp; &lt;em&gt;this.mainCanvas&lt;/em&gt; is a reference to the named Canvas in the Scene.xaml.&lt;/p&gt; &lt;p&gt;The next four lines create a &lt;a href="http://msdn2.microsoft.com/en-us/library/bb979676.aspx"&gt;Downloader&lt;/a&gt; object which is set to asynchronously fetch the Chart.xaml file.&amp;nbsp; Upon completion of downloading the file it will call the &lt;em&gt;onCompleted&lt;/em&gt; method.&amp;nbsp; Now let's add that method so it can be successfully called.&lt;/p&gt; &lt;ul&gt; &lt;li&gt;In the Scene.js file after the &lt;em&gt;handleLoad&lt;/em&gt; method's closing bracket, add a comma  &lt;li&gt;After the comma add the &lt;em&gt;onCompleted&lt;/em&gt; method as seen below:&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;&lt;code&gt;onCompleted: function(sender, args)&lt;br&gt;{&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; var chartTarget = this.plugIn.content.createFromXamlDownloader(sender, "");&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; this.mainCanvas.children.add(chartTarget);&lt;br&gt;}&lt;/code&gt;&lt;/p&gt; &lt;p&gt;This function is called after the downloader object has completed downloading the Chart.xaml file.&amp;nbsp; &lt;em&gt;sender&lt;/em&gt; is a reference to the downloader object which now holds the content of the xaml file.&amp;nbsp; Using the &lt;a href="http://msdn2.microsoft.com/en-us/bb412362.aspx"&gt;createFromXamlDownloader&lt;/a&gt; method, we create a new Silverlight object based on the downloader instance.&amp;nbsp; The new object is then added to the children collection of &lt;em&gt;mainCanvas&lt;/em&gt; in order for the object to render and become interactive.&lt;/p&gt; &lt;p&gt;Now hit Run and you will see an asynchronously loaded gray rectangle.&amp;nbsp; We are really cooking now.&lt;/p&gt; &lt;p&gt;&lt;strong&gt;Adding the Bars&lt;/strong&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;It takes two steps to add the bars to the chart.&amp;nbsp; First we need to create the reusable bars as separate components and then we need to add code to the Chart to create the bars dynamically based on the data.&lt;/p&gt; &lt;p&gt;Let's start by creating the bar component.&lt;/p&gt; &lt;ul&gt; &lt;li&gt;File -&amp;gt; New -&amp;gt; File...  &lt;li&gt;Choose the Silverlight JScript Page template  &lt;li&gt;Name the file Bar.xaml  &lt;li&gt;In the root Canvas of the Bar.xaml file add the following XAML:&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;&lt;code&gt;&amp;lt;Canvas.Background&amp;gt;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1"&amp;gt;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;LinearGradientBrush.GradientStops&amp;gt;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;GradientStop Offset="0" Color="#00b5fb"/&amp;gt;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;GradientStop Offset="1" Color="#004fac"/&amp;gt;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/LinearGradientBrush.GradientStops&amp;gt;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/LinearGradientBrush&amp;gt;&lt;br&gt;&amp;lt;/Canvas.Background&amp;gt;&lt;/code&gt;&lt;/p&gt; &lt;p&gt;Our bar is simply a Canvas painted with a LinearGradientBrush ranging from light blue to dark blue.&lt;/p&gt; &lt;p&gt;Now we'll modify the &lt;em&gt;Chart&lt;/em&gt; class so it uses the bar control to display the data.&amp;nbsp; The majority of the code here is the math used to size and position the bars properly.&lt;/p&gt; &lt;ul&gt; &lt;li&gt;Open Chart.js  &lt;li&gt;Add the following parameters to the &lt;em&gt;SilverlightBarChart.Chart&lt;/em&gt; function: &lt;em&gt;plugIn&lt;/em&gt;, &lt;em&gt;target&lt;/em&gt;, &lt;em&gt;data&lt;/em&gt;  &lt;li&gt;Within the brackets of the &lt;em&gt;SilverlightBarChart.Chart&lt;/em&gt; function add the following code:&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;&lt;code&gt;this.plugIn = plugIn;&lt;br&gt;this.target = target;&lt;br&gt;this.data = data;&lt;br&gt;this.barContainer = this.target.findName("barContainer");&lt;br&gt;this.bars = [];&lt;br&gt;this.padding = 5;&lt;br&gt;this.height = 480;&lt;br&gt;this.width = 640;&lt;/code&gt;&lt;/p&gt; &lt;p&gt;The first three lines store the parameters for later use.&amp;nbsp; &lt;em&gt;this.plugIn&lt;/em&gt; refers to the Silverlight application instance. &lt;em&gt;this.target&lt;/em&gt; represents the Silverlight object that our JavaScript class is wrapping and &lt;em&gt;this.data&lt;/em&gt; represents the JSON formatted data.&lt;/p&gt; &lt;p&gt;The next five lines set properties for rendering the dynamic bars.&amp;nbsp; &lt;em&gt;this.barContainer&lt;/em&gt; stores a reference to the container Canvas defined in the Chart.xaml file.&amp;nbsp; &lt;em&gt;this.bars&lt;/em&gt; is an Array we will use to store references to the Bar JavaScript instances.&amp;nbsp; &lt;em&gt;this.padding&lt;/em&gt;, &lt;em&gt;this.height&lt;/em&gt; and &lt;em&gt;this.width&lt;/em&gt; are all properties used to calculate the size and position of each bar.&lt;/p&gt; &lt;ul&gt; &lt;li&gt;Move down to the &lt;em&gt;SilverlightBarChart.Chart.prototype&lt;/em&gt; and remove the &lt;em&gt;handleLoad&lt;/em&gt; method  &lt;li&gt;Add the following code within the brackets of the &lt;em&gt;SilverlightBarChart.Chart.protoype&lt;/em&gt;:&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;&lt;code&gt;createBars: function(barXaml) &lt;br&gt;{&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; var barTarget = null;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; var barCount = 0;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; var barWidth = 0;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; var barHeight = 0;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; var maxValue = 0;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for(i in this.data)&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; barCount++;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if(this.data[i].value &amp;gt; maxValue)&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; maxValue = this.data[i].value;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; barWidth = (this.width - (this.padding * (barCount + 1))) / barCount;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for(var i = 0; i &amp;lt; barCount; i++)&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; barTarget = this.plugIn.content.createFromXaml(barXaml, true);&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; this.barContainer.children.add(barTarget);&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; barHeight = this.height * this.data[i].value / maxValue - this.padding;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; barTarget["Canvas.Top"] = this.height - barHeight;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; barTarget["Canvas.Left"] = barWidth * i + (this.padding * (i + 1));&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; barTarget.Width = barWidth;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; barTarget.Height = barHeight;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; this.bars.push(new SilverlightBarChart.Bar(barTarget));&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br&gt;}&lt;/code&gt;&lt;/p&gt; &lt;p&gt;Here's the magic method you've been waiting for.&amp;nbsp; Initially we setup a few variables for reuse. Second we loop through the properties of the data object in order to obtain the total count and the largest value.&amp;nbsp; This is done mainly because the JSON data is stored as an object and other than enumerating the properties there is no other way to simply get these values.&amp;nbsp; This initial loop could be avoided with more complex data structures or even by setting the discovered values directly.&lt;/p&gt; &lt;p&gt;Once we we've looped through the data we can figure out how wide each bar should be to fill up the chart, based on the chart width, padding and total bars.&lt;/p&gt; &lt;p&gt;Then we perform a second loop to create and set the properties of each bar.&amp;nbsp; The first line in the loop uses &lt;a href="http://msdn2.microsoft.com/en-us/library/bb980072.aspx"&gt;createFromXaml&lt;/a&gt; and the XAML string passed as a parameter to this method to create the Silverlight object for the bar.&amp;nbsp; Then we add the bar to the &lt;em&gt;barContainer &lt;/em&gt;so it will render and become interactive.&lt;/p&gt; &lt;p&gt;The following 5 lines dynamically set the height and width of the bar along with its position.&amp;nbsp; These numbers are calculated based off the size of the chart, the amount of bars and the value of each bar in comparison to the greatest value in the data set.&lt;/p&gt; &lt;p&gt;Don't hit Run yet, nothing new will happen.&lt;/p&gt; &lt;p&gt;&lt;strong&gt;Initializing the Chart&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;With our Chart and Bar components complete we can initialize the Chart in our main application.&lt;/p&gt; &lt;ul&gt; &lt;li&gt;Open Scene.js  &lt;li&gt;In the &lt;em&gt;handleLoad&lt;/em&gt; method, after the line that starts with &lt;em&gt;this.mainCanvas... &lt;/em&gt;add the following line: &lt;em&gt;this.chart = null;&lt;/em&gt;  &lt;li&gt;Remove the code within the brackets of the &lt;em&gt;onCompleted&lt;/em&gt; method and add the following code:&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;&lt;code&gt;if (sender.uri == "Chart.xaml")&lt;br&gt;{&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; var chartTarget = this.plugIn.content.createFromXamlDownloader(sender, "");&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; this.mainCanvas.children.add(chartTarget);&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; this.chart = new SilverlightBarChart.Chart(this.plugIn, chartTarget, chartData)&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; this.downloader.open("GET", "Bar.xaml");&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; this.downloader.send();&lt;br&gt;}&lt;br&gt;else&lt;br&gt;{&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; this.chart.createBars(sender.ResponseText);&lt;br&gt;}&lt;/code&gt;&lt;/p&gt; &lt;p&gt;What we've done here is daisy chain the asynchronous completed events of the downloader.&amp;nbsp; First in the &lt;em&gt;handleLoad&lt;/em&gt; method we asked the downloader to go get Chart.xaml.&amp;nbsp; Once it completes that request, we create a new instance of the Chart class using that response then we ask the downloader to go get the Bar.xaml file.&amp;nbsp; Once it has that response, we call the &lt;em&gt;createBars&lt;/em&gt; method of the new &lt;em&gt;Chart&lt;/em&gt; instance, passing the &lt;em&gt;ResponseText&lt;/em&gt; as the &lt;em&gt;barXaml&lt;/em&gt; parameter.&lt;/p&gt; &lt;p&gt;The script is set up now but we need to add a few JavaScript references in the Default.html in order for the newly created script classes to be resolved.&lt;/p&gt; &lt;ul&gt; &lt;li&gt;Open Default.html  &lt;li&gt;Locate the script tags at the top of the page and change them to match the following code:&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;&lt;code&gt;&amp;lt;script type="text/javascript" src="Silverlight.js"&amp;gt;&amp;lt;/script&amp;gt;&lt;br&gt;&amp;lt;script type="text/javascript" src="chartData.js"&amp;gt;&amp;lt;/script&amp;gt;&lt;br&gt;&amp;lt;script type="text/javascript" src="Chart.js"&amp;gt;&amp;lt;/script&amp;gt;&lt;br&gt;&amp;lt;script type="text/javascript" src="Bar.js"&amp;gt;&amp;lt;/script&amp;gt;&lt;br&gt;&amp;lt;script type="text/javascript" src="Scene.js"&amp;gt;&amp;lt;/script&amp;gt;&lt;/code&gt;&lt;/p&gt; &lt;p&gt;First, we still need a reference to the Silverlight.js which will provide the application helper functions.&amp;nbsp; Then a reference to the JSON data file which we will create next.&amp;nbsp; Followed by the class files of our two components and our application.&lt;/p&gt; &lt;ul&gt; &lt;li&gt;File -&amp;gt; New -&amp;gt; File...  &lt;li&gt;Select the JScriptFile Template  &lt;li&gt;Name the file chartData.js  &lt;li&gt;Open the file and add JSON formatted data as follows:&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;&lt;code&gt;chartData = [{"value":285}, {"value":342}, {"value":248}, {"value":120}, {"value":204}, {"value":190}, {"value":255}, {"value":238}, {"value":501}, {"value":297}];&lt;/code&gt;&lt;/p&gt; &lt;p&gt;The values are completely arbitrary but the script is looking for properties named &lt;em&gt;value&lt;/em&gt; with numerically typed values.&amp;nbsp; So feel free to change the values, but don't change the format of the object properties until you feel comfortable changing the script.&lt;/p&gt; &lt;p&gt;Hit Run and you should see a chart similar to the picture below:&lt;/p&gt; &lt;p&gt;&lt;img src="http://adamkinney.com/images/blog/sl_chart.jpg" alt="" /&gt; &lt;/p&gt; &lt;p&gt;Success!&amp;nbsp;&amp;nbsp; You have a chart!&amp;nbsp; Awesome!&lt;/p&gt; &lt;p&gt;&lt;strong&gt;"But what about..."&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;Yes, there is plenty more you could do with this chart, but it is all outside of the scope of this tutorial.&amp;nbsp; Many different features come to mind such as:&lt;/p&gt; &lt;ul&gt; &lt;li&gt;Different data sources&lt;/li&gt; &lt;li&gt;Assets packaged into one .zip file&lt;/li&gt; &lt;li&gt;Loading data animations&lt;/li&gt; &lt;li&gt;Easing animations for the bars&lt;/li&gt; &lt;li&gt;Different visual styles for the chart and bars ( &lt;a href="http://www.microsoft.com/expression/products/download.aspx?key=blend2preview"&gt;Expression Blend&lt;/a&gt; is waiting for you )&lt;/li&gt; &lt;li&gt;Different types of Charts&lt;/li&gt; &lt;li&gt;Values&amp;nbsp; on Bar Rollover (This is where the Bar JavaScript class would come in handy)&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;Hopefully this tutorial has shown you its not that difficult to get started and it can be fun once you start getting seeing the results of your work.&amp;nbsp; I did not explain every single piece of code, but I did try and highlight the key concepts.&amp;nbsp; If you have questions I would suggest starting with the &lt;a href="http://msdn2.microsoft.com/en-us/library/bb979679.aspx"&gt;Silverlight API reference&lt;/a&gt;. That's my favorite place to start.&lt;/p&gt; &lt;p&gt;And since you have made it all the way through this tutorial or even if you just scrolled to the bottom, you can &lt;a href="http://adamkinney.com/downloads/silverlightbarchart.zip"&gt;download the completed source&lt;/a&gt; directly.&lt;/p&gt; &lt;p&gt;Cool.&amp;nbsp; That's one line I can check off my Must-Write-About-Because-Its-Constantly-Requested list...&lt;/p&gt; &lt;p&gt;Enjoy!&lt;/p&gt;&lt;img src="http://adamkinney.com/blog/306/aggviewbug/default.aspx" alt="" /&gt;</description><comments>http://adamkinney.com/blog/306/default.aspx</comments><link>http://adamkinney.com/blog/306/default.aspx</link><pubDate>Tue, 05 Feb 2008 22:24:00 GMT</pubDate><guid isPermaLink="true">http://adamkinney.com/blog/306/default.aspx</guid><dc:creator>Adam Kinney</dc:creator><slash:comments>9</slash:comments><trackback:ping>http://adamkinney.com/blog/306/trackback/default.aspx</trackback:ping><category>Silverlight</category><category>tutorial</category></item><item><title>Consuming JSON data with Silverlight</title><description>&lt;blockquote&gt; &lt;p&gt;How would I use JSON data with Silverlight?&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;I've been asked this a few times and &lt;a href="http://blogs.msdn.com/daiken/"&gt;it happened again today&lt;/a&gt;.&amp;nbsp; So tonight is the night to write a quick tutorial on how easy it is to do this.&amp;nbsp; You can start from scratch or from any Silverlight 1.0 template, but I will be walking through the steps using Visual Studio 2008.&lt;/p&gt; &lt;p&gt;First step is to create the project.&lt;/p&gt; &lt;p&gt;&lt;code&gt;File -&amp;gt; New -&amp;gt; WebSite... -&amp;gt; Silverlight Script Web&lt;/code&gt;&lt;/p&gt; &lt;p&gt;Now we need some JSON data. I'm going to grab the latest posts from Twitter using their &lt;a href="http://twitter.com/help/api"&gt;simple and sweet API&lt;/a&gt;.&amp;nbsp; All I need to do is add a reference to the API and add a callback function to be called once the data has been received.&amp;nbsp; In the project template, I placed this line below the script block that contains the createObjectEx function.&lt;/p&gt; &lt;p&gt;&lt;code&gt;&amp;lt;script type="text/javascript" src="http://twitter.com/statuses/public_timeline.json?callback=&lt;strong&gt;twitterCallback&lt;/strong&gt;"&amp;gt;&amp;lt;/script&amp;gt;&lt;/code&gt;&lt;/p&gt; &lt;p&gt;Now to handle the loading of the data.&amp;nbsp; Within the script block containing the createObjectEx function, we first define a couple of global variables at the top.&amp;nbsp; twitterData is used to store the JSON data and scene will act as a reference to our Silverlight Application class.&lt;/p&gt; &lt;p&gt;&lt;code&gt;var twitterData;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br&gt;var scene;&lt;/code&gt;&lt;/p&gt; &lt;p&gt;Modify the Silverlight class constructor to use the newly declared scene variable by removing the var from the line below.&lt;/p&gt; &lt;p&gt;&lt;code&gt;&lt;strike&gt;var&lt;/strike&gt; scene = new &lt;em&gt;YourProjectName&lt;/em&gt;.Scene();&lt;/code&gt;&lt;/p&gt; &lt;p&gt;Next, add the twitterCallback function.&lt;/p&gt; &lt;p&gt;&lt;code&gt;function twitterCallback(obj)&lt;br&gt;{&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; twitterData = obj;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; scene.loadData();&lt;br&gt;}&lt;/code&gt;&lt;/p&gt; &lt;p&gt;Now open up you Silverlight application class file.&amp;nbsp; In the project template, the default name is Scene.js.&lt;/p&gt; &lt;ul&gt; &lt;li&gt;Remove all of the functions except for the handleLoad function.  &lt;li&gt;Within the handleLoad function, remove the sample event hookup code so you are left with the plugIn definition line.  &lt;li&gt;In the handleLoad function, add a property for the rootElement:&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;&lt;code&gt;this.root = rootElement;&lt;/code&gt;&lt;/p&gt; &lt;ul&gt; &lt;li&gt;Add the new loadData function defined below (make sure you leave a comma between handleLoad and loadData function definitions):&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;&lt;code&gt;loadData: function(){&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var item;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for(i=0;i&amp;lt;5;i++){&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; item = this.plugIn.content.createFromXaml('&amp;lt;Canvas&amp;gt;&amp;lt;Image Source="' + twitterData[i].user.profile_image_url + '" /&amp;gt;&amp;lt;TextBlock Canvas.Left="54"&amp;gt;' + twitterData[i].user.name + '&amp;lt;/TextBlock&amp;gt;&amp;lt;/Canvas&amp;gt;');&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; item["Canvas.Top"] = i*54;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; this.root.children.add(item);&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br&gt;}&lt;/code&gt;&lt;/p&gt; &lt;p&gt; The above function loops through the first 5 posts and creates a new Silverlight object for each one using their name and profile image. &lt;a href="http://msdn2.microsoft.com/en-us/library/bb412361.aspx"&gt;createFromXaml&lt;/a&gt; is the magic function which takes a string, parses it and returns an object.&amp;nbsp; The string could come from anywhere, often a separate .xaml file accessed via a &lt;a href="http://msdn2.microsoft.com/en-us/library/bb232870.aspx"&gt;downloader&lt;/a&gt; object.&amp;nbsp; Once the object is made the top position is based of the index, which causes the items to be vertically stacked.&amp;nbsp; Then the new object is added to the this.root which is a reference to the main Canvas defined in the handleLoad function above.&lt;/p&gt; &lt;p&gt;Now the last step is to open up the Scene.xaml file and remove all of the lines except for the outermost Canvas element.&lt;/p&gt; &lt;p&gt;And that's it!&amp;nbsp; Seriously, hit F5, run your project and you should see something like this:&lt;/p&gt; &lt;p&gt;&lt;img src="http://adamkinney.com/images/blog/simplejson.jpg" alt="" /&gt; &lt;/p&gt; &lt;p&gt;Now enjoy and run with it.&amp;nbsp; Hopefully this short tutorial will help you in your quest to create JSON-based Silverlight applications or at least a new Silverlight-based Twitter widget.&lt;/p&gt;&lt;img src="http://adamkinney.com/blog/290/aggviewbug/default.aspx" alt="" /&gt;</description><comments>http://adamkinney.com/blog/290/default.aspx</comments><link>http://adamkinney.com/blog/290/default.aspx</link><pubDate>Wed, 19 Dec 2007 10:22:00 GMT</pubDate><guid isPermaLink="true">http://adamkinney.com/blog/290/default.aspx</guid><dc:creator>Adam Kinney</dc:creator><slash:comments>2</slash:comments><trackback:ping>http://adamkinney.com/blog/290/trackback/default.aspx</trackback:ping><category>demo</category><category>JavaScript</category><category>Silverlight</category><category>tutorial</category></item></channel></rss>