<?xml version='1.0' encoding='UTF-8'?><rss xmlns:atom='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:thr='http://purl.org/syndication/thread/1.0' version='2.0'><channel><atom:id>tag:blogger.com,1999:blog-16855281</atom:id><lastBuildDate>Sat, 08 May 2010 08:56:18 +0000</lastBuildDate><title>house of mirrors</title><description></description><link>http://blois.us/blog/</link><managingEditor>noreply@blogger.com (pete blois)</managingEditor><generator>Blogger</generator><openSearch:totalResults>78</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-16855281.post-4491695691969188500</guid><pubDate>Mon, 15 Mar 2010 17:53:00 +0000</pubDate><atom:updated>2010-03-15T10:53:49.677-07:00</atom:updated><title>Labyrinth Sample for Windows Phone</title><description>&lt;p&gt;When I finally got my hands on the Windows Phone developer tools the first thing I wanted to do was to see how well Silverlight on the phone would work for making 2D games, so I decided to make a Labyrinth style game.&lt;/p&gt;  &lt;p&gt;The setup is fairly straightforward- I’m using the same Box2D physics engine &amp;amp; Silverlight adapters that are included in the &lt;a href="http://blois.us/Expression.Samples/Expression.Samples.zip"&gt;behaviors library&lt;/a&gt; I sent out in November. Basically the physics engine is running on the root of each level and the accelerometer from the Windows Phone device is hooked up to control the gravity of the physics engine. When the game is running in the emulator rather than a real device I simulate an accelerometer by dragging the mouse.&lt;/p&gt;  &lt;p&gt;The basic application took about half a day to get running and another full day of playing around creating random levels (I tried to make it somewhat non-traditional). After that it was just polish and lots of play-testing (of course!).&lt;/p&gt;  &lt;p&gt;The game uses the standard Windows Phone styling and navigation model to navigate between levels. Isolated storage is used to store how long it took to complete a level.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh5.ggpht.com/_5dJL4x-KevE/S550GBjSOXI/AAAAAAAAABM/Nktp9e5W454/s1600-h/image%5B17%5D.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/_5dJL4x-KevE/S550Gu02g6I/AAAAAAAAABU/NgxlmlWemb4/image_thumb%5B11%5D.png?imgmax=800" width="288" height="480" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Standard Labyrinth-style level- everything is vector graphics &amp;amp; controls except for the wood textures. Uses the hardware accelerated drop-shadow effect for depth on the walls and the ball.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh4.ggpht.com/_5dJL4x-KevE/S550Hu5XVbI/AAAAAAAAABY/bklGAjRRXVg/s1600-h/image%5B12%5D.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/_5dJL4x-KevE/S550Ibz08RI/AAAAAAAAABc/qrerDoXWK8Y/image_thumb%5B8%5D.png?imgmax=800" width="288" height="480" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;I was having a real good time playing around with alternate level ideas- this one is probably my favorite. Basically when the ball hits a flipper, the flipper activates and knocks the ball away. It’s a pretty tough level :)&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh4.ggpht.com/_5dJL4x-KevE/S550JEHpNQI/AAAAAAAAABg/uwGMQG4xY1A/s1600-h/image%5B6%5D.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/_5dJL4x-KevE/S550JlJ93-I/AAAAAAAAABk/yyYAj4cDvQw/image_thumb%5B4%5D.png?imgmax=800" width="288" height="480" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;This one is a bunch of magnets that push the ball away from them. It’s a pretty fun level to play as well.&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh6.ggpht.com/_5dJL4x-KevE/S550Kdu6UYI/AAAAAAAAABo/MrbqbL3HIjc/s1600-h/image%5B22%5D.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/_5dJL4x-KevE/S550LAh_LJI/AAAAAAAAABs/9lB9rtVjmAw/image_thumb%5B14%5D.png?imgmax=800" width="288" height="480" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Source code: &lt;a href="http://blois.us/Silverlight/Madness/Madness.zip"&gt;Madness.zip&lt;/a&gt;&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/16855281-4491695691969188500?l=blois.us%2Fblog%2Findex.html' alt='' /&gt;&lt;/div&gt;</description><link>http://blois.us/blog/2010/03/labyrinth-sample-for-windows-phone.html</link><author>noreply@blogger.com (Pete)</author><thr:total>7</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-16855281.post-2839598681411375194</guid><pubDate>Mon, 11 Jan 2010 00:06:00 +0000</pubDate><atom:updated>2010-01-10T16:06:45.821-08:00</atom:updated><title>Flexible Progress Control</title><description>&lt;p&gt;A while ago I was looking for an easy way to design decent preloaders- hopefully to allow people to create something along the lines of some of these &lt;a href="http://www.smashingmagazine.com/2008/03/13/showcase-of-creative-flash-preloaders/"&gt;Flash preloaders&lt;/a&gt; showcased in Smashing Magazine.&lt;/p&gt;  &lt;p&gt;The approach that I put together is a custom control (StoryboardedProgressControl) which is a subclass of ProgressBar, but uses an Storyboard to represent the loading progress. To use it you just create an animation of what the loading progress should look like and it just seeks to the appropriate time. This way you can represent progress in anything which can be animated- colors, paths, etc.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blois.us/CodeBrowser/?zip=../Silverlight/Progress/Progress.zip#file=Progress/Progress/StoryboardedProgressBar.cs"&gt;StoryboardedProgressControl.cs&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blois.us/Silverlight/Progress/"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: block; float: none; margin-left: auto; border-top: 0px; margin-right: auto; border-right: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/_rFfWHybtNug/S0prlGwf_PI/AAAAAAAAAEc/LJI66jU_Ykw/image%5B5%5D.png?imgmax=800" width="200" height="552" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blois.us/Silverlight/Progress/"&gt;Sample Application&lt;/a&gt;, &lt;a href="http://blois.us/CodeBrowser/?zip=../Silverlight/Progress/Progress.zip#file=Progress/Progress.Test/MainPage.xaml"&gt;sample source&lt;/a&gt;. (thanks to &lt;a href="http://blog.nibblestutorials.net/"&gt;Celso&lt;/a&gt; for the Bottle loader graphics!)&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/16855281-2839598681411375194?l=blois.us%2Fblog%2Findex.html' alt='' /&gt;&lt;/div&gt;</description><link>http://blois.us/blog/2010/01/flexible-progress-control.html</link><author>noreply@blogger.com (Pete Blois)</author><thr:total>2</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-16855281.post-6283462050529835592</guid><pubDate>Mon, 30 Nov 2009 20:31:00 +0000</pubDate><atom:updated>2009-11-30T12:31:58.820-08:00</atom:updated><title>Source Code Browser</title><description>&lt;p&gt;I hadn’t gotten a chance to play with Silverlight 4’s new RichTextArea control before PDC but really wanted to give it a try. With the holidays I was finally able to give it a try on an app that I had been wanting to put together for a while- a source code browser that works similarly to Flex’s &lt;a href="http://cookbooks.adobe.com/index.cfm?event=showdetails&amp;amp;postId=7752"&gt;source code publishing&lt;/a&gt; feature.&lt;/p&gt;  &lt;p&gt;What I did was put together an app that downloads a zipped up project file from the server, finds all of the solution files then parses the solutions and projects to create a project browser. When a file is selected it gets displayed in a RichTextArea with some primitive syntax highlighting.&lt;/p&gt;  &lt;p&gt;This way rather than having to go through the bother of downloading the source code, unzipping it, opening it in VS just to see a chunk of code, you can easily browse it in the web page. By working off of zipped projects, it doesn’t require any additional steps to publish beyond what I was already doing in uploading the zipped source.&lt;/p&gt;  &lt;p&gt;And thanks to Ben Lemmon who helped out with some code to &lt;a href="http://blogs.msdn.com/blemmon/archive/2009/11/25/reading-zip-files-from-silverlight.aspx"&gt;parse the ZIP file headers&lt;/a&gt; making it easy to walk the files of a ZIP package.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blois.us/CodeBrowser/?zip=CodeBrowser.zip"&gt;Source Code Browser Source&lt;/a&gt; (and demo of it in action)&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/16855281-6283462050529835592?l=blois.us%2Fblog%2Findex.html' alt='' /&gt;&lt;/div&gt;</description><link>http://blois.us/blog/2009/11/source-code-browser.html</link><author>noreply@blogger.com (Pete Blois)</author><thr:total>7</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-16855281.post-1300390765014373861</guid><pubDate>Mon, 30 Nov 2009 19:44:00 +0000</pubDate><atom:updated>2009-11-30T11:44:59.172-08:00</atom:updated><title>PDC Samples</title><description>&lt;p&gt;The week before last I was at PDC and did a little talk on creating behaviors, for this talk I used a number of behaviors from the Expression.Samples project on CodePlex along with some additions that I’ve been working on.&lt;/p&gt;  &lt;p&gt;I have an updated version of the Expression.Samples project to support .NET 4, Silverlight 4 and also adding Physics support (based on the Box2D physics engine) and a sample of an action with Python script.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blois.us/CodeBrowser/?zip=http://blois.us/Expression.Samples/Expression.Samples.zip"&gt;The source code for the Silverlight 4 version of the Expression.Samples project.&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;(I’m experimenting with a source code browser that allows viewing zipped solutions to save the hassle of downloading a ZIP and opening it with Visual Studio).&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/16855281-1300390765014373861?l=blois.us%2Fblog%2Findex.html' alt='' /&gt;&lt;/div&gt;</description><link>http://blois.us/blog/2009/11/pdc-samples.html</link><author>noreply@blogger.com (Pete Blois)</author><thr:total>1</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-16855281.post-4189096526810013929</guid><pubDate>Thu, 20 Aug 2009 02:34:00 +0000</pubDate><atom:updated>2009-08-19T19:34:52.656-07:00</atom:updated><title>Creating Silverlight control templates from Illustrator</title><description>&lt;p&gt;In the previous post I showed off a &lt;a href="http://blois.us/blog/2009/08/silverlight-nine-grid.html"&gt;Silverlight nine grid&lt;/a&gt;, this one explains how to leverage it to create control templates from Illustrator comps of controls.&lt;/p&gt;  &lt;p&gt;&lt;em&gt;(I wrote this a while back but am not super happy about the workflow. I decided to post it anyways in the hope that it might be a helpful to someone).&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;I’m starting with a basic button that Billy Chow (a graphic designer on the Blend team) put together- it just has the basic states of a button.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh3.ggpht.com/_rFfWHybtNug/Soy2Lp_8LkI/AAAAAAAAAC0/VuSynkE_oBY/s1600-h/image3.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/_rFfWHybtNug/Soy2L9EfMrI/AAAAAAAAAC4/chP7K1LFklw/image_thumb1.png?imgmax=800" width="155" height="147" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blois.us/Silverlight/Scale9/Button.ai"&gt;Illustrator source file&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;First step is to import the Illustrator file into Expression Blend and do some grouping and organization on the file.&lt;/p&gt;  &lt;p&gt;When working with paths in Silverlight I always like to turn off &lt;a href="http://msdn.microsoft.com/en-us/library/cc896566(VS.95).aspx"&gt;Layout Rounding&lt;/a&gt;- this can cause rounding errors which come back as visual cropping and such later on. To do this, just select the root of the imported object and turn off the UseLayoutRounding property- it’s under advanced layout.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh4.ggpht.com/_rFfWHybtNug/Soy2L8Z0QGI/AAAAAAAAAC8/SMfycv4v5Pw/s1600-h/image18.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/_rFfWHybtNug/Soy2MPHZG5I/AAAAAAAAADA/berGvJ5o8a8/image_thumb10.png?imgmax=800" width="253" height="45" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Next select the groups of paths that compose each of the states, group them each into a grid and name the grid with the state name:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh3.ggpht.com/_rFfWHybtNug/Soy2M6-zZMI/AAAAAAAAADE/WRCVKg0jWp8/s1600-h/image22.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/_rFfWHybtNug/Soy2NnsXkKI/AAAAAAAAADI/FBfJf6PAbfo/image_thumb12.png?imgmax=800" width="239" height="95" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;First state grouped and named:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh6.ggpht.com/_rFfWHybtNug/Soy2NkNP0TI/AAAAAAAAADM/qF2OVORRNn8/s1600-h/image30.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/_rFfWHybtNug/Soy2N5L677I/AAAAAAAAADQ/7Zj1Lc6v82Y/image_thumb16.png?imgmax=800" width="237" height="48" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;And while you’re at it, delete all of the TextBlocks that are the content of the Buttons- we’ll have the text come from the Button itself later.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh4.ggpht.com/_rFfWHybtNug/Soy2OI8nLBI/AAAAAAAAADU/zfkEGU88g9M/s1600-h/image38.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/_rFfWHybtNug/Soy2OYuWSKI/AAAAAAAAADY/CMZPhzRSFvQ/image_thumb20.png?imgmax=800" width="233" height="122" /&gt;&lt;/a&gt;&amp;#160; &lt;a href="http://lh5.ggpht.com/_rFfWHybtNug/Soy2OtDqEHI/AAAAAAAAADc/Hi7n_WLbjTs/s1600-h/image34.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/_rFfWHybtNug/Soy2O4ZBmLI/AAAAAAAAADg/qqVRtZUj9iU/image_thumb18.png?imgmax=800" width="85" height="143" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Next select all of the state groups and set their Left and Top properties to 0 so they are all on top of each other.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh4.ggpht.com/_rFfWHybtNug/Soy2PgytTKI/AAAAAAAAADk/eipO-omZ3q8/s1600-h/image42.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/_rFfWHybtNug/Soy2QFh_VDI/AAAAAAAAADo/7lGNsGgAsI8/image_thumb22.png?imgmax=800" width="200" height="54" /&gt;&lt;/a&gt;&amp;#160; &lt;a href="http://lh4.ggpht.com/_rFfWHybtNug/Soy2QVOuNOI/AAAAAAAAADs/xTiDG8WvgXQ/s1600-h/image50.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/_rFfWHybtNug/Soy2QYhNoBI/AAAAAAAAADw/Hqv8K3IHgZ0/image_thumb26.png?imgmax=800" width="88" height="28" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Group them into a Grid (control-G)&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh5.ggpht.com/_rFfWHybtNug/Soy2QvESMOI/AAAAAAAAAD0/GHnqW18rqoI/s1600-h/image54.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/_rFfWHybtNug/Soy2Q-Mn9JI/AAAAAAAAAD4/1Ux7hPFaBUk/image_thumb28.png?imgmax=800" width="226" height="130" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Then put that Grid into a NineGrid control to handle the scaling:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh6.ggpht.com/_rFfWHybtNug/Soy2RC5pKBI/AAAAAAAAAD8/vyObdq_bAwY/s1600-h/image59.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/_rFfWHybtNug/Soy2RdLj_iI/AAAAAAAAAEA/Ezf0gScr4NM/image_thumb31.png?imgmax=800" width="248" height="137" /&gt;&lt;/a&gt; &lt;a href="http://lh3.ggpht.com/_rFfWHybtNug/Soy2RyF7y6I/AAAAAAAAAEE/0dsdTKtV5ZY/s1600-h/image62.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/_rFfWHybtNug/Soy2SKclrqI/AAAAAAAAAEI/YMbpAlzFNOs/image_thumb32.png?imgmax=800" width="100" height="40" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Tweak the bounds of the NineGrid to get the right scaling regions- for this sample I used 6 pixels on the left and right, 5 top and bottom.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh6.ggpht.com/_rFfWHybtNug/Soy2SQ8gsWI/AAAAAAAAAEM/eeZxzBStw4o/s1600-h/image66.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/_rFfWHybtNug/Soy2SRKXj7I/AAAAAAAAAEQ/7q9cok9epVM/image_thumb34.png?imgmax=800" width="171" height="48" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Next, right-click the NineGrid, choose ‘Make Into Control…’, choose Button, then OK.&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Setting up the states&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;At this point we have a scalable, reusable Button template. Next step is making the visuals update with the state changes.&lt;/p&gt;  &lt;p&gt;Let’s rearrange the state groups so that we have some visual priority- making the mouse states appear over the focus states:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh6.ggpht.com/_rFfWHybtNug/Soy2Skeni9I/AAAAAAAAAEU/FQbC8ptI9tU/s1600-h/image70.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/_rFfWHybtNug/Soy2S3JAJbI/AAAAAAAAAEY/oZXiIVRlBQU/image_thumb36.png?imgmax=800" width="233" height="123" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Next select all of the state groups &lt;i&gt;except&lt;/i&gt; Normal and set their visibilities to Collapsed.&lt;/p&gt;  &lt;p&gt;Then go through each of the states in the States pane and set each of the corresponding part’s visibility to Visible for the state:&lt;/p&gt;  &lt;p&gt;· In the MouseOver state set Hover to Visible&lt;/p&gt;  &lt;p&gt;· In the Pressed state set Click to Visible&lt;/p&gt;  &lt;p&gt;· In the Focused state set Focus to Visible&lt;/p&gt;  &lt;p&gt;Build &amp;amp; run the application!&lt;/p&gt; &lt;iframe style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" height="99" src="http://blois.us/Silverlight/Scale9/Illustrator/demo.html" frameborder="0" width="380"&gt;&lt;/iframe&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/16855281-4189096526810013929?l=blois.us%2Fblog%2Findex.html' alt='' /&gt;&lt;/div&gt;</description><link>http://blois.us/blog/2009/08/creating-silverlight-control-templates.html</link><author>noreply@blogger.com (Pete Blois)</author><thr:total>1</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-16855281.post-400187350324127711</guid><pubDate>Sat, 08 Aug 2009 00:47:00 +0000</pubDate><atom:updated>2009-08-07T17:47:07.452-07:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>Scale9</category><category domain='http://www.blogger.com/atom/ns#'>C#</category><category domain='http://www.blogger.com/atom/ns#'>Silverlight</category><category domain='http://www.blogger.com/atom/ns#'>ninegrid</category><title>Silverlight Nine Grid</title><description>&lt;p&gt;I was recently working on a project where I ran into a need for a nice &lt;a href="http://www.sephiroth.it/tutorials/flashPHP/scale9/"&gt;nine grid&lt;/a&gt; (or scale 9 grid) and realized that with some of the new additions in Silverlight 3 and Blend 3 that one could put together a pretty sweet solution based on pixel shaders and the new design-time extensibility in Blend.&lt;/p&gt;  &lt;p&gt;&lt;iframe style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" height="400" src="http://blois.us/Silverlight/Scale9" frameborder="0" width="500"&gt;&lt;/iframe&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Nine Grids&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;Just in case everyone isn’t aware of what a nine grid is, it’s a technique for splitting up an image into 9 pieces then scaling those pieces to simulate layout-aware resizing rather than uniform scaling. Nine grids are very useful because they allow graceful resizing of otherwise non-resizable images.&lt;/p&gt;  &lt;p&gt;Normally nine grids are done using either one image duplicated, scaled and cropped into 9 parts but I realized that this could be done much more elegantly with a single shader to handle the appropriate stretching. The real big benefit of using an effect is that vector path data from tools such as Illustrator can be nine-gridded in addition to images. A pixel shader also results in a much lower framework element count which helps keep control instantiation time zippy.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Design-Time&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;Using Blend 3’s new design-time extensions I was also able to put together a solid editing experience complete with adorners on the design-surface- makes it quick and easy to configure.&lt;/p&gt;  &lt;p&gt;&lt;iframe style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" height="380" src="http://blois.us/Silverlight/Scale9/vid" frameborder="0" width="600"&gt;&lt;/iframe&gt;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blois.us/Silverlight/Scale9/Scale9.zip"&gt;Source and binaries.&lt;/a&gt;&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/16855281-400187350324127711?l=blois.us%2Fblog%2Findex.html' alt='' /&gt;&lt;/div&gt;</description><link>http://blois.us/blog/2009/08/silverlight-nine-grid.html</link><author>noreply@blogger.com (Pete Blois)</author><thr:total>12</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-16855281.post-2893484511413732544</guid><pubDate>Mon, 13 Jul 2009 19:37:00 +0000</pubDate><atom:updated>2009-07-13T12:37:23.611-07:00</atom:updated><title>Explode!</title><description>&lt;p&gt;My favorite thing to do with behaviors is to make interfaces explode- I've been doing this for years and it never fails to lighten up my day. With behaviors in Blend 3 and perspective transforms in Silverlight 3 I was finally able to make an decently gratifying explode behavior.&lt;/p&gt; &lt;iframe style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" height="480" src="http://blois.us/Explosions" frameborder="0" width="640"&gt;&lt;/iframe&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blois.us/Explosions/Explode.cs"&gt;Explode.cs&lt;/a&gt;&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/16855281-2893484511413732544?l=blois.us%2Fblog%2Findex.html' alt='' /&gt;&lt;/div&gt;</description><link>http://blois.us/blog/2009/07/explode.html</link><author>noreply@blogger.com (Pete Blois)</author><thr:total>18</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-16855281.post-8390474176051291505</guid><pubDate>Mon, 13 Jul 2009 18:48:00 +0000</pubDate><atom:updated>2009-07-13T11:48:57.833-07:00</atom:updated><title>Expression Blend Samples</title><description>&lt;p&gt;We've been working on a set of behaviors and effects for use in Expression Blend 3, beyond the set that are being shipped with the product. These are mostly experimental or 'interesting' ones that can be useful in a variety of different circumstances.&lt;/p&gt;  &lt;p&gt;The source code and an installer to have them automatically appear in Blend can be found on the &lt;a href="http://expressionblend.codeplex.com/"&gt;Expression Blend CodePlex&lt;/a&gt; site.&lt;/p&gt;  &lt;p&gt;Some of the triggers, actions and behaviors which are included:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;strong&gt;PlayMedia&lt;/strong&gt;- plays a media element&lt;/li&gt;    &lt;li&gt;&lt;strong&gt;PauseMedia&lt;/strong&gt;- pauses a media element&lt;/li&gt;    &lt;li&gt;&lt;strong&gt;TogglePlayPauseMedia&lt;/strong&gt;- toggles between play/pause on a media element&lt;/li&gt;    &lt;li&gt;&lt;strong&gt;StopMedia&lt;/strong&gt;- stops a media element&lt;/li&gt;    &lt;li&gt;&lt;strong&gt;MouseGestureTrigger&lt;/strong&gt;- triggers an action when the user makes a gesture on the element.&lt;/li&gt;    &lt;li&gt;&lt;strong&gt;MouseEventTrigger&lt;/strong&gt;- allows more complex mouse triggers such as double-click or firing from handled events&lt;/li&gt;    &lt;li&gt;&lt;strong&gt;StateChangedTrigger&lt;/strong&gt;- triggers when the state is changed&lt;/li&gt;    &lt;li&gt;&lt;strong&gt;CallDataMethod&lt;/strong&gt;- calls a method on the data context&lt;/li&gt;    &lt;li&gt;&lt;strong&gt;InvokeDataCommand&lt;/strong&gt;- executes a command on the data context&lt;/li&gt;    &lt;li&gt;&lt;strong&gt;DataEventTrigger&lt;/strong&gt;-&lt;strong&gt; &lt;/strong&gt;triggers when an event is raised on the data context. Useful for doing something such as playing a sound or animation when something happens on the data context&lt;/li&gt;    &lt;li&gt;&lt;strong&gt;SetDataProperty&lt;/strong&gt;- sets a property on the data context&lt;/li&gt;    &lt;li&gt;&lt;strong&gt;DataStateBehavior&lt;/strong&gt;- switches between two states depending on the value of a binding&lt;/li&gt;    &lt;li&gt;&lt;strong&gt;FluidBindProperty&lt;/strong&gt;- acts as a proxy for databound properties in order to animate the changing of the value&lt;/li&gt;    &lt;li&gt;&lt;strong&gt;PropertyChangedTrigger&lt;/strong&gt;- triggers when the value of the property changes, regardless of the new value&lt;/li&gt;    &lt;li&gt;&lt;strong&gt;ClippingBehavior&lt;/strong&gt;- Provides a rounded rectangular clipping that scales with the element. Useful since Silverlight and WPF clipping geometries don't scale with objects&lt;/li&gt;    &lt;li&gt;&lt;strong&gt;GoToNextState&lt;/strong&gt;- Go to the next state in a VisualStateManager. Useful for quickly navigating between various states&lt;/li&gt;    &lt;li&gt;&lt;strong&gt;GoToPreviousState&lt;/strong&gt;- Go to the previous state in a VisualStateManager. Useful for quickly navigating between various states&lt;/li&gt;    &lt;li&gt;&lt;strong&gt;SetProperty&lt;/strong&gt;- Similar to ChangePropertyAction but allows incrementing as well as setting&lt;/li&gt;    &lt;li&gt;&lt;strong&gt;ShowMessageBox&lt;/strong&gt;- Displays a standard message box to the user&lt;/li&gt;    &lt;li&gt;&lt;strong&gt;ListBoxAddOne&lt;/strong&gt;- Action which duplicates a random item in the ItemsSource collection of a ListBox. Useful for SketchFlow prototypes where you want to show adding a new item&lt;/li&gt;    &lt;li&gt;&lt;strong&gt;ListBoxRemoveOne&lt;/strong&gt;- Action which removes a random item in the ItemsSource collection of a ListBox. Useful for SketchFlow prototypes to simulate removing an item.&lt;/li&gt;    &lt;li&gt;&lt;strong&gt;ListBoxRemoveThisItem&lt;/strong&gt;- Action for use inside of a ListBoxItem which will remove the item from the data collection of the owning ListBox.&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;The source code for the project also includes quite a bit of design-time work and might be useful as a reference if anyone is wondering how to take advantage of some of Blend's extensibility features for behaviors and effects.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/16855281-8390474176051291505?l=blois.us%2Fblog%2Findex.html' alt='' /&gt;&lt;/div&gt;</description><link>http://blois.us/blog/2009/07/expression-blend-samples.html</link><author>noreply@blogger.com (Pete Blois)</author><thr:total>1</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-16855281.post-6555586691989439514</guid><pubDate>Tue, 09 Jun 2009 05:13:00 +0000</pubDate><atom:updated>2009-06-08T22:13:09.157-07:00</atom:updated><title>Updated Rooler</title><description>&lt;p&gt;Just updated &lt;a href="http://blois.us/Rooler/"&gt;Rooler&lt;/a&gt; to add multi-mon support, by popular request :)&lt;/p&gt;  &lt;p&gt;As a bonus feature I also added support for high-DPI monitors.&lt;/p&gt;  &lt;p&gt;I should have had multi-mon in the first version, but got psyched out by it. Once I sat down to really get it fixed it only took an hour or so- always good when it goes like that. High DPI was a different story, I have my fingers crossed that I didn't break anything :)&lt;/p&gt;  &lt;p&gt;Enjoy!&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/16855281-6555586691989439514?l=blois.us%2Fblog%2Findex.html' alt='' /&gt;&lt;/div&gt;</description><link>http://blois.us/blog/2009/06/updated-rooler.html</link><author>noreply@blogger.com (Pete Blois)</author><thr:total>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-16855281.post-8409039809670828599</guid><pubDate>Sat, 02 May 2009 21:12:00 +0000</pubDate><atom:updated>2009-05-02T14:12:35.191-07:00</atom:updated><title>Rooler</title><description>&lt;p&gt;I'm always working on random projects, usually simple utilities to make my life just a little easier. One of my latest projects has been &lt;a href="http://blois.us/Rooler"&gt;Rooler&lt;/a&gt;, a collection of utilities for measuring and analyzing on-screen graphics. I've been doing lots of pixel tweaking stuff on Expression Blend these past couple of weeks and I decided to put something together that would help out. A lot of the inspiration for this came from the really cool OSX-only application &lt;a href="http://iconfactory.com/software/xscope"&gt;xScope&lt;/a&gt;- if you're a Mac user then I'd definitely suggest giving it a try.&lt;/p&gt;  &lt;p&gt;Anyways, what is this &lt;a href="http://blois.us/Rooler"&gt;Rooler&lt;/a&gt;? &lt;/p&gt;  &lt;p&gt;It measures the spacing of graphics:&lt;/p&gt;  &lt;p&gt;&lt;img border="0" alt="image" src="http://lh6.ggpht.com/_rFfWHybtNug/Sfy3QAQ5xII/AAAAAAAAACQ/lCs0eW0C-0o/image%5B4%5D.png?imgmax=800" width="240" height="39" /&gt; &lt;/p&gt;  &lt;p&gt;The size of graphics:&lt;/p&gt;  &lt;p&gt;&lt;img border="0" alt="image" src="http://lh6.ggpht.com/_rFfWHybtNug/Sfy3QXbMK8I/AAAAAAAAACU/uvak7NIYqxk/image%5B8%5D.png?imgmax=800" width="128" height="51" /&gt; &lt;/p&gt;  &lt;p&gt;It magnifies:&lt;/p&gt;  &lt;p&gt;&lt;img border="0" alt="image" src="http://lh6.ggpht.com/_rFfWHybtNug/Sfy3QoYjgWI/AAAAAAAAACY/AfElzu4_J7o/image%5B12%5D.png?imgmax=800" width="152" height="157" /&gt;&amp;#160; &lt;/p&gt;  &lt;p&gt;And it works on any graphics on your screen. HTML, Silverlight, Flash, photos, whatever. As long as it renders on your monitor. Plus there's more. And more crazy ideas to come.&lt;/p&gt;  &lt;p&gt;Check out the &lt;a href="http://blois.us/Rooler"&gt;Rooler&lt;/a&gt; site.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/16855281-8409039809670828599?l=blois.us%2Fblog%2Findex.html' alt='' /&gt;&lt;/div&gt;</description><link>http://blois.us/blog/2009/05/rooler.html</link><author>noreply@blogger.com (Pete Blois)</author><thr:total>7</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-16855281.post-6471094454147945628</guid><pubDate>Sat, 11 Apr 2009 23:52:00 +0000</pubDate><atom:updated>2009-04-11T17:04:39.432-07:00</atom:updated><title>DataTrigger, Bindings on non-FrameworkElements, TypeConverters, DataStateBehavior &amp; DataStateSwitchBehavior</title><description>&lt;p&gt;One of the behaviors that we've been interested in for quite a while is a DataTrigger which works nicely in Silverlight. If you aren't familiar with WPF, the DataTrigger is used to trigger state changes based on something in your view model rather than in the UI. Normal triggers are great for representing UI state such as 'when the mouse is over this element', but data triggers capture state of the view model such as 'when MyDataObject.UserState == UserState.Online'. It's great for triggering UI states based on changes in your data.&lt;/p&gt;  &lt;p&gt;There are a couple of features which aren't in Silverlight yet which made creating a Silverlight DataTrigger interesting, but with a bit of trickery I was able to get a passable version of one working.&lt;/p&gt;  &lt;p&gt;I was very interested in preserving the simple XAML syntax of WPF's DataTriggers-    &lt;br /&gt;&lt;/p&gt;  &lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;id&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataTrigger &lt;/span&gt;&lt;span style="color: red"&gt;Binding&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color: #a31515"&gt;Binding &lt;/span&gt;&lt;span style="color: red"&gt;Value&lt;/span&gt;&lt;span style="color: blue"&gt;}&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;Value&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;True&amp;quot;&amp;gt;&lt;br /&gt;    ...&lt;/span&gt;&lt;span style="color: blue"&gt;&lt;br /&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;id&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataTrigger&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;strong&gt;Bindings&lt;/strong&gt; &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;The first issue issue is that Silverlight doesn't currently allow databinding on types which are not FrameworkElements. Since none of the Behaviors system derives from FrameworkElement it's not as simple as exposing a DependencyProperty and setting a binding on it. &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;One trick to adding bindings on behaviors is to expose a property of type Binding on the behavior- you can set a property of type binding, but you can't actually bind to something. To then actually bind this property I declared a dummy attached dependency property and set the binding on the attached DP on the FrameworkElement to which the behavior is attached to. Just listen to when the attached DP changes and presto! you have a functional binding :). It's not the most obvious solution, but I think it's by far the most elegant and functional that I've found. It actually works out quite well and works very well within Blend too. &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;In the source code which is attached, most of the heavy work here is encapsulated in the BindingListener helper class, you can see it being used in the DataTrigger class.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;strong&gt;TypeConverters&lt;/strong&gt; &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;Once you have the binding working you also need to get the type of the value to match the type of property that is being bound to. The reason for this is that in XAML the type is just represented as a string and you don't know what type to convert it to until the binding is actually evaluated.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;To do this we use type converters when they're available, but for a number of types they are not and in this case we use a little hack which we also use in some places in Blend- serialize the property to XAML and pass that through Silverlight's parser :)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;In the source code which is attached, this is encapsulated in the ConverterHelper class.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;strong&gt;DataStateBehavior&lt;/strong&gt; &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;A DataTrigger in Silverlight is nice, but a really common use of it is combined with a GoToState action to control states. This works fine, but the syntax gets a bit cumbersome since you'd need triggers for both states- the true state and the false state. To make this a bit easier, I made a simple DataStateBehavior which encapsulates the trigger and two actions into a single behavior.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;In the scenario where I have a data source 'User' with a property 'IsOnline', I want to have two states in my UI- 'Online' and 'Offline'. When the user is online the 'Online' state should be active, when the user of offline the 'Offline' state should be active.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;To do this, it's just: &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;i&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;Interaction.Behaviors&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;br /&gt;    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;id&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataStateBehavior &lt;/span&gt;&lt;span style="color: red"&gt;Binding&lt;/span&gt;&lt;span style="color: blue"&gt;='{&lt;/span&gt;&lt;span style="color: #a31515"&gt;Binding &lt;/span&gt;&lt;span style="color: red"&gt;IsOnline&lt;/span&gt;&lt;span style="color: blue"&gt;}' &lt;/span&gt;&lt;span style="color: red"&gt;Value&lt;/span&gt;&lt;span style="color: blue"&gt;='True'  &lt;/span&gt;&lt;span style="color: red"&gt;TrueState&lt;/span&gt;&lt;span style="color: blue"&gt;='Online' &lt;/span&gt;&lt;span style="color: red"&gt;FalseState&lt;/span&gt;&lt;span style="color: blue"&gt;='Offline'/&amp;gt;&lt;br /&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;i&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;Interaction.Behaviors&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;strong&gt;DataStateSwitchBehavior&lt;/strong&gt; &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;Of course not all states are quite black and white, for the case of representing a cascade of states to represent something such as the values of an enum, I put together DataStateSwitchBehavior which allow an arbitrary number of values to check against and picks the first valid one. &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;An example of this is if you have the enum in your view model: &lt;br /&gt;  &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;public enum &lt;/span&gt;&lt;span style="color: #2b91af"&gt;UserSpeed &lt;/span&gt;{&lt;br /&gt;    Slow,&lt;br /&gt;    Medium,&lt;br /&gt;    Fast,&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Then you can set up states for each of these enum values using the DataStateSwitchBehavior which allows specifying a state for each of the enum values:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;id&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataStateSwitchBehavior &lt;/span&gt;&lt;span style="color: red"&gt;Binding&lt;/span&gt;&lt;span style="color: blue"&gt;='{&lt;/span&gt;&lt;span style="color: #a31515"&gt;Binding &lt;/span&gt;&lt;span style="color: red"&gt;Speed&lt;/span&gt;&lt;span style="color: blue"&gt;}'&amp;gt;&lt;br /&gt;    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;id&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataStateSwitchCase &lt;/span&gt;&lt;span style="color: red"&gt;Value&lt;/span&gt;&lt;span style="color: blue"&gt;='Slow' &lt;/span&gt;&lt;span style="color: red"&gt;State&lt;/span&gt;&lt;span style="color: blue"&gt;='SlowState'/&amp;gt;&lt;br /&gt;    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;id&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataStateSwitchCase &lt;/span&gt;&lt;span style="color: red"&gt;Value&lt;/span&gt;&lt;span style="color: blue"&gt;='Medium' &lt;/span&gt;&lt;span style="color: red"&gt;State&lt;/span&gt;&lt;span style="color: blue"&gt;='MediumState'/&amp;gt;&lt;br /&gt;    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;id&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataStateSwitchCase &lt;/span&gt;&lt;span style="color: red"&gt;Value&lt;/span&gt;&lt;span style="color: blue"&gt;='Fast' &lt;/span&gt;&lt;span style="color: red"&gt;State&lt;/span&gt;&lt;span style="color: blue"&gt;='FastState'/&amp;gt;&lt;br /&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;id&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataStateSwitchBehavior&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;strong&gt;Source&lt;/strong&gt; &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;Source code and a &lt;em&gt;real&lt;/em&gt; basic sample for all of this can be found &lt;a href="http://blois.us/Silverlight/Interactivity.Data.zip"&gt;here&lt;/a&gt;.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/16855281-6471094454147945628?l=blois.us%2Fblog%2Findex.html' alt='' /&gt;&lt;/div&gt;</description><link>http://blois.us/blog/2009/04/datatrigger-bindings-on-non.html</link><author>noreply@blogger.com (Pete Blois)</author><thr:total>11</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-16855281.post-95744704875490923</guid><pubDate>Tue, 24 Mar 2009 20:02:00 +0000</pubDate><atom:updated>2009-03-24T13:02:37.664-07:00</atom:updated><title>Behaviors</title><description>&lt;p&gt;At the MIX '09 conference last week I got the chance to show off some new things I've been working on with Expression Blend, notably behaviors. I'm quite excited about the power that the behaviors concept brings to the designer workflow and am thrilled to finally see the support for them solidifying.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;If you're curious about Behaviors, you can watch my brief talk at the MIX conference &lt;a href="http://videos.visitmix.com/MIX09/C27M"&gt;here&lt;/a&gt;. I just posted all of the behaviors that I used in this talk (and a bunch more) on the &lt;a href="http://gallery.expression.microsoft.com/MIXBehaviorPack"&gt;Expression Gallery&lt;/a&gt;, I'll be posting some more on certain aspects of these and I'll be following up with some of the other experimental ones that I've been playing with.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;If you're curious, you can also take a look at some of my old prototypes (have I really been working on these for 3 years?!?) &lt;a href="http://blois.us/blog/2006/02/python-this-was-my-first-stab-at-using.html"&gt;here&lt;/a&gt; and &lt;a href="http://blois.us/blog/2006/02/rob-relyea-from-avalon-team-has-cool.html"&gt;here&lt;/a&gt;. It's been a fun journey :)&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/16855281-95744704875490923?l=blois.us%2Fblog%2Findex.html' alt='' /&gt;&lt;/div&gt;</description><link>http://blois.us/blog/2009/03/behaviors.html</link><author>noreply@blogger.com (Pete Blois)</author><thr:total>8</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-16855281.post-2650901694058935407</guid><pubDate>Sun, 18 Jan 2009 21:51:00 +0000</pubDate><atom:updated>2009-01-18T13:51:16.372-08:00</atom:updated><title>Expression Design Export as a build task</title><description>&lt;p&gt;When I made the &lt;a href="http://blois.us/blog/2008/03/standard-minesweeper-wasnt-quite-enough.html"&gt;Minesweeper&lt;/a&gt; app a while back I had the original graphics in an Expression Design document and was doing all of the graphics work inside of Design. I got pretty tired of manually bringing the graphics from Design into Blend and decided to take a bit of a diversion to automate the process.&lt;/p&gt;  &lt;p&gt;I decided that the workflow that I really wanted to have was to have my Expression Design file in my project system and have a custom build task automatically convert it into XAML for the final project. Design has a great feature called &lt;a href="http://blogs.msdn.com/expression/archive/2008/03/02/test-draft.aspx"&gt;Slices&lt;/a&gt; which let you slice and dice the original artwork export those slices and save all of the export settings in the .design file.&lt;/p&gt;  &lt;p&gt;I figured out that with a build task and some trickery I could automatically extract all of the slices, generate some additional helper code and make the slices act just like custom controls in the project.&lt;/p&gt;  &lt;p&gt;The great part about the workflow is that all you need to do to modify any graphics in your WPF or Silverlight project is:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Make your changes to the .design file in Expression Design &lt;/li&gt;    &lt;li&gt;Save the .design file &lt;/li&gt;    &lt;li&gt;Build &amp;amp; Run from either Visual Studio or Expression Blend &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;In addition there are some other cool benefits:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;All of the generated controls automatically appear in intellisense in Visual Studio and in Blend's Asset Library &lt;/li&gt;    &lt;li&gt;Any images from the export (from images in the original project or rasterized effects) automatically get added to the compile project as well. &lt;/li&gt;    &lt;li&gt;All changes to the .design file automatically migrate into the project but there are no intermediate files anywhere in the project. The exported XAML and generated code are purely intermediate files which get cleaned up by a clean build. This means there's no getting out of sync between your .design and .xaml files. &lt;/li&gt;    &lt;li&gt;Exporting is only done when the .design file changes, so incremental build times remain zippy. &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;The steps to make this work in your own project (works for both WPF &amp;amp; Silverlight):&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;A licensed version of Expression Design 2 installed into your Program Files directory &lt;/li&gt;    &lt;li&gt;Add a DesignExport folder to your project and copy &lt;a href="http://blois.us/Tasks/DesignExport.targets"&gt;DesignExport.targets&lt;/a&gt; and &lt;a href="http://blois.us/Tasks/DesignExport.exe"&gt;DesignExport.exe&lt;/a&gt; to this folder. These are the build tasks for converting the .design file to xaml. &lt;/li&gt;    &lt;li&gt;Add your .design file to your project by using the Add Existing Item command in Visual Studio or Blend. &lt;/li&gt;    &lt;li&gt;Open the .csproj file for your project in Notepad and make the following changes:      &lt;ul&gt;       &lt;li&gt;Add a reference to the DesignExport.targets file which was copied over in step #2, usually I do this just below the import statement for the CSharp.targets file &lt;/li&gt;     &lt;/ul&gt;   &lt;/li&gt; &lt;/ul&gt;  &lt;blockquote&gt;   &lt;p&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Import Project=&amp;quot;DesignExport\DesignExport.targets&amp;quot; /&amp;gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;ul&gt;   &lt;ul&gt;     &lt;li&gt;Change the build action for your .design file from 'None' to 'Design' &lt;/li&gt;   &lt;/ul&gt; &lt;/ul&gt;  &lt;blockquote&gt;   &lt;p&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Design Include=&amp;quot;Minesweeper.design&amp;quot; /&amp;gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Please note that this relies on unsupported functionality within Expression Design, it can (and most likely will) break in any future release.&lt;/p&gt;  &lt;p&gt;Source code:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://blois.us/Tasks/SampleDesignProjectWPF.zip"&gt;A sample WPF application&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://blois.us/Tasks/SampleDesignProjectSL.zip"&gt;A sample Silverlight application&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;The original &lt;a href="http://blois.us/Tasks/MineSweeper.zip"&gt;Minesweeper project&lt;/a&gt; built using the DesignExport build tasks&lt;/li&gt;    &lt;li&gt;&lt;a href="http://blois.us/Tasks/Tasks.zip"&gt;Source code for the build tasks&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/16855281-2650901694058935407?l=blois.us%2Fblog%2Findex.html' alt='' /&gt;&lt;/div&gt;</description><link>http://blois.us/blog/2009/01/expression-design-export-as-build-task.html</link><author>noreply@blogger.com (Pete Blois)</author><thr:total>3</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-16855281.post-2992178147796011013</guid><pubDate>Mon, 10 Nov 2008 02:24:00 +0000</pubDate><atom:updated>2008-11-09T18:24:37.118-08:00</atom:updated><title>Silverlight Skinning</title><description>&lt;p&gt;I've never really done too much serious skinning, mostly I focus on apps and usually stick to skinning buttons, listboxes and scrollviewers and such. On Friday I ran across the latest results of the skinning competition over at &lt;a href="http://scalenine.com/"&gt;scalenine&lt;/a&gt; and got inspired to see how much progress I could make on a more complete skin in Silverlight. I don't have too much raw design skill so I decided to start with cloning an existing skin rather than going off on my own.&lt;/p&gt;  &lt;p&gt;I started off with the winning skin of the scalenine skinning competition and cloned a number of control skins including Checkbox, NumericUpDown, Calendar, and ListBox. All of these controls are from either the Silverlight runtime, SDK or &lt;a href="http://codeplex.com/silverlight"&gt;Toolbox&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;I decided to do all the theming in pure XAML- no code and no images. I used Expression Blend for the whole theming process and was actually pleasantly surprised by how smoothly the whole process went. I started out on TabControl which I had never really themed before, it took a few minutes for me to get into the swing of it but by the time I got through that and Button I was on a roll and quickly did Button, Checkbox, RadioButton and Calendar.&lt;/p&gt;  &lt;p&gt;Calendar was the one that surprised me the most- I'm not a big fan (at all) of Silverlight's default Calendar theme and really tore into it. The Calendar went extremely smooth with good visual editing of all of the parts and various calendar modes. I even redid the entire layout to make it resize correctly (my personal pet peeve :))&lt;/p&gt;  &lt;p&gt;Overall it took me ~5 hours to get started and crank out the first TabControl, Checkbox, RadioButton, ComboBox, Slider and Calendar controls, not too bad but I'm definitely getting faster now.&lt;/p&gt;  &lt;p&gt;The original Flex version can be found &lt;a href="http://www.scalenine.com/blog/source/challenge/Entry26/Entry26.html"&gt;here&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;The Silverlight &lt;a href="http://blois.us/Silverlight/Themes/#Undefined"&gt;version&lt;/a&gt;-&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;a href="http://blois.us/Silverlight/Themes/#Undefined"&gt;&lt;img height="162" alt="image" src="http://lh3.ggpht.com/_rFfWHybtNug/SRebX3VIeLI/AAAAAAAAACI/QIdl2BA_yxA/image%5B16%5D.png?imgmax=800" width="503" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Once I started getting the hang of the whole theming thing I decided to go off on my own a little bit more- still keeping with the original design but there were some parts of it that I wanted to simplify and make the theme a little more subtle.&lt;/p&gt;  &lt;p&gt;I decided to call this new theme 'Seattle' since it's such a plain gray theme and this weekend was a plain gray Seattle weekend.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;The '&lt;a href="http://blois.us/Silverlight/Themes/#Seattle"&gt;Seattle&lt;/a&gt;' theme&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blois.us/Silverlight/Themes/#Seattle"&gt;&lt;img height="158" alt="image" src="http://lh4.ggpht.com/_rFfWHybtNug/SRebY3HpGhI/AAAAAAAAACM/aIA8Y1Evidk/image%5B22%5D.png?imgmax=800" width="569" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;All of these are still under development (see the TreeView in Seattle- not quite working properly yet...), but my attention span is short and I'm off to write a game now. C'est la vie.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/16855281-2992178147796011013?l=blois.us%2Fblog%2Findex.html' alt='' /&gt;&lt;/div&gt;</description><link>http://blois.us/blog/2008/11/silverlight-skinning.html</link><author>noreply@blogger.com (Pete Blois)</author><thr:total>7</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-16855281.post-4048701676418123548</guid><pubDate>Sat, 01 Nov 2008 21:10:00 +0000</pubDate><atom:updated>2008-11-01T14:10:20.362-07:00</atom:updated><title>Silverlight Version</title><description>&lt;p&gt;One nifty utility that I've been using for a long time but never got around to publishing is a &lt;a href="http://blois.us/Silverlight/Version/"&gt;Silverlight version detector&lt;/a&gt; which will tell you the full version that you have installed on your machine. It really isn't that hard to do, but the nice thing about this one is that I've been using it on Silverlight versions way back to before 1.0 was released and the product was still called WPF/E.&lt;/p&gt;  &lt;p&gt;I primarily use this code for times when someone calls me up with a problem along the lines of 'something is running wacky on my machine'. It's much easier to just point them to a URL than to list the steps needed to find their version other ways.&lt;/p&gt;  &lt;p&gt;Please note that this code is &lt;strong&gt;*not*&lt;/strong&gt; the way that you're supposed to check whether the user has a version installed or not, that's what &lt;a href="http://msdn.microsoft.com/en-us/library/bb980107(VS.95).aspx"&gt;IsVersionSupported&lt;/a&gt; is for. The reason for this is that everyone seems to add bugs when trying to roll their own version detection code, so in the interest of making sure that your code continues to work through future updates, &lt;em&gt;please&lt;/em&gt; use IsVersionSupported.&lt;/p&gt;  &lt;p&gt;To use IsVersionSupported: Application.Current.Host.IsVersionSupported(&amp;quot;2.0.31005.0&amp;quot;);&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/16855281-4048701676418123548?l=blois.us%2Fblog%2Findex.html' alt='' /&gt;&lt;/div&gt;</description><link>http://blois.us/blog/2008/11/silverlight-version.html</link><author>noreply@blogger.com (Pete Blois)</author><thr:total>3</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-16855281.post-620888486206444557</guid><pubDate>Sat, 01 Nov 2008 19:20:00 +0000</pubDate><atom:updated>2008-11-01T13:56:18.698-07:00</atom:updated><title></title><description>Finally got around to updating a couple of Silverlight samples from older versions, only took me a few weeks :)&lt;br /&gt;&lt;br /&gt;Updated samples:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;&lt;a href="http://blois.us/Silverlight/Minesweeper/"&gt;Minesweeper&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://blois.us/VE"&gt;Virtual Earth&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://blois.us/Silverlight/Tarball/"&gt;Tarball&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://blois.us/Silverlight/Pathfinding/"&gt;A* Pathfinding&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/16855281-620888486206444557?l=blois.us%2Fblog%2Findex.html' alt='' /&gt;&lt;/div&gt;</description><link>http://blois.us/blog/2008/11/finally-got-around-to-updating-couple.html</link><author>noreply@blogger.com (Pete)</author><thr:total>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-16855281.post-7898356158503826625</guid><pubDate>Wed, 09 Apr 2008 03:33:00 +0000</pubDate><atom:updated>2008-04-08T20:37:27.747-07:00</atom:updated><title></title><description>&lt;p&gt;I've heard a number of questions around how to dynamically load content into Silverlight applications and  noticed that there isn't too much on the web about it, even though it's not too hard. There are a number of scenarios where it comes in quite handy.&lt;/p&gt;  &lt;p&gt;To show this, I made a fun preloader from a sample that Celso Gomes (a designer on the Blend team) put together. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blois.us/Silverlight/Walk"&gt;&lt;img alt="image" src="http://lh6.google.com/peteblois/R_w5HWJkk3I/AAAAAAAAABo/Oxx--BZN6sw/image%5B13%5D.png?imgmax=800" border="0" height="157" width="193" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;The application complete with the preloader (a sample of an image sequence control that I'm still working on) can be run &lt;a href="http://blois.us/Silverlight/Walk"&gt;here&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;And the source is &lt;a href="http://blois.us/Silverlight/Walk/BottleLoader.zip"&gt;here&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;Since the preloader is pretty fun to watch, it can be run on it's own from &lt;a href="http://blois.us/Silverlight/Bottle/"&gt;here&lt;/a&gt;.&lt;/p&gt;    &lt;p&gt;&lt;strong&gt;Splash Screens&lt;/strong&gt;- the only documented method of implementing Silverlight splash screens that I could find is through the '&lt;a href="http://www.silverlight.net/Quickstarts/BuildUi/SplashScreen.aspx"&gt;splashscreensource&lt;/a&gt;' parameter on the HTML object tag. That approach works but you'll be coding in Javascript and there is no way to make a seamless transition to the loaded content. (If your imagination about what can be done is failing you, I strongly recommend a stroll through &lt;a href="http://www.smashingmagazine.com/2008/03/13/showcase-of-creative-flash-preloaders/"&gt;Smashing Magazine's 'Showcase of Flash Preloaders'&lt;/a&gt;). &lt;/p&gt;  &lt;p&gt;By implementing a splash screen through dynamically loading the rest of the app and have much more control over how the content gets transitioned and what gets accounted for in the progress. For instance, the splash screen could download multiple files, or account for web service requests needed to perform app initialization.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Dynamic loading&lt;/strong&gt;- in order to minimize upfront download size many applications break themselves into multiple parts and either download parts that are needed later in the background or on demand. This is extremely common in large Flash applications.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Add-ins, Plug-ins &amp;amp; Ads&lt;/strong&gt;- it is strongly recommended that you &lt;strong&gt;*do not*&lt;/strong&gt; use this for loading third-party code such as add-ins and advertisements, there is no sandbox in this example and there is a high potential for exploitation by malicious third-parties.&lt;/p&gt;    &lt;p&gt;&lt;strong&gt;Setting up the Solution&lt;/strong&gt;&lt;img alt="image" src="http://lh6.google.com/peteblois/R_w5HWJkk4I/AAAAAAAAABw/cbxRdnBAum0/image%5B2%5D.png?imgmax=800" align="right" border="0" height="157" width="200" /&gt;&lt;/p&gt;  &lt;p&gt;The basic approach for dynamic loading is to load one Silverlight application ('XAP') into another Silverlight application. In Visual Studio, start with creating a standard Silverlight Application project and making sure that 'Add a new web to the solution for hosting the control' is selected (it's the default). This first Silverlight application can be the preloader.&lt;/p&gt;  &lt;p&gt;Next, add a second Silverlight application to the project and choose the 'Link this Silverlight control into an existing Web site'. Doing this will have the second application be automatically deployed into the web site as well.&lt;/p&gt;    &lt;p&gt;&lt;strong&gt;Downloading the second XAP &amp;amp; showing progress&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;In the startup for the first XAP the second XAP can be downloaded using any of the web APIs, normally I use &lt;a href="http://msdn2.microsoft.com/en-us/library/system.net.webclient%28VS.95%29.aspx"&gt;WebClient&lt;/a&gt; since it seems to be the simplest. You'll want to hook the DownloadProgressChanged event and use this to present progress to the user. In my sample app I abstracted this out into a Downloader control which exposes the URI for the app to be downloaded and has a templated UI to display the progress. Note that Silverlight does not currently have a progressbar control, so I threw one of those in there as well :).&lt;/p&gt;    &lt;p&gt;&lt;strong&gt;Instantiating an element from the second XAP&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;Once the download of the XAP has completed and we have a stream to it, it's time to load the assemblies then instantiate an instance of the class which is to be shown. To do this I use the following chunk of code which will parse the XAP, load all referenced assemblies into the runtime, then instantiate a type out of the main assembly: &lt;/p&gt;  &lt;pre style="background: rgb(128, 128, 136) none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; margin-left: 20px;"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;static&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;object&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; CreateFromXAP(&lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;Stream&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; package, &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; objectTypeName) {&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 128, 0);"&gt;// Extract the AppManifest from the XAP package&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; appManifestString = &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; &lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;StreamReader&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;(&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;Application&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;.GetResourceStream(&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; &lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;StreamResourceInfo&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;(package, &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;null&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;),&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; &lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;Uri&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);"&gt;"AppManifest.xaml"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;UriKind&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;.Relative)&lt;br /&gt;).Stream).ReadToEnd();&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 128, 0);"&gt;// Use the XamlReader to parse the AppManifest into managed objects&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;Deployment&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; deployment = (&lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;Deployment&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;)&lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;XamlReader&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;.Load(appManifestString);&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 128, 0);"&gt;// Keep track of the main assembly,&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 128, 0);"&gt;// we'll assume that the element to create is located here.&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;Assembly&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; mainAssembly = &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;null&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 128, 0);"&gt;// Walk all of the assemblies and load them into the CLR.&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 128, 0);"&gt;// This will load any dependent assemblies.&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;foreach&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; (&lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;AssemblyPart&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; assemblyPart &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;in&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; deployment.Parts) {&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; source = assemblyPart.Source;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;StreamResourceInfo&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; streamInfo = &lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;Application&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;.GetResourceStream(&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; &lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;StreamResourceInfo&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;(package, &lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);"&gt;"application/binary"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;),&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; &lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;Uri&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;(source, &lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;UriKind&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;.Relative));&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;Assembly&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; assembly = assemblyPart.Load(streamInfo.Stream);&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; (assembly.FullName.Split(&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);"&gt;','&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;)[0] == deployment.EntryPointAssembly)&lt;br /&gt;mainAssembly = assembly;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 128, 0);"&gt;// Create a new instance of the object from the main assembly&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;Type&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; objectType = mainAssembly.GetType(objectTypeName);&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; &lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;Activator&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;.CreateInstance(objectType);&lt;br /&gt;}&lt;/span&gt;&lt;/pre&gt;Just call this method with the full name of the class to be instantiated, cast the object to a FrameworkElement, then add it to the visual tree:&lt;br /&gt;&lt;pre style="background: rgb(128, 128, 136) none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; margin-left: 20px;"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;FrameworkElement&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; visual = CreateFromXAP(e.Result, &lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);"&gt;"MySampleApp.MainScene"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;) &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;as&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; &lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;FrameworkElement&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; (visual != &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;null&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;)&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;this&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;.LayoutRoot.Children.Add(visual);&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;&lt;strong&gt;Making a reusable preloader&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;In the project linked above I made the URI for the XAP to download and the path of the main scene parameters to the object tag in the HTML. This way I can reuse the preloader for multiple applications. The arguments are passed via the initParams parameter: &lt;/p&gt;&lt;pre style="background: rgb(128, 128, 136) none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; margin-left: 20px;"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);"&gt;param&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;name&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;='initParams'&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;value&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;='packageSource=ImageSequencerSample.xap,mainVisual=ImageSequencerSample.Page'&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;And extracted from the StartupEventArgs in the preloader application:&lt;br /&gt;&lt;pre style="background: rgb(128, 128, 136) none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; margin-left: 20px;"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;private&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; OnStartup(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;object&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; sender, &lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;StartupEventArgs&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; e) {&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; packageSource = e.InitParams[&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);"&gt;"packageSource"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;];&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; visualName = e.InitParams[&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);"&gt;"mainVisual"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;];&lt;/span&gt;&lt;/pre&gt;&lt;strong&gt;Minimizing the download size&lt;/strong&gt;&lt;br /&gt;Often there will be assemblies that are referenced by multiple parts of your application which you only want to download once (perhaps the most common example is System.Windows.Controls.dll). If you know that the assembly will already have been pulled down with an earlier XAP before the second one will need it then you can exclude it from being included in the second XAP by changing the 'Copy Local' property for the assembly reference in Visual Studio to be 'False' (right-click the assembly, select Properties, change Copy Local to False).&lt;br /&gt;&lt;p&gt;&lt;strong&gt;Warnings &amp;amp; Known Issues&lt;/strong&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Loaded content is not sandboxed. XAPs should not be downloaded from domains that are not fully trusted (as a general practice, only download from the domain that your code is running from). &lt;/li&gt;  &lt;li&gt;The Application object of the downloaded XAP will never be constructed and the Startup event will never be fired. Any code residing here should be moved into the constructor or Loaded event of the visual to be instantiated.&lt;/li&gt;  &lt;li&gt;Application-level resources of the loaded XAP will not be available. The above sample does not merge any app-level resources into the primary application's resources, so any app-level resources will not resolve. Hopefully in the not-too-distant future this will be possible.&lt;/li&gt;  &lt;li&gt;There may be some localization issues, but I have not investigated this aspect yet.&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Useful classes that I used in the sample above:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;a href="http://blois.us/Silverlight/Walk/Downloader.cs"&gt;Downloader.cs&lt;/a&gt;&lt;/li&gt;  &lt;li&gt;&lt;a href="http://blois.us/Silverlight/Walk/Progress.cs"&gt;Progress.cs&lt;/a&gt;&lt;/li&gt;  &lt;li&gt;&lt;a href="http://blois.us/Silverlight/Walk/generic.xaml"&gt;generic.xaml&lt;/a&gt; (default styles &amp;amp; templates for both)&lt;/li&gt;&lt;br /&gt;&lt;/ul&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/16855281-7898356158503826625?l=blois.us%2Fblog%2Findex.html' alt='' /&gt;&lt;/div&gt;</description><link>http://blois.us/blog/2008/04/preloaders-dynamic-loading.html</link><author>noreply@blogger.com (Pete Blois)</author><thr:total>6</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-16855281.post-5669746543634963181</guid><pubDate>Tue, 01 Apr 2008 02:03:00 +0000</pubDate><atom:updated>2008-03-31T19:03:02.277-07:00</atom:updated><title>Fun</title><description>&lt;p&gt;That last post was a bit too developer centric, time to balance it out with something more fun. I recycled an old WPF project and converted it over to Silverlight. Lots of fun to play with though it doesn't appear to run all that well on Firefox or Safari (if your browser appears to hang just wait a few seconds).&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blois.us/Silverlight/Tarball/"&gt;&lt;img height="480" alt="image" src="http://lh3.google.com/peteblois/R_GX1WJkk2I/AAAAAAAAABg/qBCZrzGd0TU/image%5B11%5D.png?imgmax=800" width="637" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;The source can be found &lt;a href="http://blois.us/Silverlight/Tarball/Tarball.zip"&gt;here&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;The app can be run &lt;a href="http://blois.us/Silverlight/Tarball/"&gt;here&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;Enjoy!&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/16855281-5669746543634963181?l=blois.us%2Fblog%2Findex.html' alt='' /&gt;&lt;/div&gt;</description><link>http://blois.us/blog/2008/03/fun.html</link><author>noreply@blogger.com (Pete Blois)</author><thr:total>3</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-16855281.post-6281920238296564938</guid><pubDate>Tue, 01 Apr 2008 01:39:00 +0000</pubDate><atom:updated>2008-03-31T18:39:07.462-07:00</atom:updated><title>A* Pathfinding</title><description>&lt;p&gt;In the process of making a Silverlight Tower Defense app a while back I made a simple sample application of the A* pathfinding algorithm that could be useful for anyone else&amp;#160; working on Silverlight games (or games in general I suppose). &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blois.us/Silverlight/Pathfinding/"&gt;&lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="157" alt="image" src="http://lh5.google.com/peteblois/R_GSO2Jkk1I/AAAAAAAAABU/6YQCxSVW-EI/image%5B13%5D.png?imgmax=800" width="240" align="right" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;I won't do an entire explanation of the A* algorithm, there are tons of great resources out there already (&lt;a title="http://www.google.com/search?q=A*+path+finding" href="http://www.google.com/search?q=A*+path+finding"&gt;http://www.google.com/search?q=A*+path+finding&lt;/a&gt;). The one I referenced most was probably &lt;a title="http://www.policyalmanac.org/games/aStarTutorial.htm" href="http://www.policyalmanac.org/games/aStarTutorial.htm"&gt;http://www.policyalmanac.org/games/aStarTutorial.htm&lt;/a&gt;. This sample contains a bunch of debugging info along the lines of what you'll see at the policyalmanac site, just to make it a bit easier to customize.&lt;/p&gt;  &lt;p&gt;The app contains the logic for a couple of different pathfinding routines, notably:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Standard: run-of-the-mill pathfinding&lt;/li&gt;    &lt;li&gt;Drunken: I found that my tower defense critters were too predictable, so I added a bit of randomness in to the standard pathfinding&lt;/li&gt;    &lt;li&gt;Roundabout: just having fun, critter takes a very long route. Not really useful&lt;/li&gt;    &lt;li&gt;Worst: critter tries to find the absolute longest path available without going over the same tile twice.&lt;/li&gt;    &lt;li&gt;Speed Bump: critter tries to avoid certain tiles (can weigh the expense of going through a tile). I used this for little bomber-men in my tower defense game- they try to just go through the map but if there's a good shortcut by going through some towers then they'll try to blast a hole and go through :)&lt;/li&gt;    &lt;li&gt;Escape: inspired by &lt;a href="http://www.gamedesign.jp/flash/chatnoir/chatnoir.html"&gt;Chat Noir&lt;/a&gt; (a great game on it's own), it's actually Dijkstra's algorithm where the critter just tries to get to the edge.&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;In case you're wondering, the tower defense app is working, but it's no fun to play at all. Balancing the game turns out to be much more difficult than I expected and everytime I sit down to make some progress I just end up creating new weapons like flamethrowers and nukes or Raiden-style plasma beams. &lt;/p&gt;  &lt;p&gt;The sample can be run &lt;a href="http://blois.us/Silverlight/Pathfinding/"&gt;here&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;The source is &lt;a href="http://blois.us/Silverlight/Pathfinding/PathFinding.zip"&gt;here&lt;/a&gt;.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/16855281-6281920238296564938?l=blois.us%2Fblog%2Findex.html' alt='' /&gt;&lt;/div&gt;</description><link>http://blois.us/blog/2008/03/pathfinding.html</link><author>noreply@blogger.com (Pete Blois)</author><thr:total>3</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-16855281.post-3028358070098689991</guid><pubDate>Mon, 31 Mar 2008 16:40:00 +0000</pubDate><atom:updated>2008-03-31T18:27:10.342-07:00</atom:updated><title></title><description>Quick tip-&lt;br /&gt;The background color of the default Silverlight preloader can be changed by changing the 'background' parameter in the object tag in HTML. Making the preloader and HTML backgrounds match your Silverlight app's background is an easy way to make the loading sequence just that much nicer.&lt;br /&gt;&lt;pre style='background: #505050; margin-left: 20px;'&gt;&lt;span style='color:#000000'&gt;&lt;/span&gt;&lt;span style='color:#a31515'&gt;html&lt;/span&gt;&lt;span style='color:#000000'&gt;, &lt;/span&gt;&lt;span style='color:#a31515'&gt;body&lt;/span&gt;&lt;span style='color:#000000'&gt; {&lt;br /&gt;    &lt;/span&gt;&lt;span style='color:#ff0000'&gt;height&lt;/span&gt;&lt;span style='color:#000000'&gt;: &lt;/span&gt;&lt;span style='color:#0000ff'&gt;100%&lt;/span&gt;&lt;span style='color:#000000'&gt;;&lt;br /&gt;    &lt;/span&gt;&lt;span style='color:#ff0000'&gt;overflow&lt;/span&gt;&lt;span style='color:#000000'&gt;: &lt;/span&gt;&lt;span style='color:#0000ff'&gt;auto&lt;/span&gt;&lt;span style='color:#000000'&gt;;&lt;br /&gt;    &lt;/span&gt;&lt;span style='color:#ff0000'&gt;background&lt;/span&gt;&lt;span style='color:#000000'&gt;: &lt;/span&gt;&lt;span style='color:#0000ff'&gt;#4F818A&lt;/span&gt;&lt;span style='color:#000000'&gt;;&lt;br /&gt;}&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;pre style='background: #505050; margin-left: 20px;'&gt;&lt;span style='color:#000000'&gt;&lt;/span&gt;&lt;span style='color:#0000ff'&gt;&amp;lt;&lt;/span&gt;&lt;span style='color:#a31515'&gt;object&lt;/span&gt;&lt;span style='color:#000000'&gt; &lt;/span&gt;&lt;span style='color:#ff0000'&gt;...&lt;/span&gt;&lt;span style='color:#000000'&gt; &lt;/span&gt;&lt;span style='color:#0000ff'&gt;&amp;gt;&lt;br /&gt;&lt;/span&gt;&lt;span style='color:#000000'&gt;&lt;/span&gt;&lt;span style='color:#0000ff'&gt;&amp;lt;&lt;/span&gt;&lt;span style='color:#a31515'&gt;param&lt;/span&gt;&lt;span style='color:#000000'&gt; &lt;/span&gt;&lt;span style='color:#ff0000'&gt;name&lt;/span&gt;&lt;span style='color:#0000ff'&gt;="background"&lt;/span&gt;&lt;span style='color:#000000'&gt; &lt;/span&gt;&lt;span style='color:#ff0000'&gt;value&lt;/span&gt;&lt;span style='color:#0000ff'&gt;="#7F2727"&lt;/span&gt;&lt;span style='color:#000000'&gt; &lt;/span&gt;&lt;span style='color:#0000ff'&gt;/&amp;gt;&lt;br /&gt;&amp;lt;/&lt;/span&gt;&lt;span style='color:#a31515'&gt;object&lt;/span&gt;&lt;span style='color:#0000ff'&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/16855281-3028358070098689991?l=blois.us%2Fblog%2Findex.html' alt='' /&gt;&lt;/div&gt;</description><link>http://blois.us/blog/2008/03/quick-tip-background-color-of-default.html</link><author>noreply@blogger.com (Pete Blois)</author><thr:total>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-16855281.post-7974888916078201231</guid><pubDate>Thu, 27 Mar 2008 19:34:00 +0000</pubDate><atom:updated>2008-03-27T12:38:36.193-07:00</atom:updated><title></title><description>Matt over at Signal vs Noise had a quote that struck a note with me-&lt;br /&gt;&lt;blockquote&gt;&lt;/blockquote&gt;&lt;blockquote&gt;All web apps are trying to suck. They are trying to be bloated. They are trying  to be unstructured. They are trying to be confusing.&lt;br /&gt;&lt;p&gt;You are the stopgap. You are the one who stands between order and chaos. You  are the sniper who must pick off every distraction, unneeded feature, and extra  word that doesn’t &lt;em&gt;absolutely&lt;/em&gt; have to be there.&lt;/p&gt;&lt;br /&gt;&lt;/blockquote&gt;&lt;a href="http://www.37signals.com/svn/posts/934-ira-glass-entropy-and-software-development"&gt;http://www.37signals.com/svn/posts/934-ira-glass-entropy-and-software-development&lt;/a&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;/blockquote&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/16855281-7974888916078201231?l=blois.us%2Fblog%2Findex.html' alt='' /&gt;&lt;/div&gt;</description><link>http://blois.us/blog/2008/03/matt-over-at-signal-vs-noise-had-quote.html</link><author>noreply@blogger.com (Pete Blois)</author><thr:total>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-16855281.post-7170111279300707739</guid><pubDate>Wed, 19 Mar 2008 02:06:00 +0000</pubDate><atom:updated>2008-03-31T18:31:46.168-07:00</atom:updated><title></title><description>Last week I made 2 minesweeper games, which were fun and all, but the overwhelming response from my friends was "wtf! can't flag tiles with right click!". It took all the fun out of the game.&lt;br /&gt;&lt;br /&gt;This weekend I noticed that Google Docs makes nice use of right click gestures and my mission began- enable flagging tiles via right-click in Minesweeper!&lt;br /&gt;&lt;br /&gt;Easier said than done, but with the help of some previous investigators in &lt;a href="http://www.uza.lt/blog/2007/08/solved-right-click-in-as3"&gt;Flash &lt;/a&gt;and &lt;a href="http://www.rtlogicsystems.com/Home/tabid/224/EntryID/23/Default.aspx"&gt;Silverlight&lt;/a&gt;, I was able to hack out a passable solution that works on IE and Firefox (OS X &amp;amp; Windows). Alas, Safari has beaten me once again.&lt;br /&gt;&lt;br /&gt;Once I was able to get the right-click event, I needed to figure out which element the mouse clicked on. In Silverlight 2 there's now a HitTest API which made this easy- just hit test with the mouse position and get the first element:&lt;pre class="csharpcode"&gt;UIElement element &lt;span class="kwrd"&gt;in&lt;/span&gt; Application.Current.RootVisual&lt;br /&gt;.HitTest(&lt;span class="kwrd"&gt;new&lt;/span&gt; Point(e.OffsetX, e.OffsetY))&lt;/pre&gt;The next step was to figure out a good strategy for propagating the event. In WPF the &lt;a href="http://msdn2.microsoft.com/en-us/library/system.windows.routedevent.aspx"&gt;RoutedEvent &lt;/a&gt;class fits the bill perfectly- it's allows propagating any event through the visual tree. Unfortunately even though RoutedEvents are in Silverlight, they are not extensible and I couldn't add my own. Bummer.&lt;br /&gt;&lt;br /&gt;I ended up implementing my own variant of RoutedEvents, BubblingEvents (for lack of a better name) and made a super minimal version of them for Silverlight. The code is similar enough to RoutedEvents to be able to start quickly.&lt;br /&gt;&lt;br /&gt;To declare a new BubblingEvent:&lt;br /&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;readonly&lt;/span&gt; BubblingEvent&amp;lt;ContextMenuEventArgs&amp;gt; ContextMenuEvent&lt;br /&gt;= &lt;span class="kwrd"&gt;new&lt;/span&gt; BubblingEvent&amp;lt;ContextMenuEventArgs&amp;gt;(&lt;span class="str"&gt;"ContextMenu"&lt;/span&gt;, RoutingStrategy.Bubble);&lt;/pre&gt;This declares a new event with event args of type ContextMenuEvent which will bubble up the visual tree.&lt;br /&gt;&lt;br /&gt;Handling the event is very similar to WPF where the handler is set up for the type:&lt;br /&gt;&lt;pre class="csharpcode"&gt;ContextMenuGenerator.ContextMenuEvent.&lt;br /&gt;  RegisterClassHandler(&lt;span class="kwrd"&gt;typeof&lt;/span&gt;(Page),&lt;br /&gt;  Page.HandleContextMenuEvent, &lt;span class="kwrd"&gt;false&lt;/span&gt;);&lt;br /&gt;&lt;br /&gt;&lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; HandleContextMenuEvent(&lt;span class="kwrd"&gt;object&lt;/span&gt; sender, ContextMenuEventArgs e) {&lt;br /&gt;  ((Page)sender).OnContextMenu(e);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;span class="kwrd"&gt;protected&lt;/span&gt; &lt;span class="kwrd"&gt;virtual&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; OnContextMenu(ContextMenuEventArgs e) {&lt;br /&gt;  e.Handled = true;&lt;br /&gt;}&lt;/pre&gt;Then it's just a matter of flagging the tiles from the event. The event propagation automatically stops when the handled flag is set to true, unless you register for all events- just like WPF's as well.&lt;br /&gt;&lt;br /&gt;Once I got this part going then I realized that my mouse wheel handling code could really benefit from this mechanism as well; it was a very easy modification to convert it to use BubblingEvents.&lt;br /&gt;&lt;br /&gt;The cool part is that since the event handling registration is done based on types, I could easily and efficiently create a helper that would register for all MouseWheel events on every ScrollViewer in an entire application:&lt;br /&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; ScrollableScrollViewer {&lt;br /&gt;   &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;bool&lt;/span&gt; initialized = &lt;span class="kwrd"&gt;false&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;   &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Initialize() {&lt;br /&gt;       &lt;span class="kwrd"&gt;if&lt;/span&gt; (!ScrollableScrollViewer.initialized) {&lt;br /&gt;           MouseWheelGenerator.MouseWheelEvent.&lt;br /&gt;RegisterClassHandler(&lt;span class="kwrd"&gt;typeof&lt;/span&gt;(ScrollViewer),&lt;br /&gt;ScrollableScrollViewer.HandleMouseWheel, &lt;span class="kwrd"&gt;false&lt;/span&gt;);&lt;br /&gt;           ScrollableScrollViewer.initialized = &lt;span class="kwrd"&gt;true&lt;/span&gt;;&lt;br /&gt;       }&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;   &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; HandleMouseWheel&lt;br /&gt;       (&lt;span class="kwrd"&gt;object&lt;/span&gt; sender, MouseWheelEventArgs e) {&lt;br /&gt;       ScrollViewer sv = (ScrollViewer)sender;&lt;br /&gt;&lt;br /&gt;       &lt;span class="kwrd"&gt;double&lt;/span&gt; verticalOffset = sv.VerticalOffset;&lt;br /&gt;       &lt;span class="kwrd"&gt;if&lt;/span&gt; (e.Delta &amp;gt; 0 &amp;amp;&amp;amp; verticalOffset &amp;gt; 0) {&lt;br /&gt;           sv.ScrollToVerticalOffset(verticalOffset - e.Delta * 50);&lt;br /&gt;           e.Handled = &lt;span class="kwrd"&gt;true&lt;/span&gt;;&lt;br /&gt;       }&lt;br /&gt;       &lt;span class="kwrd"&gt;else&lt;/span&gt; &lt;span class="kwrd"&gt;if&lt;/span&gt; (e.Delta &amp;lt; 0 &amp;amp;&amp;amp; verticalOffset &amp;lt; sv.ScrollableHeight) {&lt;br /&gt;           sv.ScrollToVerticalOffset(verticalOffset - e.Delta * 50);&lt;br /&gt;           e.Handled = &lt;span class="kwrd"&gt;true&lt;/span&gt;;&lt;br /&gt;       }&lt;br /&gt;   }&lt;br /&gt;}&lt;/pre&gt;One call to ScrollableScrollViewer.Initialize() and scrollbars now work 'as expected' :)&lt;br /&gt;&lt;br /&gt;Code files used here:&lt;br /&gt;    &lt;a href="http://blois.us/Silverlight/BubblingEvent.cs"&gt;BubblingEvent.cs&lt;/a&gt;- implementation of extensible routed events in Silverlight.&lt;br /&gt;    &lt;a href="http://blois.us/Silverlight/ContextMenuGenerator.cs"&gt;ContextMenuGenerator.cs&lt;/a&gt;- provides bubbling ContextMenu (right-click) events in Silverlight.&lt;br /&gt;    &lt;a href="http://blois.us/Silverlight/MouseWheelGenerator.cs"&gt;MouseWheelGenerator.cs&lt;/a&gt;- provides bubbling MouseWheel events in Silverlight.&lt;br /&gt;    &lt;a href="http://blois.us/Silverlight/ScrollableScrollViewer.cs"&gt;ScrollableScrollViewer.cs&lt;/a&gt;- makes all scrollviewers in an application scroll with the mouse wheel.&lt;br /&gt;&lt;br /&gt;Samples:&lt;br /&gt;    Right-click enabled &lt;a href="http://blois.us/Silverlight/HexMinesweeper"&gt;Minesweeper.&lt;/a&gt;&lt;br /&gt;    &lt;a href="http://blois.us/Silverlight/RightClickTest"&gt;Test app&lt;/a&gt; for scrolling scrollbars and right click. &lt;a href="http://blois.us/Silverlight/RightClickTest/RightClickTest.zip"&gt;Source&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/16855281-7170111279300707739?l=blois.us%2Fblog%2Findex.html' alt='' /&gt;&lt;/div&gt;</description><link>http://blois.us/blog/2008/03/last-week-i-made-2-minesweeper-games.html</link><author>noreply@blogger.com (Pete Blois)</author><thr:total>6</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-16855281.post-4082405628083346835</guid><pubDate>Fri, 14 Mar 2008 02:39:00 +0000</pubDate><atom:updated>2008-03-13T19:45:12.714-07:00</atom:updated><title></title><description>Standard minesweeper wasn't quite enough, hex minesweeper just had to be done...&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://blois.us/Silverlight/HexMinesweeper"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://blois.us/blog/uploaded_images/Hex-755289.png" alt="" border="0" /&gt;&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/16855281-4082405628083346835?l=blois.us%2Fblog%2Findex.html' alt='' /&gt;&lt;/div&gt;</description><link>http://blois.us/blog/2008/03/standard-minesweeper-wasnt-quite-enough.html</link><author>noreply@blogger.com (pete blois)</author><thr:total>3</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-16855281.post-9172511447435426037</guid><pubDate>Wed, 12 Mar 2008 00:55:00 +0000</pubDate><atom:updated>2008-03-11T18:56:40.965-07:00</atom:updated><title></title><description>&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://blois.us/Silverlight/Minesweeper/"&gt;&lt;img style="margin: 0pt 0pt 10px 10px; float: right; cursor: pointer;" src="http://blois.us/blog/uploaded_images/Minesweeper-754944.png" alt="" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;I had an old Minesweeper app that I did with Aaron Jasinski in WPF a while back that I decided to convert to Silverlight last night, it was actually a fun little project.&lt;br /&gt;&lt;br /&gt;Go ahead and &lt;a href="http://blois.us/Silverlight/Minesweeper/"&gt;play it!&lt;/a&gt; &lt;span style="font-size:78%;"&gt;(only tricky thing is to use ctrl-click to mark a tile, no right clicks!)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;I had to do something to get my spirits up- I was bummed because I had a pretty slick Twitter app that I was all ready to send out that got broken the day before when Twitter disabled their crossdomain.xml file. Bastards!&lt;br /&gt;&lt;br /&gt;Ahh well, the Twitter outage sounds temporary, though it will have a lame authentication mechanism when it comes back. They're removing support for HTTP basic authentication because of a security alert on Saturday. I'm not sure what new security alerts had to be found, the stuff is sending the username/password over the wire in plaintext for crissakes! Ah well, enough crying about that.&lt;br /&gt;&lt;br /&gt;Minesweeper was easy enough to throw together, took about 2 hours while reusing the core code that I had from the WPF version. I had a good time because I was trying out some prototyping that I'm working on for some Expression Design to Blend &amp;amp; VS integration, which is also preventing me from sending out the source code for now (sorry!).&lt;br /&gt;&lt;br /&gt;You can download the Expression Design file for the project from &lt;a href="http://blois.us/Silverlight/Minesweeper/minesweeper.design"&gt;here&lt;/a&gt; though.&lt;br /&gt;&lt;br /&gt;I did have to recreate a Viewbox control- I'm hoping something like this makes it into the runtime but it wasn't too bad to make from scratch. Feel free to grab my code from &lt;a href="http://blois.us/Silverlight/Minesweeper/Viewbox.cs"&gt;here&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;Enjoy!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/16855281-9172511447435426037?l=blois.us%2Fblog%2Findex.html' alt='' /&gt;&lt;/div&gt;</description><link>http://blois.us/blog/2008/03/i-had-old-minesweeper-app-that-i-did.html</link><author>noreply@blogger.com (pete blois)</author><thr:total>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-16855281.post-5892656333815862189</guid><pubDate>Fri, 07 Mar 2008 20:23:00 +0000</pubDate><atom:updated>2008-03-07T12:27:13.105-08:00</atom:updated><title></title><description>Andy Beaulieu has really fun example of a Silverlight physics engine: &lt;a href="http://www.andybeaulieu.com/silverlight/2.0/polygondemo/testpage.html"&gt;http://www.andybeaulieu.com/silverlight/2.0/polygondemo/testpage.html&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;I really like how you draw out the elements to be operated on- no pre-canned blocks and other shapes! Lots of fun to make a big stack of objects then draw a big object in the middle- makes the entire stack explode :)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/16855281-5892656333815862189?l=blois.us%2Fblog%2Findex.html' alt='' /&gt;&lt;/div&gt;</description><link>http://blois.us/blog/2008/03/andy-beaulieu-has-really-fun-example-of.html</link><author>noreply@blogger.com (pete blois)</author><thr:total>1</thr:total></item></channel></rss>