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

<channel>
	<title>Jeff Wilcox &#187; Web</title>
	<atom:link href="http://www.jeff.wilcox.name/topics/web/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.jeff.wilcox.name</link>
	<description>Silverlight, rich client apps and web development</description>
	<lastBuildDate>Mon, 26 Jul 2010 17:56:55 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>&#8217;09 blog housekeeping &amp; thanks</title>
		<link>http://www.jeff.wilcox.name/2009/01/housekeeping-2009/</link>
		<comments>http://www.jeff.wilcox.name/2009/01/housekeeping-2009/#comments</comments>
		<pubDate>Sat, 03 Jan 2009 22:17:07 +0000</pubDate>
		<dc:creator>Jeff Wilcox</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[Web Servers]]></category>

		<guid isPermaLink="false">http://www.jeff.wilcox.name/2009/01/housekeeping-2009/</guid>
		<description><![CDATA[I hope that you&#8217;ve had an excellent new year; I&#8217;m pretty excited for what is in store for the next twelve months. Here&#8217;s some general notes &#38; blog information. Last year we took Silverlight from a simple plugin &#38; a brand name to a complete platform powered by .NET. With a tough economy, the pressure [...]]]></description>
			<content:encoded><![CDATA[<p>I hope that you&#8217;ve had an excellent new year; I&#8217;m pretty excited for what is in store for the next twelve months. Here&#8217;s some general notes &amp; blog information.</p>
<p>Last year we took Silverlight from a simple plugin &amp; a brand name to a complete platform powered by .NET.</p>
<p>With a tough economy, the pressure is on to actually deliver value and make sound investments, and the open source work that we&#8217;re doing at Microsoft on the <a href="http://www.codeplex.com/Silverlight">Silverlight Toolkit</a> definitely is a good value.</p>
<p>I&#8217;d also like to take a minute to thank the thousands of subscribers and site visitors. I always <a href="http://www.jeff.wilcox.name/about/contact/">welcome your feedback</a> and post suggestions.</p>
<h3>Jeff Wilcox&#8217;s RSS feeds</h3>
<p>Last year I delivered a large set of tutorials, Silverlight guides, and overall I&#8217;m very happy with the content. I&#8217;d like to take this chance to present three key RSS feeds for my blog, in case you&#8217;re doing some RSS reader housekeeping.</p>
<p><strong>Recent posts RSS: <img src="http://www.jeff.wilcox.name/icons/feed-icon-14x14.png" /> <a title="http://feeds.feedburner.com/JeffWilcox/" href="http://feeds.feedburner.com/JeffWilcox/">http://feeds.feedburner.com/JeffWilcox/</a>&#160;</strong></p>
<p><strong>Silverlight-only RSS: <img src="http://www.jeff.wilcox.name/icons/feed-icon-14x14.png" />&#160;<a title="http://feeds.feedburner.com/JeffWilcox/Silverlight/" href="http://feeds.feedburner.com/JeffWilcox/Silverlight/">http://feeds.feedburner.com/JeffWilcox/Silverlight/</a>&#160;</strong>    <br />This is the RSS feed that is syndicated on the <a href="http://www.silverlight.net/">http://www.silverlight.net/</a> homepage and <a href="http://silverlight.net/blogs/microsoft/rss.aspx">this Microsoft feed</a>. This is a good subscription choice if you&#8217;re less interested in other technologies and topics (Apache, PHP, Seattle weather, you name it)</p>
<p><strong>Recent comments RSS: <img src="http://www.jeff.wilcox.name/icons/feed-icon-14x14.png" />&#160;<a title="http://www.jeff.wilcox.name/comments/feed/" href="http://www.jeff.wilcox.name/comments/feed/">http://www.jeff.wilcox.name/comments/feed/</a>&#160;</strong></p>
<p><strong>Silverlight Toolkit team RSS: <img src="http://www.jeff.wilcox.name/icons/feed-icon-14x14.png" />&#160;<a title="http://feeds.feedburner.com/SilverlightToolkitTeamMembersBlogFeeds" href="http://feeds.feedburner.com/SilverlightToolkitTeamMembersBlogFeeds/">http://feeds.feedburner.com/SilverlightToolkitTeamMembersBlogFeeds/</a>&#160; </strong></p>
<h3>Site updates</h3>
<p>If you visit my web site, <a href="http://www.jeff.wilcox.name/">http://www.jeff.wilcox.name/</a>, or click through to individual blog posts, you&#8217;ll notice that I spent some time in the month of December to refresh the visual design, styles, and functionality of my site and blog.</p>
<p>The pages have a true #fff white background now, archive pages and other pages list more topics, have excerpts, and the blog remains advertising-free.</p>
</p>
<h3>Best way to deliver code snippets in blog postings?</h3>
<p>Back in May, <a href="http://www.jeff.wilcox.name/2008/05/blog-syntax/">I announced</a> that I was moving from screen captured code to JavaScript-enhanced post &lt;pre /&gt; content.</p>
<p>I&#8217;d appreciate it if you could share any comments on the format, I&#8217;m open to spending some time changing the process again. The experience today is a simple &lt;pre /&gt; text block for RSS readers, and when viewing the actual post web page, JavaScript powers value add (syntax highlighting, additional options, clipboard features).</p>
<h3>Disclaimer reminder</h3>
<p>Just a reminder to those that subscribe to these feed: as reproduced on all blog and site pages: <em>&quot;The content on this site represents my own personal opinions and thoughts at the time of posting, and does not reflect those of my employer in any way.&quot;</em></p>
<h3>Powered by&#8230;</h3>
<p> Finally, thanks go to <a href="http://wordpress.org/">WordPress</a>, the best web publishing platform out there. The recent upgrade to WordPress 2.7 went great, and the product just continues to improve.
<p>This blog is powered by:</p>
<ul>
<li><a href="http://www.wordpress.org/">WordPress 2.7</a></li>
<li>LAMP stack; <a href="http://php.net/">PHP 5</a>, <a href="http://www.mysql.com/">MySql</a>, dedicated Linux server hosting by <a href="http://www.serverbeach.com/">ServerBeach</a></li>
</ul>
<p>And produced using:</p>
<ul>
<li>Microsoft <a href="http://www.windowslive.com/Desktop/Writer">Windows Live Writer</a></li>
<li><a href="http://www.adobe.com/products/creativesuite/web/?promoid=121DJGTB_P_US_FP2_WP_CS4_MN&amp;tt=P_US_FP2_WP_CS4_MN">Adobe Creative Suite 4 Web Premium</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.jeff.wilcox.name/2009/01/housekeeping-2009/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Silverlight 2 Unleashed by Laurent Bugnion</title>
		<link>http://www.jeff.wilcox.name/2008/11/silverlight-2-unleashed-book/</link>
		<comments>http://www.jeff.wilcox.name/2008/11/silverlight-2-unleashed-book/#comments</comments>
		<pubDate>Fri, 07 Nov 2008 07:34:48 +0000</pubDate>
		<dc:creator>Jeff Wilcox</dc:creator>
				<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://www.jeff.wilcox.name/2008/11/06/silverlight-2-unleashed-book/</guid>
		<description><![CDATA[If you&#8217;re looking for a great overview of all things Silverlight 2, Laurent Bugnion&#8217;s Silverlight 2 Unleashed book is a great introductory book for web developers, designers, and folks new to the Microsoft web/client platform. Amazon delivered my copy in the pouring rain today, so I immediately took it up to my neighborhood coffee shop. [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.amazon.com/gp/product/0672330148?ie=UTF8&amp;tag=jwilcoxblog-20&amp;linkCode=as2&amp;camp=1789&amp;creative=390957&amp;creativeASIN=0672330148"><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="160" alt="sl2unleashed" src="http://www.jeff.wilcox.name/wp-content/uploads/2008/11/sl2unleashed.jpg" width="123" align="right" border="0" /></a> If you&#8217;re looking for a great overview of all things Silverlight 2, Laurent Bugnion&#8217;s <a href="http://www.amazon.com/gp/product/0672330148?ie=UTF8&amp;tag=jwilcoxblog-20&amp;linkCode=as2&amp;camp=1789&amp;creative=390957&amp;creativeASIN=0672330148">Silverlight 2 Unleashed</a> book is a great introductory book for web developers, designers, and folks new to the Microsoft web/client platform. Amazon delivered my copy in the pouring rain today, so I immediately took it up to my neighborhood coffee shop.</p>
<p><em>Since my blog&#8217;s filled with some fairly technical resources, I should point out that the book is not the right reference for anyone that has an extensive knowledge of WPF or that has been an early adopter of Silverlight 2.</em></p>
<p>Laurent&#8217;s book instead targets everyone else: the millions of web developers that are new to .NET, looking to expand their working knowledge, or just wanting to learn something about the new exciting Silverlight platform. Much like Adam Nathan&#8217;s <a href="http://www.amazon.com/gp/product/0672328917?ie=UTF8&amp;tag=jefwilsblo-20&amp;linkCode=as2&amp;camp=1789&amp;creative=390957&amp;creativeASIN=0672328917">WPF Unleashed</a> book, the full color examples and screen captures really add life and will help you connect to the tools and examples.</p>
<p>The book is organized into many vignettes almost, each covering a concept, walkthrough of a task, and showing screen captures, code, and helpful tips along the way. As a former client- server- Flash- everything- guy, I&#8217;m confident in saying that this is a great overview of what you&#8217;d expect if you were wanting to get all the key, above-the-fold info on this new platform.</p>
<p>In Chapter 1, the book begins covering where Silverlight has come from, other plug-ins, and demos. Chapter 2 moves on to XAML, and then the book moves on to basic transforms, colors, paths, JavaScript basics, and finally, chapter 9, an intro to .NET.</p>
<p>The middle of the book moves to C# programming, isolated storage, and animations. There&#8217;s then coverage on Expression, videos, and events. It then progresses to details on the rich Microsoft presentation platform basics, and will be familiar to WPF developers. This includes layout basics, the built-in controls, simple interaction and interoperability features.</p>
<p>The rest of Silverlight 2 Unleashed book covers a few neat topics that people may not be as familiar with: loading media metadata, quick WCF basics, cross-domain requests, exception handling, and then a bunch of odds-and-ends that will whet your appetite for learning more about working in a Silverlight world, working with binding converters, unit testing, and resources for finding controls and resources. </p>
<p>And, yes, you read that right: a Silverlight unit testing walkthrough is on pages 541-549. For full disclosure, I should note that I did work with Laurent to review that part of Chapter 24.</p>
<p>Anyway, if you&#8217;re looking to move to the Microsoft web platform, expand your skills, and see what Silverlight is all about &#8211; do check it out! Oh, and if you&#8217;re looking for even more controls resources, do check out the <a href="http://www.codeplex.com/Silverlight/">Silverlight Toolkit</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jeff.wilcox.name/2008/11/silverlight-2-unleashed-book/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Successful .Xap deployment with your CDN: Set the application/x-silverlight-app MIME type</title>
		<link>http://www.jeff.wilcox.name/2008/11/xap-mime-type/</link>
		<comments>http://www.jeff.wilcox.name/2008/11/xap-mime-type/#comments</comments>
		<pubDate>Sat, 01 Nov 2008 23:16:37 +0000</pubDate>
		<dc:creator>Jeff Wilcox</dc:creator>
				<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[Web Servers]]></category>

		<guid isPermaLink="false">http://www.jeff.wilcox.name/2008/11/01/xap-mime-type/</guid>
		<description><![CDATA[If you host XAP files on a CDN or other host (such as Amazon S3), you need to have the server configured with the new Silverlight MIME type. You can find out specifics in the breaking changes reference. When you do not need to configure the MIME type: If your .Xap files and web pages [...]]]></description>
			<content:encoded><![CDATA[<p>If you host XAP files on a CDN or other host (such as Amazon S3), you need to have the server configured with the new Silverlight MIME type. You can find out specifics in the <a href="http://msdn.microsoft.com/en-us/library/cc645049(VS.95).aspx">breaking changes</a> reference.</p>
<p>When you do not need to configure the MIME type:</p>
<ul>
<li>If your .Xap files and web pages are on the same domain and do not need to be embedded elsewhere  </li>
<li>If you use a service like Silverlight Streaming and just embed &lt;iframe /&gt; tags in your web site</li>
</ul>
<p>But, if you want to share or enable embedding for others, you need to add the &#8220;application/x-silverlight-app&#8221; MIME type for your .Xap files.</p>
<p>This will allow:</p>
<ul>
<li>You to host your application binaries with a CDN  </li>
<li>Others to embed your applications in their pages and sites  </li>
<li>Bloggers to embed Silverlight &lt;object /&gt; tags right in their content and let syndication services and news readers embed the content</li>
</ul>
<p>Equally important, if you don&#8217;t want others to directly link to and reference your .Xap from their domains, then make sure to not send this mime type.</p>
<p><strong>Apache</strong><br />For global configuration, in your central mime.types file, add:</p>
<blockquote><p># Enable Silverlight support for our apps to be embedded anywhere<br />application/x-silverlight-app&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; xap</p>
</blockquote>
<p>Then restart Apache:</p>
<blockquote><p>$ sudo ./apachectl restart</p>
</blockquote>
<p>If you&#8217;re just configuring at the directory level, edit or add the .htaccess file in the directory you want to serve anywhere, and add the line:</p>
<blockquote><p>AddType application/x-silverlight-app xap</p>
</blockquote>
<p><strong>IIS 6 &amp; 7<br /></strong>Here&#8217;s a nice <a href="http://learn.iis.net/page.aspx/262/silverlight/">step-by-step guide to adding the MIME</a> type on Windows web servers.</p>
<p><strong>Amazon S3<br /></strong>Maybe not a true CDN, I do use Amazon&#8217;s Simple Storage Service (S3) for most of my Silverlight application hosting.</p>
<p>Amazon S3 records the MIME type that your S3 client sends with each file upload. This means that you <u>must</u> configure your system with the appropriate &#8220;application/x-silverlight-app&#8221; MIME type <strong>when you upload</strong>, or when clients download your .Xap, they will get an unknown MIME type and be greeted with blank space where you&#8217;d expect your app to be working.</p>
<p><strong>Your CDN</strong><br />I do not know the current <a href="http://www.limelightnetworks.com/">Limelight</a> or <a href="http://www.akamai.com/">Akamai</a> stories, sorry! Feel free to post a comment if you know.</p>
<h3>Use Fiddler to check</h3>
<p>I&#8217;d highly recommend that you download and use <a href="http://www.fiddler2.com/Fiddler2/version.asp">Fiddler2</a> on your Windows system. Using it, you can make sure and see what the content type is when it comes back in an HTTP response.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jeff.wilcox.name/2008/11/xap-mime-type/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Introducing the AutoCompleteBox</title>
		<link>http://www.jeff.wilcox.name/2008/10/introducing-autocompletebox/</link>
		<comments>http://www.jeff.wilcox.name/2008/10/introducing-autocompletebox/#comments</comments>
		<pubDate>Fri, 31 Oct 2008 03:43:35 +0000</pubDate>
		<dc:creator>Jeff Wilcox</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://www.jeff.wilcox.name/?p=137</guid>
		<description><![CDATA[The Silverlight AutoCompleteBox is now available. This guide covers the control&#8217;s properties, usage, and demonstrates how to hook it up to a JSON web service. Note: This post contains live Silverlight content that your news reader may not be able to display. The auto complete pattern is well-known, useful, time-tested. There&#8217;s been one in IE [...]]]></description>
			<content:encoded><![CDATA[<p>The Silverlight AutoCompleteBox is now available. This guide covers the control&#8217;s properties, usage, and demonstrates how to hook it up to a JSON web service.</p>
<p><img alt="AutoCompleteBox for Silverlight" src="http://media.jeff.wilcox.name/blog/AutoComplete/AutoCompleteBox.png" /> </p>
<p><em><font color="#404040">Note: This post contains live Silverlight content that your news reader may not be able to display.</font></em></p>
<p>The auto complete pattern is well-known, useful, time-tested. There&#8217;s been one in IE for ages. You expect that your e-mail client auto completes. Auto complete functionality can be found in controls in Winforms, WPF, AJAX, Flex. And now, Silverlight.</p>
<p>With the Silverlight Toolkit, we&#8217;ve decided to go beyond text-only suggestions. With basics in mind, we designed a flexible &amp; extensible control that lets modern app developers use data binding, styling, data templates, and more.</p>
<p><strong>Auto complete features you expect</strong></p>
<ul>
<li>Bind to a list </li>
<li>Override population </li>
<li>Set a minimum length required to get results </li>
<li>Set a delay before fetching suggestions </li>
</ul>
<p><strong>Silverlight AutoCompleteBox features</strong></p>
<ul>
<li>Style and retemplate: style the control, the text box, the container; set a DataTemplate for items in the drop down; retemplate the control to look like a combo box; you name it. </li>
<li>Built-in search modes. Provide your own custom text and item filter lambdas. </li>
<li>Replace the ListBox with your own custom selection adapter </li>
</ul>
<h3>Using AutoComplete</h3>
<p>To get started, just set the ItemsSource property to an IEnumerable. You&#8217;re then hooked up to the default filtering and are ready to go.</p>
<p>I&#8217;m going to walk you through some simple scenarios now using the control assemblies that we shipped in the toolkit. To follow along, you&#8217;ll need Visual Studio 2008 (SP1) with the Silverlight 2 Tools installed, plus the free <a href="http://www.codeplex.com/Silverlight/">Silverlight Toolkit</a>.</p>
<p>First, create a new Silverlight application project: open Visual Studio, go to the File | New | Project menu option, and create a new C# &#8216;Silverlight Application&#8217; project.</p>
<p>In the &#8216;Add Silverlight Application&#8217; dialog, select the 2nd option to &#8216;Automatically generate a test page&#8217;, and click Ok.</p>
<p>To add a reference to the main toolkit control library, right-click on the project in the Solution Explorer and select &#8216;Add Reference&#8217;.</p>
<p>Now, click on the &#8216;Browse&#8217; tab, locate the extracted toolkit folders, and move into the &#8216;Binaries&#8217; directory. Select the &#8216;Microsoft.Windows.Controls.dll&#8217; file and click Ok.</p>
<p><img alt="Add Reference" src="http://media.jeff.wilcox.name/blog/AutoComplete/AddReference.png" /> </p>
<p>If you create a new Silverlight Application project and add a reference to the Microsoft.Windows.Controls.dll assembly that we shipped in the toolkit, you can follow along and learn about the control.</p>
<p>Inside Microsoft.Windows.Controls we included ObjectCollection. It makes it easy to create collections in SIlverlight XAML.</p>
<p>Inside Page.xaml:</p>
<ul>
<li>Add the XML namespace for the Silverlight Toolkit controls. I&#8217;m using the prefix &quot;controls&quot; here. </li>
<li>Add mscorlib as a namespace, for strings. </li>
<li>Add an ObjectCollection of months in the resources. </li>
<li>Create an AutoCompleteBox control, setting the ItemsSource. </li>
</ul>
<p>Here&#8217;s the Page.xaml file:</p>
<div class="wlWriterSmartContent" id="scid:887EC618-8FBE-49a5-A908-2339AF2EC720:55663c25-0377-4ab5-a71b-983beb9f62b9" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px">
<pre class="xml" name="code">&lt;UserControl x:Class="SilverlightApplication6.Page"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:clr="clr-namespace:System;assembly=mscorlib"
    xmlns:controls="clr-namespace:Microsoft.Windows.Controls;assembly=Microsoft.Windows.Controls"
    Width="400" Height="300"&gt;
    &lt;UserControl.Resources&gt;
        &lt;controls:ObjectCollection x:Key="Months"&gt;
            &lt;clr:String&gt;January&lt;/clr:String&gt;
            &lt;clr:String&gt;February&lt;/clr:String&gt;
            &lt;clr:String&gt;March&lt;/clr:String&gt;
            &lt;clr:String&gt;April&lt;/clr:String&gt;
            &lt;clr:String&gt;May&lt;/clr:String&gt;
            &lt;clr:String&gt;June&lt;/clr:String&gt;
            &lt;clr:String&gt;July&lt;/clr:String&gt;
            &lt;clr:String&gt;August&lt;/clr:String&gt;
            &lt;clr:String&gt;September&lt;/clr:String&gt;
            &lt;clr:String&gt;October&lt;/clr:String&gt;
            &lt;clr:String&gt;November&lt;/clr:String&gt;
            &lt;clr:String&gt;December&lt;/clr:String&gt;
        &lt;/controls:ObjectCollection&gt;
    &lt;/UserControl.Resources&gt;
    &lt;StackPanel VerticalAlignment="Top" Margin="5"&gt;
        &lt;controls:AutoCompleteBox ItemsSource="{StaticResource Months}" /&gt;
    &lt;/StackPanel&gt;
&lt;/UserControl&gt;</pre>
</div>
<p>If you press F5 to run the project, you&#8217;ll get a text box that lets you type in a month.</p>
<p><img src="http://media.jeff.wilcox.name/blog/AutoComplete/January.png" /> </p>
<p>Here is the application:</p>
<p><img alt="Embedded Silverlight Application (begin)" src="http://media.jeff.wilcox.name/blog/view/ESAStart.png" /><br /><object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="400" height="150"><param name="source" value="http://www.jeff.wilcox.name/xap/2008/SilverlightApplication6.xap" /><a href="http://go2.microsoft.com/fwlink/?LinkID=124807" style="text-decoration: none;"><img src="http://go2.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight" style="border-style: none" /></a><br />
</object><br /><img alt="Embedded Silverlight Application (end)" src="http://media.jeff.wilcox.name/blog/view/ESAFinish.png" /> </p>
<p>Do know that in the current release, this control does not respect the INotifyCollectionChanged interface. If you&#8217;re changing the underlying data, please reset the ItemsSource to a new list. We&#8217;ll address this in a future release.</p>
<h3>Key AutoCompleteBox properties, methods and events</h3>
<p><strong>ItemsSource</strong> </p>
<p>Set your data here.</p>
<p><strong>Text</strong> </p>
<p>Contains the current text that the user has entered or selected.</p>
<p>The <strong>TextChanged</strong> event is fired whenever the text is updated. Most classic auto complete applications function like text boxes, so those apps can use the Text and TextChanged events as they are.</p>
<p>You can also replace most simple TextBox instances in your applications with AutoCompleteBox.</p>
<p><strong>IsTextCompletionEnabled</strong> </p>
<p>This property is true by default. It will perform a search on your items and look for the best match; if one is found, the text box is updated with the item&#8217;s string value, and the rest of the text will be highlighted.</p>
<p><img alt="IsTextCompletionEnabled property" src="http://media.jeff.wilcox.name/blog/AutoComplete/itce.png" /> </p>
<p><strong>SelectedItem</strong> </p>
<p>Is null if no item is currently selected.</p>
<p>If the user navigates through the drop down, selecting items, or clicks on an item, this will be updated to that item.</p>
<p>The <strong>SelectedItemChanged</strong> event fires when the item changes.</p>
<p>If you enter text into the control, such as &quot;Steve Ballmer,&quot; the SelectedItem may not be updated to an item unless the list box item is selected or if you have text completion enabled.</p>
<p><strong>SearchMode</strong> </p>
<p>Selects the built-in search filter to use. The default is &quot;StartsWith,&quot; and checks that each item&#8217;s string value starts with the user&#8217;s search string. &quot;Contains&quot; is another very useful value, as is &quot;None&quot;.</p>
<p>If you connect AutoCompleteBox to a web server that performs its own filtering, you&#8217;ll probably want to set the SearchMode to &#8216;None&#8217;.</p>
<p><strong>MinimumPopulateDelay</strong> </p>
<p>This is an amount of time that elapses after the user types and the population event is fired.</p>
<p>The default value of 0 is very quick, so every time the user enters new character, the Populating event is fired. If you&#8217;re connected to a web service, you&#8217;ll want to step back and place a reasonable value in here so that not every keypress goes straight to the server.</p>
<p><strong>MinimumPrefixLength</strong> </p>
<p>This is the minimum number of characters that must be entered before the control looks for suggestions. The default value is 1, but a lot of classic AJAX auto complete controls use 3 as the default value, so this is a common customization property.</p>
<p><em>Advanced scenarios might make use of:</em></p>
<p><strong>TextFilter</strong> </p>
<p>Provide a lambda/delegate that takes two parameters: the search string, and the string that represents an item. The function needs to return bool true or false, indicating whether the item should be shown as a suggestion in the drop down list.</p>
<p><strong>ItemFilter</strong> </p>
<p>The more fun version of TextFilter, this takes a lambda expression that has two inputs: the search string, and the item as an object. You are then free to use your own filtering logic with your rich data types to return true or false.</p>
<p><strong>Populating event</strong> </p>
<p>Called whenever the control is ready to search for suggestions, this is your opportunity to intercept the standard filtering and manage the items source first.</p>
<p>If you have the data available immediately, before your handler returns, you can simply change the ItemsSource property of the AutoCompleteBox control right here, no other changes necessary.</p>
<p>But if you&#8217;re going to perform an asynchronous operation (background thread calculations; call a web service), you need to set the Cancel property of the event arguments to True. This will cancel the built-in AutoComplete filtering and effectively tell the control to hold off until you are ready.</p>
<p>To continue the suggestion process, you need to then call the <strong>PopulateComplete</strong> method. In your web service completion event, you&#8217;ll want to place this call.</p>
<p><strong>Populated event</strong> </p>
<p>This is called once suggestions are found and ready to be displayed. The Data property of the event arguments gives you read-only access to the view that will be provided to the selection control.</p>
<p><strong>DropDownOpening, DropDownOpened, DropDownClosing, DropDownClosed</strong> </p>
<p>A nice set of drop down events. The Opening and Closing events can be canceled.</p>
<h3>AutoComplete items in the real world</h3>
<p>Setting the ItemsSource in XAML is not a real scenario. Enter web services, business object collections, XML files.</p>
<p>The ItemsSource property will take any IEnumerable. Linq fans rejoice. If you don&#8217;t have the data ahead of time, you can subscribe to the Populating event of AutoCompleteBox and update the ItemsSource with the appropriate results, synchronously or asynchronously.</p>
<p><strong>Using ItemsSource with a collection</strong></p>
<p>If your application already has a set of data available (list of names, parsed XML, set of static city and state names), you can just set the items source in code to your enumerable collection.</p>
<p>Here&#8217;s another quick app. The XAML is:</p>
<div class="wlWriterSmartContent" id="scid:887EC618-8FBE-49a5-A908-2339AF2EC720:d3b8e49c-1f14-4541-8be8-63e721cf67c8" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px">
<pre class="xml" name="code">&lt;UserControl x:Class="SilverlightApplication7.Page"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:controls="clr-namespace:Microsoft.Windows.Controls;assembly=Microsoft.Windows.Controls"
    Width="400" Height="100"&gt;
    &lt;StackPanel VerticalAlignment="Top" Margin="5"&gt;
        &lt;controls:AutoCompleteBox x:Name="AutoComplete1" /&gt;
    &lt;/StackPanel&gt;
&lt;/UserControl&gt;</pre>
</div>
<p>And the code behind file:</p>
</p>
<div class="wlWriterSmartContent" id="scid:887EC618-8FBE-49a5-A908-2339AF2EC720:585071d7-d37d-45d3-bb11-23347fc5b2d3" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px">
<pre class="c-sharp" name="code">using System.Windows;
using System.Windows.Controls;

namespace SilverlightApplication7
{
    public partial class Page : UserControl
    {
        public Page()
        {
            InitializeComponent();
            Loaded += OnLoaded;
        }

        private void OnLoaded(object sender, RoutedEventArgs e)
        {
            AutoComplete1.ItemsSource = new string[]
            {
                "Steve Ballmer",
                "Bill Gates",
            };
        }
    }
}</pre>
</div>
<p><img alt="Embedded Silverlight Application (begin)" src="http://media.jeff.wilcox.name/blog/view/ESAStart.png" /><br /><object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="400" height="150"><param name="source" value="http://www.jeff.wilcox.name/xap/2008/SilverlightApplication7.xap" /><a href="http://go2.microsoft.com/fwlink/?LinkID=124807" style="text-decoration: none;"><img src="http://go2.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight" style="border-style: none" /></a><br />
</object><br /><img alt="Embedded Silverlight Application (end)" src="http://media.jeff.wilcox.name/blog/view/ESAFinish.png" /> </p>
<p><strong>Connecting to a JSON web service</strong></p>
<p>Most AJAX auto complete controls today use JSON. The transmit format is lightweight, able to transfer rich object data, and supported by just about everything out there. The System.Json assembly in Silverlight makes it easy to parse in VB and C#.</p>
<p>Here is a minimalistic example. I have this PHP page deployed:</p>
<div class="wlWriterSmartContent" id="scid:887EC618-8FBE-49a5-A908-2339AF2EC720:35087a74-4eac-4fe8-a4ac-301baf6eabc2" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px">
<pre class="php" name="code">&lt;?php
header("Content-type: application/json");

$var = "prefix";
if (isset($_GET[$var]) and $_GET[$var] != "")
{
        // Shorten
        $prefix = substr($_GET[$var], 0, 40);

        // Strip
        $s = strip_tags($prefix);

        // Create suggestions
        $suggestions = array();

        for ($i = 0; $i &lt; 11; $i++)
        {
                $suggestions[] = $s . $i;
        }

        print json_encode($suggestions);
}
?&gt;</pre>
</div>
<p>I&#8217;m using the same Page.xaml from before. To get ready to use JSON, I need to:</p>
<ul>
<li>Add a reference to the System.Json Silverlight assembly </li>
<li>Add a using statement to the top of my file for &#8216;System.Json&#8217;, &#8216;Microsoft.Windows.Controls&#8217;, &#8216;System.Linq&#8217;, and &#8216;System.Windows.Browser&#8217; </li>
</ul>
<p>The code behind file doesn&#8217;t need many changes to deal with a web service.</p>
<p>The basic idea is to intercept the Populating event, cancel it, and kick off a web client. In the completion event for the web client, we update the items source of the AutoCompleteBox and call the PopulateComplete method to display the suggestions.</p>
<p>In my app, I first subscribe to Population. I set some basic properties too:</p>
<div class="wlWriterSmartContent" id="scid:887EC618-8FBE-49a5-A908-2339AF2EC720:46bba493-b99c-4691-a398-b5ec69af52eb" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px">
<pre class="c-sharp" name="code">        private void OnLoaded(object sender, RoutedEventArgs e)
        {
            AutoComplete1.IsTextCompletionEnabled = false;

            // Server does the filtering
            AutoComplete1.SearchMode = AutoCompleteSearchMode.None;

            AutoComplete1.Populating += (s, args) =&gt;
                {
                    args.Cancel = true;
                    WebClient wc = new WebClient();
                    string prefix = HttpUtility.UrlEncode(args.Parameter);
                    Uri service = new Uri("http://www.jwpc.com/services/suggest/?prefix=" + prefix);
                    wc.DownloadStringCompleted += DownloadStringCompleted;
                    wc.DownloadStringAsync(service, s);
                };
        }</pre>
</div>
<p>Then, in the DownloadStringCompleted handler, I parse the JSON response:</p>
<div class="wlWriterSmartContent" id="scid:887EC618-8FBE-49a5-A908-2339AF2EC720:cf922312-381a-4bc5-bc66-59e7a3387c01" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px">
<pre class="c-sharp" name="code">        private void DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
        {
            AutoCompleteBox acb = e.UserState as AutoCompleteBox;
            if (acb != null &#038;&#038; e.Error == null &#038;&#038; !e.Cancelled &#038;&#038; !string.IsNullOrEmpty(e.Result))
            {
                List&lt;string&gt; suggestions = new List&lt;string&gt;();
                JsonArray ja = JsonArray.Parse(e.Result) as JsonArray;
                foreach (JsonPrimitive suggestion in ja)
                {
                    suggestions.Add(suggestion.ToString());
                }
                if (suggestions.Count &gt; 0)
                {
                    acb.ItemsSource = suggestions;
                    acb.PopulateComplete();
                }
            }
        }</pre>
</div>
<p>That&#8217;s all there is to it!</p>
<p><img alt="Embedded Silverlight Application (begin)" src="http://media.jeff.wilcox.name/blog/view/ESAStart.png" /><br /><object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="400" height="200"><param name="source" value="http://www.jeff.wilcox.name/xap/2008/SilverlightApplication8.xap" /><a href="http://go2.microsoft.com/fwlink/?LinkID=124807" style="text-decoration: none;"><img src="http://go2.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight" style="border-style: none" /></a><br />
</object><br /><img alt="Embedded Silverlight Application (end)" src="http://media.jeff.wilcox.name/blog/view/ESAFinish.png" /> </p>
<p><strong>Real world AutoComplete example</strong></p>
<p>Inside the Silverlight Toolkit samples project, I&#8217;ve included a similar example of connecting to a JSON web service. It uses the excellent Live search suggestions. In this sample, the MinimumPopulateDelay is set to 150 milliseconds.</p>
<p>Here&#8217;s the Live.com sample:</p>
<p><img alt="Embedded Silverlight Application (begin)" src="http://media.jeff.wilcox.name/blog/view/ESAStart.png" /><br /><object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="685" height="410"><param name="source" value="http://www.jeff.wilcox.name/xap/2008/SilverlightApplication9.xap" /><a href="http://go2.microsoft.com/fwlink/?LinkID=124807" style="text-decoration: none;"><img src="http://go2.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight" style="border-style: none" /></a><br />
</object><br /><img alt="Embedded Silverlight Application (end)" src="http://media.jeff.wilcox.name/blog/view/ESAFinish.png" /> </p>
<h3>How we determine what text to display in the text box</h3>
<p>For performance reasons, we haven&#8217;t exposed the ability for you to creating a binding expression linking your items and the text that should be used in comparisons.</p>
<p>When you bind to a list of objects, the string representation is evaluated in the following order:</p>
<ul>
<li>Attempting to use an IValueConverter instance (this is the <strong>Converter</strong> property, along with ConverterParameter and ConverterCulture) </li>
<li>Calling <strong>ToString()</strong> on the item </li>
</ul>
<p>So, if you own the data classes in your application, you&#8217;ll want to expose the most meaningful name (such as a person&#8217;s full name, or employee ID), since the default ToString operator is going to return the type name of your item instead.</p>
<p>You can also provide a value converter in all situations.</p>
<h3>AutoCompleteBox data templates, styling, and templating</h3>
<p>You can use the <strong>ItemTemplate</strong> property to provide a DataTemplate that is used for rendering items.</p>
<p>These dependency properties can be used for styling:</p>
<ul>
<li><strong>ItemContainerStyle</strong> </li>
<li><strong>TextBoxStyle</strong> </li>
</ul>
<p>In the Live search example, the text box style was:</p>
<div class="wlWriterSmartContent" id="scid:887EC618-8FBE-49a5-A908-2339AF2EC720:30688ea8-60cc-4d2e-853f-370a7a3b3a22" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px">
<pre class="xml" name="code">    &lt;UserControl.Resources&gt;
        &lt;Style x:Key="SearchTextBoxStyle" TargetType="TextBox"&gt;
            &lt;Setter Property="Background" Value="#AAFFFFFF" /&gt;
            &lt;Setter Property="FontFamily" Value="Verdana" /&gt;
            &lt;Setter Property="FontSize" Value="18" /&gt;
            &lt;Setter Property="Padding" Value="2" /&gt;
        &lt;/Style&gt;
    &lt;/UserControl.Resources&gt;</pre>
</div>
<p>And the AutoCompleteBox XAML:</p>
<div class="wlWriterSmartContent" id="scid:887EC618-8FBE-49a5-A908-2339AF2EC720:ecb2ba6b-84db-4f46-bf85-95f8dc42f87e" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px">
<pre class="xml" name="code">&lt;controls:AutoCompleteBox
    SearchMode="None"
    x:Name="Search"
    TextBoxStyle="{StaticResource SearchTextBoxStyle}"
    IsTextCompletionEnabled="False"
    IsEnabled="False" /&gt;</pre>
</div>
<p>The control defines four template parts, similar to ComboBox; however, the default control template only provides 3 of those parts, since it does not expose a toggle button. All 4 are:</p>
<ul>
<li>The text box; named &#8216;Text&#8217; </li>
<li>The popup; named &#8216;Popup&#8217; </li>
<li>The selection adapter (ListBox is the default); control type or wrapper implements the ISelectionAdapter interface; named &#8216;SelectionAdapter&#8217; </li>
<li>The drop down toggle button; named &#8216;DropDownToggle&#8217; and of type ToggleButton </li>
</ul>
<h3>What&#8217;s next?</h3>
<p>I hope this gives you what you need to get started using AutoCompleteBox in your own applications. In the coming days I&#8217;ll be posting some details and fun examples of how you can really make your apps shine with this control.</p>
<p>If you&#8217;re looking for other posts about the control, I&#8217;d recommend checking out <a href="http://jonas.follesoe.no/ImproveYourUserExperienceUsingTheAutoCompleteBox.aspx">Jonas Folles&#248;&#8217;s AutoCompleteBox post</a> too. He&#8217;s a blogging machine!</p>
<p><em>Hope this helps.</em></p>
<p>See also:<br />
  <br /><a href="http://www.jeff.wilcox.name/2008/10/30/fivethings-autocompletebox/">AutoCompleteBox: The 5 things you need to know</a></p>
<p><a href="http://www.jeff.wilcox.name/2008/10/30/video-autocompletebox/">AutoCompleteBox Video Introduction</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.jeff.wilcox.name/2008/10/introducing-autocompletebox/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Sorry boss, I just released the new Silverlight Controls source code to the world.</title>
		<link>http://www.jeff.wilcox.name/2008/10/open-source-silverlight-toolkit/</link>
		<comments>http://www.jeff.wilcox.name/2008/10/open-source-silverlight-toolkit/#comments</comments>
		<pubDate>Tue, 28 Oct 2008 21:28:31 +0000</pubDate>
		<dc:creator>Jeff Wilcox</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://www.jeff.wilcox.name/2008/10/28/open-source-silverlight-toolkit/</guid>
		<description><![CDATA[Last night, I signed on to the CodePlex site and checked in the source code to all the Silverlight controls we&#8217;ve been working on night-and-day. Like an open source ninja! On just about any other team at Microsoft, I might have some major explaining to do right about now. In all seriousness, Shawn Burke is [...]]]></description>
			<content:encoded><![CDATA[<p>Last night, I signed on to the <a href="http://www.codeplex.com/Silverlight/">CodePlex site</a> and checked in the source code to all the Silverlight controls we&#8217;ve been working on night-and-day. Like an open source ninja! On just about any other team at Microsoft, I might have some major explaining to do right about now.</p>
<p>In all seriousness, <a href="http://blogs.msdn.com/sburke/archive/2008/10/28/silverlight-toolkit-now-available-for-download.aspx">Shawn Burke is the man behind open source</a> in the developer division. And my boss. And we&#8217;ve been planning this major source release for a while now. He&#8217;s the person to thank for having the vision and the passion to challenge us to get this out there for you all.</p>
<p>All of our work is out there now with the <a href="http://www.microsoft.com/opensource/licenses.mspx#Ms-PL">Microsoft Public License</a> (Ms-PL), an <a href="http://www.opensource.org/licenses/ms-pl.html">Open Source Initiative</a>-approved license, so there&#8217;s a lot of opportunity for developers to reuse our hard work.</p>
<p>Delivering source code is easy. So we&#8217;re raising the bar, and shipping sample apps, sample source, plus the thousands of unit and functional tests that we used for testing these controls on all the supported platforms. <a href="http://www.codeplex.com/Silverlight/">Download the November &#8217;08 release now</a>!</p>
<p>We also deliver a complete data visualization stack, and <a href="http://blogs.msdn.com/delay/archive/2008/10/28/announcing-a-free-open-source-charting-solution-for-silverlight-silverlight-toolkit-released-today-at-pdc.aspx">David Anson has more details</a> on that.</p>
<h3>AutoCompleteBox</h3>
<p>I was the developer for the AutoCompleteBox control and will be sharing a lot of the fun scenarios that the control enables on this blog in the coming days. This control is a lot like other AutoComplete AJAX controls that are out there, but shaken up and served with a twist of extensibility.</p>
<p>One small example for the true geeks out there: I love that we were able to deliver a searching/filtering story that lets you provide a lambda function to perform your own advanced filtering on the items.</p>
<p><a href="http://silverlight.net/samples/sl2/toolkitcontrolsamples/run/default.html"><img alt="Search suggestions sample page" src="http://media.jeff.wilcox.name/blog/AutoComplete/AutoCompleteSample.jpg" /></a>     <br /><em>Click to <a href="http://silverlight.net/samples/sl2/toolkitcontrolsamples/run/default.html">open the live sample project</a> shown above. Then navigate to &quot;AutoCompleteBox &gt; Scenarios &gt; Search Suggestions&quot;.</em></p>
<p>The &quot;Search Suggestions&quot; scenario sample inside the live control samples application actually connects to the Live Search web service, just like Live.com and IE8 do. The requests come back in JSON. And the sample features the AutoCompleteBox control for Silverlight. Clicking through the filenames at the top of the frame you&#8217;ll see that the whole thing was done in about a page of code.</p>
<p><strong>The proverbial Microsoft blog storm is off to a good start. I&#8217;ll contribute my own wave of posts here soon enough. In the meantime, there&#8217;s </strong><a href="http://jonas.follesoe.no/ImproveYourUserExperienceUsingTheAutoCompleteBox.aspx"><strong>already</strong></a><strong> </strong><a href="http://jonas.follesoe.no/ChangeTheLookOfYourSilverlightApplicationUsingThemes.aspx"><strong>plenty</strong></a><strong> </strong><a href="http://jonas.follesoe.no/NewLayoutControlsInTheSilverlightToolkit.aspx"><strong>of</strong></a><strong> </strong><a href="http://www.bluerosegames.com/SilverlightBrassTacks/post/Viewbox-in-the-Silverlight-Toolkit.aspx"><strong>coverage</strong></a><strong> </strong><a href="http://www.andybeaulieu.com/Home/tabid/67/EntryID/124/Default.aspx"><strong>out</strong></a><strong> </strong><a href="http://weblogs.asp.net/dwahlin/archive/2008/10/28/silverlight-toolkit-released.aspx"><strong>there</strong></a><strong>.</strong></p>
<p>Enjoy the source. Learn from it. Tell us what you would like us to focus on and do better and we continue to iterate on this toolkit.</p>
<p>Stay tuned.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jeff.wilcox.name/2008/10/open-source-silverlight-toolkit/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Awesome controls are coming for the Silverlight platform</title>
		<link>http://www.jeff.wilcox.name/2008/10/controls-are-coming/</link>
		<comments>http://www.jeff.wilcox.name/2008/10/controls-are-coming/#comments</comments>
		<pubDate>Thu, 23 Oct 2008 08:22:21 +0000</pubDate>
		<dc:creator>Jeff Wilcox</dc:creator>
				<category><![CDATA[Conferences]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://www.jeff.wilcox.name/2008/10/23/controls-are-coming/</guid>
		<description><![CDATA[Now that the wait is over and Silverlight 2 is out there in the wild, there&#8217;s very little excuse not to be using this awesome Microsoft platform. Easy-to-use controls make fast, easy development possible, and there is a clear roadmap out there now on what all is going on. Last week I was really bunkered [...]]]></description>
			<content:encoded><![CDATA[<p>Now that the wait is over and Silverlight 2 is out there in the wild, there&#8217;s very little excuse not to be using this awesome Microsoft platform. Easy-to-use controls make fast, easy development possible, and there is a clear roadmap out there now on what all is going on.</p>
<p>Last week I was really bunkered down with Silverlight. That and upgrading to the 64-bit Photoshop. That&#8217;s nice, but I&#8217;m always pressing Alt-Tab to use Expression Blend. You really can build expressive apps with Silverlight.</p>
<p>I know for a fact that there&#8217;s some neat work happening in the community, and do apologize for being silent on the blogging front. Here&#8217;s some of what&#8217;s going on.</p>
<h3>Built-in controls</h3>
<p>The controls that ship with the Silverlight 2 runtime and SDK are slick. They received crisp, refined styles this time around, and the experience for application and interface developers is feeling similar to WPF now. There&#8217;s also a progress bar and password box built-in now.</p>
<p><img src="http://media.jeff.wilcox.name/blog/toolkit/NewSilverlightThemes.png" /> </p>
<p>If you&#8217;re not using the DataGrid in your apps, you&#8217;re missing out: <a href="http://blogs.msdn.com/scmorris/archive/2008/10/14/silverlight-2-datagrid-is-released.aspx">Scott Morrison has been busy updating</a> all of the great DataGrid tutorials for the final release version. Key messages: Performance, customizable, and new features too, like multi-selection.</p>
<h3>Silverlight Toolkit</h3>
<p>With the final Silverlight 2 release a little over a week ago, Shawn Burke blogged about the progress that we&#8217;re making on the <a href="http://blogs.msdn.com/sburke/archive/2008/10/14/silverlight-2-released-silverlight-toolkit-on-the-way.aspx">Silverlight Toolkit</a>. There are neat controls in the pic that he posted: Expander, a TreeView, NumericUpDown, and an AutoComplete text box.</p>
<p><img alt="DataGrid thing" src="http://media.jeff.wilcox.name/blog/toolkit/SampleControl.png" /></p>
<p><em>Oops. I hit the wrong button, and Windows Live Writer seems to have posted a screenshot of a sample that I had up on my desktop&#8230; hmm&#8230; It sort of looks like a text box. And a drop down. Yet it has a DataGrid, too. Interesting&#8230;</em></p>
<p>So, stay tuned. Reiterating the cool things Shawn&#8217;s talked about:</p>
<ul>
<li><a href="http://www.opensource.org/licenses/ms-pl.html">MS-PL</a>, open source from Microsoft</li>
<li>Things you&#8217;ve been missing: WrapPanel. DockPanel.</li>
<li>Accompanying unit &amp; integration tests built with the <a href="http://code.msdn.microsoft.com/silverlightut/">Silverlight Unit Test Framework</a></li>
</ul>
<h3>Watermarked TextBox Control</h3>
<p>Yesterday Tim Heuer posted some <a href="http://timheuer.com/blog/archive/2008/10/22/silverlight-watermark-text-box-control.aspx">Watermarked TextBox goodness</a> on his blog, in case you were looking for that one.</p>
<h3>SilverlightContrib</h3>
<p>A few days ago a friend pointed me to the <a href="http://www.codeplex.com/silverlightcontrib/">SilverlightContrib</a> project. I&#8217;ll admit I don&#8217;t know a lot about it, other than the bullet points I saw on the homepage. I&#8217;m not associated with this project in any way, but want to give it props. Just look at some of the things it has:</p>
<ul>
<li>Zip compression</li>
<li>Utilities galore: byte utilities. string utilities. animation stuff</li>
<li>Some selection controls and gauges.</li>
</ul>
<p>Check it out! There is a <a href="http://silverlightcontrib.org/demo/">live demo page</a> out there, too.</p>
<h3>Here comes PDC</h3>
<p>If you&#8217;re looking for something to do next weekend, it sounds like all the Microsoft geeks will be converging on the Los Angeles Convention Center for <a href="http://microsoftpdc.com/Default.aspx">PDC 2008</a>. There is even a nice convincing <a href="http://microsoftpdc.com/Letter.aspx">letter you can send your boss</a>. Let me know if that works for you.</p>
<h3>Stay tuned!</h3>
<p>I&#8217;ve been involved in Silverlight for a few years now, in one capacity or another &#8211; and the trip has been awesome. </p>
<p>I won&#8217;t reminisce much, other than to say that I do have vivid memories of the weeks that debugging didn&#8217;t work&#8230; the weeks that the wrong clicks in a sequence could cause problems&#8230; What was released last week is <strong>solid.</strong> </p>
<p>Major kudos to everyone that made the release happen, it has been a pleasure working with you all. Now we&#8217;re going to see just how fun this gets. There&#8217;s more to come.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jeff.wilcox.name/2008/10/controls-are-coming/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Client-side HTML controls for Silverlight 2</title>
		<link>http://www.jeff.wilcox.name/2008/10/html-controls-for-silverlight/</link>
		<comments>http://www.jeff.wilcox.name/2008/10/html-controls-for-silverlight/#comments</comments>
		<pubDate>Sun, 05 Oct 2008 21:51:10 +0000</pubDate>
		<dc:creator>Jeff Wilcox</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://www.jeff.wilcox.name/2008/10/05/html-controls-for-silverlight/</guid>
		<description><![CDATA[What if you could use and create ASP.NET-like web controls that are 100% client-side, powered by the Silverlight 2 runtime? What if ViewState was a thing of the past? Would you like to cut your web application&#8217;s load on your servers from 50 pageviews down to 0? Wouldn&#8217;t your users love it if your application [...]]]></description>
			<content:encoded><![CDATA[<p>What if you could use and create ASP.NET-like web controls that are 100% client-side, powered by the Silverlight 2 runtime? What if ViewState was a thing of the past? Would you like to cut your web application&#8217;s load on your servers from 50 pageviews down to 0? Wouldn&#8217;t your users love it if your application was always instantly responsive?</p>
<p>A week ago, I posted &quot;<a href="http://www.jeff.wilcox.name/2008/09/28/do-it-in-js-and-cs/">If you can do it in JavaScript, you can do it in managed Silverlight .NET code</a>.&quot; Here&#8217;s proof that the HTML interoperability capabilities in Silverlight are not only world-class, but also amazingly powerful.</p>
<p>This &quot;managed HTML controls&quot; <strong>concept</strong> is a neat idea: something that might whet your appetite to explore the interoperability features and consider using the feature to build sophisticated applications. However, key hurdles leave this as a conversation piece more than a new application platform. At the end of the day, the Silverlight presentation framework as it stands if going to be your best bet for a majority of your applications.</p>
<p>Exploring and thinking about changing the boundaries and status quo of web apps is something that&#8217;s fun and challenging. A client-side implementation of ASP.NET, enabling rich browser apps written in C#, was totally my dream a few years ago. Nikhil&#8217;s <a href="http://projects.nikhilk.net/ScriptSharp/Default.aspx">Script#</a> actually can get you some of the way by letting you write client apps in .NET. </p>
<p>Today, a client-side ASP.NET HtmlControl is interesting, but not a game-changer, given the maturity of JavaScript platform and the richer app platforms out there like Silverlight (that is based on WPF) and Flex.</p>
<h3>What&#8217;s the HtmlControls concept look like?</h3>
<p>Here&#8217;s a look at a few of the types.</p>
<p>By exposing strongly typed properties, methods, and events, your .NET HTML application code will be cleaner, easier to maintain, enable you to use static analysis tools, and even perform unit testing.</p>
<p><img src="http://media.jeff.wilcox.name/blog/dom/SampleClasses.png" /></p>
<p>Although the HtmlControlBase exposes a lot of the sample string-based properties as the standard Silverlight HtmlElement, it adds overloads with enumeration-based parameters (cut down on spelling errors), and stop having to duplicate strings through your app:</p>
<p><img alt="The CssAttribute enum." src="http://media.jeff.wilcox.name/blog/dom/CssAttribute.png" /> </p>
<p>You can set Font properties like you would in ASP.NET, without worrying so much about CSS at the end of the day:</p>
<p><img alt="The FontInfo object." src="http://media.jeff.wilcox.name/blog/dom/FontInfo.png" /> </p>
<p>The same goes for standard HTML properties defined by the W3C &#8211; helpful HtmlProperty enum:</p>
<p><img alt="The HtmlProperty enum." src="http://media.jeff.wilcox.name/blog/dom/HtmlProperty.png" /> </p>
<h3>Thinking about the pros and cons</h3>
<p>Some of what you can do with managed HTML controls:</p>
<ul>
<li>Create strongly typed custom controls: be more efficient, create simpler code, less spaghetti code </li>
<li>Develop rich web applications using Visual Studio, including built-in FxCop, code refactoring, the object browser, XML documentation support, and more </li>
<li>Create sophisticated AJAX-like applications with IntelliSense support </li>
<li>No need for your controls to POST-back to the server or worry about ViewState ~ these are stateful, since they are in memory </li>
<li>Integrate with Silverlight 2 applications, and all the richness it provides in its framework and class libraries </li>
<li>You could move an application like 37signals&#8217; Backpack out of a server farm, store the .Xap on a CDN, and use occassional cross-domain web service calls to store and retrieve data&#8230; imagine, some types of apps could serve a billion application users with only 1 billion .Xap downloads from your CDN, instead of generating tens of billions of web pages on an expensive web farm </li>
</ul>
<p><strong>What&#8217;s so great about it?</strong></p>
<ul>
<li>Replace loosely typed string property setters (spaghetti code) with strongly typed code </li>
<li><a href="http://projects.nikhilk.net/ScriptSharp/Default.aspx">Like Script#</a>&#8230; but with the live .NET Silverlight 2 CLR! </li>
<li>Kind of like a cheap ASP.NET implementation, on the client side, that works on Windows and Mac (IE, Firefox, Safari) </li>
<li>Proves how powerful Silverlight can be, even for out-of-the-box projects </li>
<li>Fun! </li>
</ul>
<p><strong>What are the drawbacks?</strong></p>
<ul>
<li>Silverlight has a much richer presentation story: <em>really</em> rich controls, animations, design tools like Blend, and WPF goodness. Videos. Audio. Full-screen. </li>
<li>Why build effectively an HTML-based AJAX app using Silverlight, and yet require your users to have the Silverlight 2 runtime on their machines? </li>
<li>The memory performance of this concept is probably quite bad: each element is already in the browser; there&#8217;s a pointer to that from the native platform in Silverlight; there&#8217;s the Silverlight HtmlElement object instance; and then there&#8217;s the HtmlControl type. That&#8217;s a lot of duplicated stuff! </li>
<li>The performance of the concept in general isn&#8217;t going to be too awesome: there&#8217;s a lot of interop here between the web browser, JavaScript, the browser&#8217;s plugin APIs (NPAPI or ActiveX), the managed CLR, and back again </li>
<li>All the <a href="http://www.jeff.wilcox.name/2008/09/28/do-it-in-js-and-cs/">points made here to NOT use</a> the HTML DOM bridge </li>
</ul>
<p><strong>What does it give you that you don&#8217;t get with JavaScript?</strong></p>
<ul>
<li>C#, VB, or DLR languages like Ruby running in the browser, client-side, interacting with the HTML page </li>
<li>The ability to use Visual Studio for client web development </li>
</ul>
<p>And, at the end of the day, Script# might get you these things, without the Silverlight dependency.</p>
<p><strong>What does it give you that you don&#8217;t get with Silverlight today?</strong></p>
<ul>
<li>Add managed code to existing AJAX applications and HTML elements by hooking up events and altering properties </li>
<li>Easier way to work with HTML pages than using the functional but basic HTML interop </li>
<li>Create rich HTML text editing controls and web forms; create elements for the browser&#8217;s built-in printing system </li>
</ul>
<h3>Using the HTML control framework</h3>
<p><strong>Example: Setting the width and height</strong></p>
<p>Without this framework, to set the width of an HtmlElement in Silverlight, you&#8217;d need to write this code (assumes you have a regular Silverlight HtmlElement instance called &quot;element&quot;):</p>
<div class="wlWriterSmartContent" id="scid:887EC618-8FBE-49a5-A908-2339AF2EC720:e8d37199-3177-4bd7-b8ce-4eeb1a8121f8" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px">
<pre class="c-sharp" name="code">// Setting the height and width - notice the typo you wouldn't know
// about until runtime:
element.SetStyleAttribute("width", "50px");
element.SetStyleAttribute("height", "450ppx");</pre>
</div>
<p>There&#8217;s no type checking: you won&#8217;t know about spelling errors or other problems until runtime, and if you do any CSS manipulation, your code will get very difficult to maintain. Here&#8217;s the same code, with a managed HTML control (using a few different ways of setting the value):</p>
</p>
<div class="wlWriterSmartContent" id="scid:887EC618-8FBE-49a5-A908-2339AF2EC720:60fdaa87-916b-40b5-afd1-51e0ae4a5ccd" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px">
<pre class="c-sharp" name="code">// Set the width and height of the control
control.Width = 50;
control.Height = new Unit(450, UnitType.Pixel);</pre>
</div>
<p>Same # of lines of code, but a little more &quot;attractive&quot; API.</p>
<p>You can also wrap existing HtmlElements with a managed control in some cases: either standard parts of your web page, existing AJAX applications. This is possible when the constructor exposes a HtmlElement parameter.</p>
<p><strong>Creating a composite control</strong></p>
<p>Here&#8217;s a simple &quot;user control&quot; that has a link and a button inside of it:</p>
</p>
<div class="wlWriterSmartContent" id="scid:887EC618-8FBE-49a5-A908-2339AF2EC720:e5fb406f-29ea-46dc-b686-61862b03507a" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px">
<pre class="c-sharp" name="code">using System;
using WebPage = System.Windows.Browser.HtmlPage;
using Microsoft.Silverlight.Testing.Html;

namespace HtmlControlSample
{
    /// &lt;summary&gt;
    /// A simple managed HTML control.
    /// &lt;/summary&gt;
    public class MyUserControl : HtmlDiv
    {
        /// &lt;summary&gt;
        /// A simple link that is hooked up to the app.
        /// &lt;/summary&gt;
        private HtmlAnchor _appLink;

        /// &lt;summary&gt;
        /// A simple button.
        /// &lt;/summary&gt;
        private HtmlButton _button;

        /// &lt;summary&gt;
        /// Initializes a new instance of the MyUserControl control.
        /// &lt;/summary&gt;
        public MyUserControl()
        {
            InitializeComponent();
        }

        /// &lt;summary&gt;
        /// Initialize composite controls and add them as children.
        /// &lt;/summary&gt;
        private void InitializeComponent()
        {
            // A link that will display the current time
            _appLink = new HtmlAnchor(
                "Click me for the time!",
                (sender, e) =&gt; Alert(DateTime.Now.ToLongTimeString()));

            _button = new HtmlButton();
            _button.InnerText = "Toggle my boldness";
            _button.Click += (sender, e) =&gt; _button.Font.Bold = !_button.Font.Bold;

            Controls.Add(_appLink);
            Controls.Add(_button);
        }

        /// &lt;summary&gt;
        /// Uses the Alert method of the HTML interoperability feature to
        /// display text.
        /// &lt;/summary&gt;
        /// &lt;param name="text"&gt;The text to display.&lt;/param&gt;
        private static void Alert(string text)
        {
            WebPage.Window.Alert(text);
        }
    }
}</pre>
</div>
<p>To hook it up to the application, here is a simple class that shrinks the Silverlight plugin to not occupy any space on the page, that creates a new instance of the MyUserControl type and appends it to the web page body.</p>
<p>The HideSilverlightPlugin function is important because it lets you press F5 while working in a standard Silverlight application project.</p>
</p>
<div class="wlWriterSmartContent" id="scid:887EC618-8FBE-49a5-A908-2339AF2EC720:d2316b18-4527-4620-8fb6-6c57927ad641" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px">
<pre class="c-sharp" name="code">using System;
using Microsoft.Silverlight.Testing.Html;
using WebPage = System.Windows.Browser.HtmlPage;

namespace HtmlControlSample
{
    /// &lt;summary&gt;
    /// A sample HTML application.
    /// &lt;/summary&gt;
    public class SampleHtmlApp
    {
        /// &lt;summary&gt;
        /// The application's user interface control.
        /// &lt;/summary&gt;
        private MyUserControl _myUserInterface;

        /// &lt;summary&gt;
        /// Initialize and run the application.
        /// &lt;/summary&gt;
        public static void Run()
        {
            new SampleHtmlApp();
        }

        /// &lt;summary&gt;
        /// Initializes a new instance of the SampleHtmlApp class.
        /// &lt;/summary&gt;
        private SampleHtmlApp()
        {
            HideSilverlightPlugin();

            // Creates a new managed HTML control
            _myUserInterface = new MyUserControl();

            // Appends the control to the web page body
            WebPage.Document.Body.AppendChild(_myUserInterface);
        }

        /// &lt;summary&gt;
        /// Takes the current Silverlight plugin instance and changes its size
        /// to be 0x0 pixels. Makes the same change to the hosting div element.
        /// This enables F5 testing of a managed HTML control app inside Visual
        /// Studio when using the standard TestPage.html in a Silverlight app.
        /// &lt;/summary&gt;
        private void HideSilverlightPlugin()
        {
            HtmlControl plugin = new HtmlControl(WebPage.Plugin);
            HtmlControl host = new HtmlControl(WebPage.Plugin.Parent);
            plugin.Width = 0;
            plugin.Height = 0;
            host.Width = 0;
            host.Height = 0;
        }
    }
}</pre>
</div>
<p>You can call the Run() method from anywhere in your Silverlight application &#8211; both can co-exist without issue. However, I&#8217;ve just replaced the RootVisual call in the Application_Startup method to demonstrate this example:</p>
</p>
<div class="wlWriterSmartContent" id="scid:887EC618-8FBE-49a5-A908-2339AF2EC720:61ccbf1e-736d-499d-b9a7-6b4c23dd6cf9" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px">
<pre class="c-sharp" name="code">        public App()
        {
            this.Startup += this.Application_Startup;
            this.UnhandledException += this.Application_UnhandledException;

            InitializeComponent();
        }

        private void Application_Startup(object sender, StartupEventArgs e)
        {
            SampleHtmlApp.Run();
        }</pre>
</div>
<p>Here is this simple HTML application (powered by Silverlight) running on OS X 10.5 in the Safari web browser:</p>
<p><img alt="The app running in Safari." src="http://media.jeff.wilcox.name/blog/dom/SafariTime.png" /> </p>
<p><strong>Appending a managed control tree to HtmlElements</strong></p>
<p>Thanks to an extension method, you can append a managed HTML control (that inherits from HtmlControlBase) to the standard HtmlElement inside Silverlight as if the control <em>is </em>an HtmlElement:</p>
<p><img alt="The extension method on HtmlElement::AppendChild." src="http://media.jeff.wilcox.name/blog/dom/ExtensionMethod.png" /></p>
<p>The managed control wrapper actually tracks any changes (styles, properties, child controls) to the control and waits until it is inserted into the live web page tree to apply the properties and create the child elements.</p>
<p>At the end of the day there are a <em>lot</em> of types involved here, bridging several layers of abstraction. This is definitely <em>not</em> a &quot;lightweight&quot; solution.</p>
<p><img alt="Looking at the abstractions." src="http://media.jeff.wilcox.name/blog/dom/HtmlObjectRelationDiagram.png" /></p>
<h3>These bits are in use today</h3>
<p>One of the key features of the in-browser <a href="http://code.msdn.microsoft.com/silverlightut/">Silverlight unit test framework</a> is that it exposes an interactive log inside the browser, using the HTML interoperability feature.</p>
<p>If you&#8217;ve used the Silverlight unit test framework, then you&#8217;ve used this managed HTML controls implementation without knowing it: to move away from &quot;spaghetti-code&quot;, we setup the log to use simple custom controls built on top of this framework.</p>
<p>Here&#8217;s a few screenshots of components, including a ProgressBar control:</p>
<p><img alt="The unit test log, powered by managed HTML controls." src="http://media.jeff.wilcox.name/blog/rc0/new_progress_bar.png" /> </p>
<p>Here&#8217;s the implementation of the ProgressBar:</p>
<div class="wlWriterSmartContent" id="scid:887EC618-8FBE-49a5-A908-2339AF2EC720:68bd98dd-0560-45ef-8e4e-c10c26651ba0" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px">
<pre class="c-sharp" name="code">using System;
using Microsoft.Silverlight.Testing.Html;

namespace Microsoft.Silverlight.Testing.UnitTesting.UI
{
    /// &lt;summary&gt;
    /// A control to visualize a test run's progress.
    /// &lt;/summary&gt;
    public partial class TestRunProgress : HtmlDiv
    {
        /// &lt;summary&gt;
        /// The percent of the run that is complete.
        /// &lt;/summary&gt;
        private double _percent;

        /// &lt;summary&gt;
        /// The progress bar.
        /// &lt;/summary&gt;
        private HtmlDiv _progress;

        /// &lt;summary&gt;
        /// Initializes a new progress bar control.
        /// &lt;/summary&gt;
        public TestRunProgress() : base()
        {
            InitializeComponent();
        }

        /// &lt;summary&gt;
        /// Gets or sets the percent complete on a scale from 0 to 100.
        /// &lt;/summary&gt;
        public double PercentComplete
        {
            set
            {
                _percent = value;
                UpdateProgressBar();
            }

            get
            {
                return _percent;
            }
        }

        /// &lt;summary&gt;
        /// Sets the color of the progress bar.
        /// &lt;/summary&gt;
        /// &lt;param name="value"&gt;The color value.&lt;/param&gt;
        public void SetProgressColor(string value)
        {
            _progress.BackgroundColor = value;
        }

        /// &lt;summary&gt;
        /// Updates the progress bar.
        /// &lt;/summary&gt;
        private void UpdateProgressBar()
        {
            double width = (double)GetProperty(HtmlProperty.ClientWidth);
            if (width &lt;= 0)
            {
                return;
            }
            int round = (int) Math.Round(_percent * (width / 100));
            _progress.Width = round;
        }

        /// &lt;summary&gt;
        /// Initializes the web control.
        /// &lt;/summary&gt;
        private void InitializeComponent()
        {
            SetStyleAttribute(CssAttribute.Position, "relative");
            _progress = new HtmlDiv();
            _progress.SetStyleAttribute(CssAttribute.Position, "absolute");
            _progress.Position.Left = _progress.Position.Top = _progress.Position.Bottom = 0;
            SetProgressColor(Color.Black);
            MakeTransparent(_progress, 25);
            Controls.Add(_progress);
        }

        /// &lt;summary&gt;
        /// Makes a control transparent.  Works with several browsers.
        /// &lt;/summary&gt;
        /// &lt;param name="control"&gt;The control.&lt;/param&gt;
        /// &lt;param name="opacity"&gt;The opacity amount.&lt;/param&gt;
        private static void MakeTransparent(HtmlControl control, int opacity)
        {
            control.SetStyleAttribute("filter", "alpha(opacity=" + opacity + ")");
            control.SetStyleAttribute("-moz-opacity", "." + opacity);
            control.SetStyleAttribute("opacity", "." + opacity);
        }
    }
}</pre>
</div>
<p>Clicking on a test method name expands a details drill-down full of stats and information, including links that can be clicked to retry tests and display easy-to-copy details:</p>
<p><img alt="The unit test log with details expanded." src="http://media.jeff.wilcox.name/blog/rc0/new_expander_details.png" /> </p>
<h3>Download the bits</h3>
<p>Since this is only a concept, and not something you would want to use in a production application, the bits are currently only available as part of the <a href="http://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=silverlightut&amp;DownloadId=3274">Silverlight unit test framework download</a> for the Silverlight 2 Release Candidate 0.</p>
<p>The implementation is not a complete framework, but rather a minimal set that enables basic functionality: links, buttons, and displaying and creating HTML elements. It does not contain a rich web forms implementation, cool validation controls, or anything like that.</p>
<p>In the future I may make the concept available as a download separate from the test framework, but today I want to make it clear that it <strong>isn&#8217;t something that is ready to really be used in everyday web applications</strong>&#8230; so hopefully the total size of the test framework assembly will discourage that [81kb]!</p>
<p>It is totally unsupported, to be considered prototype code.</p>
<p>Here&#8217;s the set of types and enums in the namespace today. You&#8217;ll see that it is a minimal set, and isn&#8217;t including a lot of the typical HTML controls like check boxes, forms, or web form controls. There&#8217;s room to innovate, but the value may not be there:</p>
<p><img alt="List of types in the Microsoft.Silverlight.Testing.Html namespace." src="http://media.jeff.wilcox.name/blog/dom/TypeList.png" /> </p>
<p>Do let me know if you like it, or build anything noteworthy, in the comments, and I will post a follow up in the future.</p>
<h3>Other ideas</h3>
<p>There is potential for the concept in some apps, and I&#8217;m sure some really brilliant folks out there could do any of the following things that&#8217;ve come across my mind:</p>
<ul>
<li>Writing an ASP.NET-style XML parser using System.Xml.Linq, enabling you to embed .aspx-like pages inside your application to enable generating managed HTML control trees at runtime </li>
<li>Integrating with XAML, so a XAML page could contain a managed HTML control tree </li>
<li>Writing a compatibility layer that would allow custom ASP.NET controls to run inside Silverlight </li>
<li>Integrating or porting popular AJAX functionality (animations, rich control behaviors) </li>
<li>Writing applications that live as a .Xap file at your CDN or Amazon S3, and access cross-domain web services for any data needs, combined with isolated storage </li>
</ul>
<p>I&#8217;ve built a number of fun applications using this framework and think it&#8217;s a neat concept, I will share those sometime&#8230; </p>
<p><em>Special thanks to Hao Kung, Huangli Wu, Stefan Schackow, and Wilco Bauwer for their excellent work in shipping the amazing HTML DOM feature inside Silverlight 2!</em></p>
<p><em>Hope you find this interesting,<br />
    <br />-Jeff</em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.jeff.wilcox.name/2008/10/html-controls-for-silverlight/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>If you can do it in JavaScript, you can do it in managed Silverlight .NET code</title>
		<link>http://www.jeff.wilcox.name/2008/09/do-it-in-js-and-cs/</link>
		<comments>http://www.jeff.wilcox.name/2008/09/do-it-in-js-and-cs/#comments</comments>
		<pubDate>Sun, 28 Sep 2008 23:23:49 +0000</pubDate>
		<dc:creator>Jeff Wilcox</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://www.jeff.wilcox.name/2008/09/28/do-it-in-js-and-cs/</guid>
		<description><![CDATA[Just because you can do something doesn&#8217;t mean that you should do something. Just because you can get Quake to run on your iPhone doesn&#8217;t mean that&#8217;s the best way to do things. But it&#8217;s pretty cool! Now that we&#8217;re clear on that one, this is the part where I show you that you can [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://media.jeff.wilcox.name/blog/rc0/JSandCSshirt.png" align="right"/> Just because you <em>can</em> do something doesn&#8217;t mean that you <em>should</em> do something. Just because you can get <a href="http://search.live.com/results.aspx?q=quake+iphone&amp;">Quake to run on your iPhone</a> doesn&#8217;t mean that&#8217;s the best way to do things. But it&#8217;s pretty cool!</p>
<p>Now that we&#8217;re clear on that one, this is the part where I show you that you can do a ton of stuff in Silverlight, through the JavaScript interoperability features.</p>
<p>Reaching out to the browser can help you improve the fit and finish of your Silverlight application and to integrate with existing services.</p>
<p>So, if you can do it in AJAX/JavaScript, you can totally do it in your Silverlight application when it is hosted in a web browser.</p>
<p>Reasons not to use the &#8220;HTML DOM bridge&#8221; (JavaScript interoperability features) in Silverlight:</p>
<ul>
<li>Feels &#8220;Hacky&#8221;  </li>
<li>Leads to spaghetti code &#8211; the calls are very procedural and you lose the nice strongly typed features of your .NET language of choice  </li>
<li>One line of JavaScript often takes 3 or 4 lines of managed code to accomplish the same thing via the interop syntax  </li>
<li>The rich presentation framework in Silverlight is pretty awesome &#8211; you should use it!  </li>
<li>Potential performance implications having JavaScript &#8211; native code &#8211; managed code all involved with timers, marshalling, etc.  </li>
<li>Can just use JavaScript without requiring the Silverlight 2 runtime</li>
</ul>
<p>Reasons to use it:</p>
<ul>
<li>Interact with the web browser host: set the page title, alter the plugin, add dynamic HTML content on the fly  </li>
<li>Bridge classic web applications, AJAX apps, and rich Silverlight  </li>
<li>Can replicate the experience of a server-side application, with web forms, HTML elements, and more &#8211; all on the client-side, without having to go back to the server to run an ASP.NET or PHP application  </li>
<li>A lot of analytics and advertising systems are exposed great in JavaScript</li>
</ul>
<p>What follows is a list of some previously covered articles and examples. They may be out of date; for instance, in the Release Candidate of Silverlight, you now use the ScriptObjectCollection instead of the HtmlElementCollection. Mike Snow has a <a href="http://silverlight.net/blogs/msnow/archive/2008/09/25/silverlight-version-2-rc0-release.aspx">nice list of the breaking changes</a>.</p>
<p><strong>Access and create JavaScript arrays from managed code</strong></p>
<p>You <a href="http://www.jeff.wilcox.name/2008/04/10/js-arrays/">can access JavaScript arrays</a>, but because of the loosely-defined, &#8220;do anything you want in JavaScript&#8221; way that things work, it leaves you with pretty unattractive managed code.</p>
<p><a href="http://www.jeff.wilcox.name/2008/04/10/js-arrays/">VB samples are here</a>. Some C# samples:</p>
<div class="wlWriterSmartContent" id="scid:887EC618-8FBE-49a5-A908-2339AF2EC720:623ebebf-f579-45c6-a719-94dd7706aeda" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px">
<pre class="c-sharp" name="code">// Create an array
var array = (ScriptObject) HtmlPage.Window.Eval("[10, 9, 8, 7, 6 ];");

// Get the length of an array
int length = (int)((double)array.GetProperty("length"));

// Return a single element by index
var singleElement = array.GetProperty(index.ToString())</pre>
</div>
<p><strong>Resize the Silverlight plugin</strong></p>
<p>You can <a href="http://www.jeff.wilcox.name/2008/08/24/quickzeropixel/">change the size of the plugin and its host element</a>. Here&#8217;s some Visual Basic that makes a &#8220;zero-pixel&#8221; plugin:</p>
<div class="wlWriterSmartContent" id="scid:887EC618-8FBE-49a5-A908-2339AF2EC720:1caf3e27-9015-4391-904a-71a87666cecd" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px">
<pre class="vb" name="code">Imports System.Windows.Browser

Namespace System.Windows.Browser
    Public Class ZeroPixelPlugin
        ''' &lt;summary&gt;
        ''' Resizes the Silverlight plugin and its host element to be zero pixels
        ''' in width and height. Only really useful for HTML
        ''' &lt;/summary&gt;
        ''' &lt;remarks&gt;&lt;/remarks&gt;
        Public Shared Sub HideSilverlightPlugin()
            Dim plugin As HtmlElement = HtmlPage.Plugin
            Dim host As HtmlElement = plugin.Parent
            plugin.SetStyleAttribute("width", "0")
            plugin.SetStyleAttribute("height", "0")
            host.SetStyleAttribute("width", "0")
            host.SetStyleAttribute("height", "0")
        End Sub
    End Class
End Namespace</pre>
</div>
<p><strong>Get information about the browser and physical screen</strong></p>
<p>Wondering what the color depth is of your end users? Want to work with the available screen size? All this information is exposed by JavaScript and you can easily read the values in C#.</p>
<p>Here&#8217;s a <a href="http://www.jeff.wilcox.name/2008/06/24/browserscreeninformation/">simple static class</a> that does the work for you. The class takes care of the differences between the NPAPI web browsers and Internet Explorer, so your application doesn&#8217;t need to worry about it so much.</p>
<p><a href="http://www.jeff.wilcox.name/2008/06/24/browserscreeninformation/"><img src="http://media.jeff.wilcox.name/blog/rc0/BrowserScreenInformationDiagram.png"/></a> </p>
<p>&nbsp;<strong>Store text in the clipboard</strong></p>
<p>If you have information that you want your end users to be able to copy into the clipboard, you only have a few options:</p>
<ul>
<li>Place the text in a TextBox control, allowing a user to select and press Control + C or Command + C to copy it into their clipboard
</li>
<li>Use interop features to talk to the web browser, or other plugins</li>
</ul>
<p><a href="http://www.jeff.wilcox.name/2008/05/21/clipboard-access/">Here&#8217;s a solution</a> that uses the browser APIs in IE, and another plugin if you&#8217;re on a non-IE browser. It isn&#8217;t perfect, but it&#8217;s an interesting hack.</p>
<p><strong>Generate an entire HTML/AJAX-style user interface</strong></p>
<p>You can write complete applications, just like an AJAX app, using managed code. Your business logic and other components benefit from strongly typed, easy-to-edit C#. Your application can be delivered through a .Xap, and doesn&#8217;t have any server side dependencies if it is written just right.</p>
<p>Here was a <a href="http://www.jeff.wilcox.name/2008/04/01/link-cloud/">homepage &#8220;link cloud&#8221; app</a>. It hasn&#8217;t been updated in a while, but most of the code should work without changes in the release candidate.</p>
<p><a href="http://www.jeff.wilcox.name/2008/04/01/link-cloud/"><img src="http://media.jeff.wilcox.name/blog/view/apps/home/safari-home.png"/></a> </p>
<p>Some of the things the app and the post show:</p>
<ul>
<li>Creating and managing HTML elements in .NET
</li>
<li>Attaching and working with HTML DOM events
</li>
<li>Using IsolatedStorage for saving information on the local machine</li>
</ul>
<p><strong>Interface with web analytics software</strong></p>
<p>A while back (yeah, Silverlight 1.1 days) I posted about <a href="http://www.jeff.wilcox.name/2007/10/01/google-analytics-with-silverlight/">interfacing with Google Analytics / Urchin</a>. Although the information is still useful, Google did make some major updates to the APIs, so I&#8217;d recommend not using the Urchin implementation in the post.</p>
<p><strong>Anything else cool?</strong></p>
<p>If you&#8217;re using the DOM bridge to do some interesting stuff, feel free to post a link here &#8211; I&#8217;d like to post about the neat uses at some point in the near future.</p>
<p>Well, I hope that gets you started working with the interop features a little more. Done right, you can start wearing a T-shirt the says &#8220;I do it in JavaScript&#8230; <em>AND</em> in .NET!&#8221;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jeff.wilcox.name/2008/09/do-it-in-js-and-cs/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Code display: Moving back from screen captures to text</title>
		<link>http://www.jeff.wilcox.name/2008/05/blog-syntax/</link>
		<comments>http://www.jeff.wilcox.name/2008/05/blog-syntax/#comments</comments>
		<pubDate>Wed, 21 May 2008 18:15:01 +0000</pubDate>
		<dc:creator>Jeff Wilcox</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://www.jeff.wilcox.name/2008/05/21/blog-syntax/</guid>
		<description><![CDATA[Blog authors have always struggled (well, at least I have!) with the issue of pasting in code samples. In the past I&#8217;ve tried a few things, from using Visual Studio to WordPress formatting tools to Windows Live Writer plugins for code.&#160; I settled on using screen captures, with the intention of attaching the code projects [...]]]></description>
			<content:encoded><![CDATA[<p>Blog authors have always struggled (well, at least I have!) with the issue of pasting in code samples. In the past I&#8217;ve tried a few things, from using <a href="http://fluxcapacity.net/2007/07/22/one-solution-to-wordpress-code-snippet-formatting-problems/" target="_blank">Visual Studio to WordPress formatting tools</a> to Windows Live Writer plugins for code.&#160; I settled on using screen captures, with the intention of attaching the code projects as downloadable text files.</p>
<p>Today, I&#8217;m making an attempt to move back to raw &lt;pre /&gt; tags, populated with text, that should be formatted on the fly by modern web browsers.&#160; This is great for folks that visit my blog, but does deliver a less-than-attractive experience for newsreaders.</p>
<p>This is accomplished using:</p>
<ul>
<li><a href="http://windowslivewriter.spaces.live.com/" target="_blank">Windows Live Writer</a> </li>
<li>Coskun Sunali&#8217;s <a href="http://gallery.live.com/liveItemDetail.aspx?li=ce0ed754-9088-4bdf-974d-bb3f67726b62&amp;bt=9&amp;pl=8" target="_blank">Insert Tag Snippet</a> plugin for Writer </li>
<li>Alex Gorbatchev&#8217;s <a href="http://code.google.com/p/syntaxhighlighter/" target="_blank">syntaxhighlighter</a> </li>
</ul>
<p>Scott Guthrie&#8217;s monster blog posts are amazing, and the look is consistent everywhere.&#160; This is because they&#8217;re full of Visual Studio + code screen captures.&#160; I&#8217;m sure the syntax highlighter screen caps set off the latest wave of .NET developer&#8217;s color customizing that&#8217;s on all the dev&#8217;s machines that I&#8217;ve seen.</p>
<p>Here&#8217;s what C# code used to look like on my blog:</p>
<p><img src="http://media.jeff.wilcox.name/blog/dom/js2.png" /> </p>
<p>On to samples of the new system:</p>
<h3>C#</h3>
<div class="wlWriterSmartContent" id="scid:887EC618-8FBE-49a5-A908-2339AF2EC720:b521b14b-1cf4-4847-950d-87601d79bcb3" style="padding-right: 0px; display: inline; padding-left: 0px; float: none; padding-bottom: 0px; margin: 0px; padding-top: 0px">
<pre name="code" class="c-sharp">    [TemplatePart(Name = HyperlinkButton.StateDisabledName, Type = typeof(Storyboard))]
    public partial class HyperlinkButton : ButtonBase
    {
        #region NavigateUri
        /// &lt;summary&gt;
        /// Gets or sets a URI to navigate to when the link is clicked.
        /// &lt;/summary&gt;
        [TypeConverter(typeof(UriTypeConverter))]
        public Uri NavigateUri
        {
            get { return GetValue(NavigateUriProperty) as Uri; }
            set { SetValue(NavigateUriProperty, value); }
        }</pre>
</div>
<h3>Visual Basic</h3>
<div class="wlWriterSmartContent" id="scid:887EC618-8FBE-49a5-A908-2339AF2EC720:36af7b43-c757-4e9f-ad16-8a668e6384ec" style="padding-right: 0px; display: inline; padding-left: 0px; float: none; padding-bottom: 0px; margin: 0px; padding-top: 0px">
<pre name="code" class="vb">Imports Microsoft.Silverlight.Testing
Imports Microsoft.VisualStudio.TestTools.UnitTesting

&lt;TestClass()&gt; _
Public Class Class1

    ' This is a super simple test
    Public Sub SimpleTest()
        Assert.IsTrue(True)
    End Sub

End Class</pre>
</div>
<h3>JavaScript</h3>
<div class="wlWriterSmartContent" id="scid:887EC618-8FBE-49a5-A908-2339AF2EC720:2cab03b8-3029-4f01-8392-f0ed7051f7c7" style="padding-right: 0px; display: inline; padding-left: 0px; float: none; padding-bottom: 0px; margin: 0px; padding-top: 0px">
<pre name="code" class="js">var cssNode = document.createElement('link');
cssNode.type = 'text/css';
cssNode.rel = 'stylesheet';
cssNode.href = ss;
cssNode.media = 'screen';

// Append the new node
head.appendChild(cssNode);</pre>
</div>
<h3>XML</h3>
<div class="wlWriterSmartContent" id="scid:887EC618-8FBE-49a5-A908-2339AF2EC720:19c38a03-445d-4491-b382-c844a3e0caa4" style="padding-right: 0px; display: inline; padding-left: 0px; float: none; padding-bottom: 0px; margin: 0px; padding-top: 0px">
<pre name="code" class="xml">&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;items&gt;
  &lt;item type="photoset" id="395" owner="12037949754@N01"
		primary="6521" secret="5a3cc65d72" server="2"
		commentsold="1" commentsnew="1"
		views="33" photos="7" more="0"&gt;
    &lt;title&gt;A set of photos&lt;/title&gt;
    &lt;activity&gt;
      &lt;event type="comment"
			user="12037949754@N01" username="Bees"
			dateadded="1144086424"&gt;yay&lt;/event&gt;
    &lt;/activity&gt;
  &lt;/item&gt;
&lt;/items&gt;</pre>
</div>
<h3>XAML</h3>
<div class="wlWriterSmartContent" id="scid:887EC618-8FBE-49a5-A908-2339AF2EC720:484d377a-e11d-4caa-8183-edc50b8d09d1" style="padding-right: 0px; display: inline; padding-left: 0px; float: none; padding-bottom: 0px; margin: 0px; padding-top: 0px">
<pre name="code" class="xml">&lt;ResourceDictionary
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"&gt;

    &lt;!-- Default style for System.Windows.Controls.Button --&gt;
    &lt;Style TargetType="Button"&gt;
        &lt;Setter Property="IsEnabled" Value="true" /&gt;
        &lt;Setter Property="IsTabStop" Value="true" /&gt;
        &lt;Setter Property="Background" Value="#FF003255" /&gt;
        &lt;Setter Property="Foreground" Value="#FF313131" /&gt;
        &lt;Setter Property="MinWidth" Value="5" /&gt;
        &lt;Setter Property="MinHeight" Value="5" /&gt;
        &lt;Setter Property="Margin" Value="0" /&gt;
        &lt;Setter Property="HorizontalContentAlignment" Value="Center" /&gt;
        &lt;Setter Property="VerticalContentAlignment" Value="Center" /&gt;
        &lt;Setter Property="Cursor" Value="Arrow" /&gt;</pre>
</div>
<p>I&#8217;ll probably do some customizing of the highlighting brushes in the future, or see about porting the library to C# + Silverlight 2.&#160; Let me know what you think about this change as I begin posting some new content: a step in the right direction?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jeff.wilcox.name/2008/05/blog-syntax/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Homepage &#8220;link cloud&quot; application</title>
		<link>http://www.jeff.wilcox.name/2008/04/link-cloud/</link>
		<comments>http://www.jeff.wilcox.name/2008/04/link-cloud/#comments</comments>
		<pubDate>Wed, 02 Apr 2008 02:38:30 +0000</pubDate>
		<dc:creator>Jeff Wilcox</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[cloud]]></category>
		<category><![CDATA[dom]]></category>
		<category><![CDATA[html dom bridge]]></category>
		<category><![CDATA[link]]></category>
		<category><![CDATA[link cloud]]></category>
		<category><![CDATA[silverlight 2]]></category>

		<guid isPermaLink="false">http://www.jeff.wilcox.name/2008/04/01/link-cloud/</guid>
		<description><![CDATA[My new browser start page uses Silverlight to produce a simple link cloud.&#160; By targeting the rich class libraries of .NET that are available in Silverlight 2, the app loads quicker than a server-based solution, is useful, and very simple.&#160; The app I built is a good demonstration of the “zero pixel” Silverlight plugin concept: [...]]]></description>
			<content:encoded><![CDATA[<p>My new browser start page uses Silverlight to produce a simple link cloud.&nbsp; By targeting the rich class libraries of .NET that are available in Silverlight 2, the app loads quicker than a server-based solution, is useful, and very simple.&nbsp; The <a href="http://media.jeff.wilcox.name/apps/home/index.htm">app</a> I built is a good demonstration of the “zero pixel” Silverlight plugin concept: I’m using the HTML DOM bridge to create and manage all of the elements in the web page document.</p>
<p>The app has some key features:</p>
<ul>
<li>No dependencies on a web server, web service, or database server  </li>
<li>Links are true HTML links that get larger the more often they’re clicked.&nbsp; They can be added, removed, and rearranged  </li>
<li>Stores the link information locally, available to all browsers on the platform  </li>
<li>The data is yours: you can import/export the raw data to easily bring it to another of your computers</li>
</ul>
<p>Special thanks to <a href="http://d-struct.org/">Chris Gansen</a> for letting me borrow the specifics from his <a href="http://www.rubyonrails.org/">RoR</a> implementation of this application, it translated nicely to a client app.</p>
<p><a href="http://media.jeff.wilcox.name/apps/home/index.htm"><strong>Experience this application</strong></a><strong> live.</strong>&nbsp; <br />Since the local isolated storage is used, the links are only on your machine, the first time you use the app it’ll have no links.&nbsp; <a href="http://media.jeff.wilcox.name/apps/home/SampleData.txt">Click here</a> for a text file you can paste in using the import/export feature to load a set of sample links.&nbsp; I store my link cloud in <a href="http://mail.google.com/">GMail</a> so that I can always setup another machine in seconds from my mail account.</p>
<p><a href="http://media.jeff.wilcox.name/apps/home/index.htm"><img src="http://media.jeff.wilcox.name/blog/view/apps/home/safari-home.png"/></a></p>
<p>The .Xap file that represents the app is a miniscule 10kb.&nbsp; By comparison, a server-side version of this app can easily serve 40kb pages once the editing interface is included.&nbsp; The only hard-coded dependency is the stylesheet link that I’m injecting at runtime.</p>
<p>This uses many of the less sexy Silverlight 2 Beta 1 features:</p>
<ul>
<li><a href="http://msdn2.microsoft.com/en-us/library/system.windows.browser(VS.95).aspx">HTML DOM</a> interoperability: the bridge between managed code and the web browser, the entire underlying user interface is generated and managed by managed code  </li>
<li>Local <a href="http://msdn2.microsoft.com/en-us/library/system.io.isolatedstorage(VS.95).aspx">isolated storage</a>: By storing the data on the local machine, there&#8217;s no complex web service or database required  </li>
<li><a href="http://msdn2.microsoft.com/en-us/library/system.io.isolatedstorage.applicationsettings(VS.95).aspx">ApplicationSettings</a>: An easy-to-use way of storing data to the isolated storage area, there&#8217;s no need to deal with StringReaders and Stream manipulation code  </li>
<li>Zero pixel 0&#215;0 plugin: By resizing the Silverlight plugin to occupy no space upon load, the application demonstrates the capabilities of managed code without the use of controls and the rich presentation framework  </li>
<li>.Xap package is easy to deploy and store on a content delivery network, file or web server</li>
</ul>
<p>Although I’m using ApplicationSettings type to store the link cloud data, I just wanted to get this up and running, so I’m not following any best practices, and am actually serializing the cloud data myself into a single string.</p>
<p><strong>Downloads</strong><br /><a href="http://media.jeff.wilcox.name/apps/home/index.htm">Live app</a> (10k) – feel free to use this for your homepage<br /><a href="http://media.jeff.wilcox.name/apps/home/SampleData.txt">Sample data file</a> (2k) – can import for sample data<br /><a href="http://media.jeff.wilcox.name/apps/home/LinkPage.zip">Source code</a> (39k) – Zip file with the Visual Studio project, just barebones code, no good code in here<br /><a href="http://media.jeff.wilcox.name/apps/home/LinkPage.cs.txt">LinkPage.cs</a> (21k) – Primary source file</p>
<p>Briefly jumping into the code, you’ll find that everything’s really contained inside <a href="http://media.jeff.wilcox.name/apps/home/LinkPage.cs.txt">LinkPage.cs</a>.&nbsp; Some of the things inside the file that I’d like to call out:</p>
<h3>Setting the page title</h3>
<p><img src="http://media.jeff.wilcox.name/blog/linkcloud/lc1.png"/> </p>
<p>This updates the title displayed in the browser’s window.&nbsp; It’s equivalent to the simple JavaScript call of setting document.title.&nbsp; The <a href="http://msdn2.microsoft.com/en-us/library/system.windows.browser.htmldocument(VS.95).aspx">HtmlDocument</a> type, in the System.Windows.Browser namespace, maps directly.</p>
<h3>Reading from ApplicationSettings and changing the &lt;body /&gt; element’s CSS class</h3>
<p><img src="http://media.jeff.wilcox.name/blog/linkcloud/lc2.png"/> </p>
<p>The <a href="http://msdn2.microsoft.com/en-us/library/system.io.isolatedstorage.applicationsettings(VS.95).aspx">ApplicationSettings type</a> is a nice shortcut to having to use Isolated Storage, and is used to store two settings for this link cloud application: the color used for the stylesheet (there’s a few themes available), and the actual link cloud data.&nbsp; The data’s updated and saved whenever a change occurs to avoid having to write the changes at one time.</p>
<h3>Injecting a Stylesheet element</h3>
<p><img src="http://media.jeff.wilcox.name/blog/linkcloud/lc3.png"/> </p>
<p>Pretty standard document object model workflow here: the code’s nothing but spaghetti.&nbsp; The new element is created, attributes set, and then appended.&nbsp; There’s no need to keep a reference to the element unless you intend on interacting with it later.</p>
<p>There’s a built-in property HtmlPage.Document.Body that can be used to return the &lt;body /&gt; element on the web page, but not one for the &lt;head /&gt; element.&nbsp; The code above successfully will add to the head of the page, assuming the head exists.</p>
<h3>Prompting the user for confirmation</h3>
<p>A lot of AJAX applications use ‘confirm(…)’ to get quick verification before deleting data permanently.&nbsp; Both <a href="http://msdn2.microsoft.com/en-us/library/system.windows.browser.htmlwindow.alert(VS.95).aspx">Alert</a> and <a href="http://msdn2.microsoft.com/en-us/library/system.windows.browser.htmlwindow.confirm(VS.95).aspx">Confirm</a> are available within the HtmlWindow type in the HTML DOM bridge, so it’s super easy to do the same in managed code:</p>
<p><img src="http://media.jeff.wilcox.name/blog/linkcloud/lc5.png"/> </p>
<h3>Navigating to a new web page</h3>
<p><img src="http://media.jeff.wilcox.name/blog/linkcloud/lc6.png"/> </p>
<p>The links in the link cloud have the href attribute set to point to the destination page – this enables the end user to open the links in a new tab or window easily.&nbsp; However, the click count is only incremented when the link is clicked since the onclick event is used to track and increment the underlying hit data.</p>
<p>The <a href="http://msdn2.microsoft.com/en-us/library/system.windows.browser.htmlwindow.navigate(VS.95).aspx">Navigate</a> method of <a href="http://msdn2.microsoft.com/en-us/library/system.windows.browser.htmlwindow(VS.95).aspx">HtmlWindow</a> is used to go to the requested URI.</p>
<h3>Creating an HTML button and hooking up to its Click event</h3>
<p>The form that’s created on the page uses managed event handlers in C# to process events and read data:</p>
<p><img src="http://media.jeff.wilcox.name/blog/linkcloud/lc4.png"/> </p>
<p>The button above is used to add the form data into the cloud as a new link.&nbsp; If you examine it you’ll also see use of SetProperty, SetStyleAttribute, GetProperty, and more – these are all at parity with traditional AJAX JavaScript coding, so it should be quite familiar.&nbsp; </p>
<p><a href="http://www.wilcob.com/Wilco/News/silverlight-interoperability.aspx">Wilco</a> has a lot <a href="http://www.wilcob.com/Wilco/News/silverlight-interoperability.aspx">more information</a> on the subject of the HTML DOM interoperability feature in Silverlight 2.</p>
<p><a href="http://media.jeff.wilcox.name/apps/home/index.htm"><img src="http://media.jeff.wilcox.name/blog/view/apps/home/ie-home.png"/></a> </p>
<p><em>Hope you find this useful!</em></p>
<p><em>Looking at the spaghetti code, it’s clear that some kind of helpful “managed HTML object” library would make creating this style of application a lot easier in the future.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.jeff.wilcox.name/2008/04/link-cloud/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Some great Silverlight posts on the DataGrid, HtmlTextBlock, right clickin&#8217;, and more</title>
		<link>http://www.jeff.wilcox.name/2008/03/silverlight-posts-1/</link>
		<comments>http://www.jeff.wilcox.name/2008/03/silverlight-posts-1/#comments</comments>
		<pubDate>Fri, 21 Mar 2008 07:30:29 +0000</pubDate>
		<dc:creator>Jeff Wilcox</dc:creator>
				<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://www.jeff.wilcox.name/2008/03/20/some-great-silverlight-posts-on-the-datagrid-htmltextblock-right-clickin-and-more/</guid>
		<description><![CDATA[There’s been some sweet blog activity this past week, so in case you aren’t subscribed to all of these blogs, take a look: Using the Silverlight DataGridScott Morrison gets you started using the DataGrid, autogenerating columns are great!&#160; Also useful if you’re new to the data binding in Silverlight. Isolated StorageWilco Bauwer is the developer [...]]]></description>
			<content:encoded><![CDATA[<p>There’s been some sweet blog activity this past week, so in case you aren’t subscribed to all of these blogs, take a look:</p>
<p><strong>Using the Silverlight DataGrid</strong><br /><a href="http://blogs.msdn.com/scmorris/">Scott Morrison</a> gets you started <a href="http://blogs.msdn.com/scmorris/archive/2008/03/21/using-the-silverlight-datagrid.aspx">using the DataGrid</a>, autogenerating columns are great!&nbsp; Also useful if you’re new to the data binding in Silverlight.</p>
<p><strong>Isolated Storage</strong><br /><a href="http://www.wilcob.com/Wilco/News/Default.aspx">Wilco Bauwer</a> is the developer on our team who’s done much of the isolated storage API work that’s new to Silverlight, he has a <a href="http://www.wilcob.com/Wilco/News/isolatated-storage-in-Silverlight.aspx">quick look at IsoStore</a> in the beta.&nbsp; Also check out his <a href="http://www.wilcob.com/Wilco/News/silverlight-interoperability.aspx">detailed interoperability post</a>, all about the <a href="http://msdn2.microsoft.com/en-us/library/system.windows.browser(VS.95).aspx">HTML DOM bridge feature</a> that is much more powerful than that delivered last year in the v1.1 alpha.</p>
<p><strong>Right-click<br /></strong><a href="http://blois.us/blog/">Peter Blois</a> has a good Windows Internet Explorer and Firefox <a href="http://blois.us/blog/2008/03/last-week-i-made-2-minesweeper-games.html">right-click bubbling implementation</a>.&nbsp; Above, his minesweeper implementation that lets you flag using a right-click.</p>
<p><a href="http://blois.us/blog/2008/03/last-week-i-made-2-minesweeper-games.html"><img src="http://media.jeff.wilcox.name/blog/silverlight/minesweeper.png"/></a>&nbsp;</p>
<p><strong>HtmlTextBlock<br /></strong><a href="http://blogs.msdn.com/delay/">David Anson</a> revises <a href="http://blogs.msdn.com/delay/archive/2008/03/17/continuing-support-for-simple-html-display-in-silverlight-htmltextblock-sample-updated-for-silverlight-2-beta-1.aspx">his HtmlTextBlock control</a>, now supporting Beta 1 of Silverlight 2.&nbsp; Good stuff!&nbsp; Above is his sample app, available for download as an attachment on his post.</p>
<p><strong>Synchronous network stack<br /></strong>Although personally I’m a major fan of the asynchronous-only network stack exposed by Silverlight 2, some people are definitely in favor of synchronous calls, so <a href="http://silverlight.net/forums/t/11508.aspx">this forum post</a> on Silverlight.net by <a href="http://silverlight.net/forums/t/11508.aspx">Jack Bond</a> might get you where you’ll looking to go.</p>
<p><em>Related,<br /></em>I’ll work to release my 100% asynchronous <a href="http://www.flickr.com/services/api/">Flickr API</a> implementation in the coming weeks, so look for that.</p>
<p><strong>HttpUtility</strong><br />I’ve had a few people ask recently how to URL encode strings in Silverlight.&nbsp; Within the System.Windows.Browser namespace, there’s the <a href="http://msdn2.microsoft.com/en-us/library/system.windows.browser.httputility(VS.95).aspx">HttpUtility</a> type which is very similar to ASP.NET’s, so there you’ll find HtmlDecode, HtmlEncode, UrlDecode, &amp; UrlEncode.</p>
<p><strong>Using a production web server</strong><br /><a href="http://blogs.msdn.com/brada/default.aspx">Brad Abrams</a> provides <a href="http://blogs.msdn.com/brada/archive/2008/03/14/using-silverlight-2-on-a-production-web-server.aspx">some hosting tips</a> for making sure that .xap, .xaml, and other filetypes can be served with some server configuration tips.</p>
<p>Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jeff.wilcox.name/2008/03/silverlight-posts-1/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
