<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://weblogs.asp.net/utility/FeedStylesheets/atom.xsl" media="screen"?><feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en"><title type="html">Fredrik Normén</title><subtitle type="html">ASP.NET, AJAX, Silverlight, RIA, Architecture, Clean Code</subtitle><id>http://weblogs.asp.net/fredriknormen/atom.aspx</id><link rel="alternate" type="text/html" href="http://weblogs.asp.net/fredriknormen/default.aspx" /><link rel="self" type="application/atom+xml" href="http://weblogs.asp.net/fredriknormen/atom.aspx" /><generator uri="http://communityserver.org" version="3.0.20510.895">Community Server</generator><updated>2009-08-20T11:30:00Z</updated><entry><title>Fluent-API to add ActionFilters to Controllers – ASP.NET MVC Part 2</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/fredriknormen/archive/2009/11/07/fluent-api-to-add-actionfilters-to-controllers-asp-net-mvc-part-2.aspx" /><id>http://weblogs.asp.net/fredriknormen/archive/2009/11/07/fluent-api-to-add-actionfilters-to-controllers-asp-net-mvc-part-2.aspx</id><published>2009-11-07T09:39:30Z</published><updated>2009-11-07T09:39:30Z</updated><content type="html">&lt;p&gt;I’m working with my Fluent-API for adding Action Filters to Controllers and Action Methods. In my &lt;a href="http://weblogs.asp.net/fredriknormen/archive/2009/11/07/fluent-api-to-add-actionfilters-to-controller-in-asp-net-mvc.aspx"&gt;previous post&lt;/a&gt;, I created a new instance of each Action Filter and add it to an Action Method or Controller. Based on how the Action Filters are often implemented they don’t or shouldn’t keep any state, so in that case I don’t need to create a new instance of the same Action Filter with the same configuration for each Action Method I want to add it to. I also want to have an option to have a better overview of which Action Filter is added to which Controllers and Action Methods. I have added to methods, AddFilterToControllers and AddFilterToActions:&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;pre class="csharpcode"&gt;            .AddFilterToActions(&lt;span class="kwrd"&gt;new&lt;/span&gt; HandleErrorAttribute(),
                                c=&amp;gt; c.About(),
                                c=&amp;gt; c.Index());
            .AddFilterToActions(&lt;span class="kwrd"&gt;new&lt;/span&gt; OutOfMemoryException(),
                                c=&amp;gt; c.About());
             .AddFilterToActions(&lt;span class="kwrd"&gt;new&lt;/span&gt; HandleErrorAttribute() ...,
                                c=&amp;gt; c.MyMethod());

            .AddFilterToControllers(&lt;span class="kwrd"&gt;new&lt;/span&gt; HandleErrorAttribute(),
                                    &lt;span class="kwrd"&gt;typeof&lt;/span&gt;(HomeController),
                                    &lt;span class="kwrd"&gt;typeof&lt;/span&gt;(Controller));&lt;/pre&gt;
&lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;The code is not yet available due to some more changes and testing.&lt;/p&gt;
&lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7248779" width="1" height="1"&gt;</content><author><name>Fredrik N</name><uri>http://weblogs.asp.net/members/Fredrik-N.aspx</uri></author><category term="ASP.Net" scheme="http://weblogs.asp.net/fredriknormen/archive/tags/ASP.Net/default.aspx" /><category term="ASP.NET MVC" scheme="http://weblogs.asp.net/fredriknormen/archive/tags/ASP.NET+MVC/default.aspx" /></entry><entry><title>Fluent-API to add ActionFilters to Controller in ASP.NET MVC</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/fredriknormen/archive/2009/11/07/fluent-api-to-add-actionfilters-to-controller-in-asp-net-mvc.aspx" /><id>http://weblogs.asp.net/fredriknormen/archive/2009/11/07/fluent-api-to-add-actionfilters-to-controller-in-asp-net-mvc.aspx</id><published>2009-11-07T00:45:00Z</published><updated>2009-11-07T00:45:00Z</updated><content type="html">&lt;P&gt;&lt;STRONG&gt;Note: The name of the classes and the methods are just temporary and may change, I’m so bad when it comes to naming classes and methods. The source code is simple and haven’t done so much refactoring etc. Just wanted to see if I could get it to work, so please have that in mind.&lt;/STRONG&gt;&lt;BR&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;EDIT:&amp;nbsp;Working with new methods&amp;nbsp;to get a better overview of Action Filters added and also reusing AcitonFitlers,&amp;nbsp;you can read about it &lt;/STRONG&gt;&lt;A href="http://weblogs.asp.net/fredriknormen/archive/2009/11/07/fluent-api-to-add-actionfilters-to-controllers-asp-net-mvc-part-2.aspx" mce_href="http://weblogs.asp.net/fredriknormen/archive/2009/11/07/fluent-api-to-add-actionfilters-to-controllers-asp-net-mvc-part-2.aspx"&gt;&lt;STRONG&gt;here&lt;/STRONG&gt;&lt;/A&gt;&lt;STRONG&gt;.&lt;/STRONG&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR&gt;When we create controllers for our ASP.NET MVC application we can also add Action Filters to handle cross-cutting concerns, like Authorization, Error handling and Caching etc. If we want to have Error handling on every controller we need to add the HandleErrorAttribute to all controllers, like this: &lt;BR&gt;&lt;BR&gt;&lt;BR&gt;&lt;/P&gt;&lt;PRE class=csharpcode&gt;[HandleError] 
&lt;SPAN class=kwrd&gt;public&lt;/SPAN&gt; MyController : Controller 
{ 
}&lt;BR&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;BR&gt;By adding Action Filters by using attributes it can be hard to get a good overview of which controllers that has the HandleErrorAttribute. The same regarding Action methods, for example if we have a lot of Controllers and want to see see all the Action methods that uses for example the OutputCacheAttribute, we need to go through all Controllers and methods, there is no easy way to get a simple overview of them.&lt;/P&gt;
&lt;P&gt;Adding Action Filters to Action methods and Controllers also add some sort of “dependency” to action filters (not a big deal, though). I decided to try a way to add Action Filters to Controllers and Action methods in one single file, so I could get a better overview of which Controllers and Action methods uses what ActionFilter etc. Because ActionFitlers contains cross-cutting concerns I also wanted to move it away as attributes from the Controllers and Action methods so developers don’t need to care about the cross-cutting concerns during the creation of Controllers. instead add them later.&lt;/P&gt;
&lt;P&gt;I sort of used a Fluent-API for the configuration of ActionFilters, and the configuration is added to the Global.asax’s Application_Start event. Here is an example where I add the ErroHandler Action Filter to all Controllers Action Methods: &lt;BR&gt;&lt;BR&gt;&lt;BR&gt;&lt;/P&gt;
&lt;STYLE type=text/css&gt;.csharpcode {
	BACKGROUND-COLOR: #ffffff; FONT-FAMILY: consolas, "Courier New", courier, monospace; COLOR: black; FONT-SIZE: small
}
.csharpcode PRE {
	BACKGROUND-COLOR: #ffffff; FONT-FAMILY: consolas, "Courier New", courier, monospace; COLOR: black; FONT-SIZE: small
}
.csharpcode PRE {
	MARGIN: 0em
}
.csharpcode .rem {
	COLOR: #008000
}
.csharpcode .kwrd {
	COLOR: #0000ff
}
.csharpcode .str {
	COLOR: #006080
}
.csharpcode .op {
	COLOR: #0000c0
}
.csharpcode .preproc {
	COLOR: #cc6633
}
.csharpcode .asp {
	BACKGROUND-COLOR: #ffff00
}
.csharpcode .html {
	COLOR: #800000
}
.csharpcode .attr {
	COLOR: #ff0000
}
.csharpcode .alt {
	BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; WIDTH: 100%
}
.csharpcode .lnum {
	COLOR: #606060
}
&lt;/STYLE&gt;
&lt;PRE class=csharpcode&gt;ConfigActionFilter.ConfigController&amp;lt;Controller&amp;gt;() 
                  .AddFilterToController(&lt;SPAN class=kwrd&gt;new&lt;/SPAN&gt; HandleErrorAttribute());
&lt;/PRE&gt;
&lt;STYLE type=text/css&gt;.csharpcode {
	BACKGROUND-COLOR: #ffffff; FONT-FAMILY: consolas, "Courier New", courier, monospace; COLOR: black; FONT-SIZE: small
}
.csharpcode PRE {
	BACKGROUND-COLOR: #ffffff; FONT-FAMILY: consolas, "Courier New", courier, monospace; COLOR: black; FONT-SIZE: small
}
.csharpcode PRE {
	MARGIN: 0em
}
.csharpcode .rem {
	COLOR: #008000
}
.csharpcode .kwrd {
	COLOR: #0000ff
}
.csharpcode .str {
	COLOR: #006080
}
.csharpcode .op {
	COLOR: #0000c0
}
.csharpcode .preproc {
	COLOR: #cc6633
}
.csharpcode .asp {
	BACKGROUND-COLOR: #ffff00
}
.csharpcode .html {
	COLOR: #800000
}
.csharpcode .attr {
	COLOR: #ff0000
}
.csharpcode .alt {
	BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; WIDTH: 100%
}
.csharpcode .lnum {
	COLOR: #606060
}
&lt;/STYLE&gt;

&lt;P&gt;&lt;BR&gt;If I want to add an Action Filters to a specific Controller I just use the type of the Controller:&lt;BR&gt;&lt;BR&gt;&lt;BR&gt;&lt;/P&gt;&lt;PRE class=csharpcode&gt;ConfigActionFilter.ConfigController&amp;lt;HomeController&amp;gt;()
                              .AddFilterToController(&lt;SPAN class=kwrd&gt;new&lt;/SPAN&gt; HandleErrorAttribute());&lt;/PRE&gt;
&lt;STYLE type=text/css&gt;.csharpcode {
	BACKGROUND-COLOR: #ffffff; FONT-FAMILY: consolas, "Courier New", courier, monospace; COLOR: black; FONT-SIZE: small
}
.csharpcode PRE {
	BACKGROUND-COLOR: #ffffff; FONT-FAMILY: consolas, "Courier New", courier, monospace; COLOR: black; FONT-SIZE: small
}
.csharpcode PRE {
	MARGIN: 0em
}
.csharpcode .rem {
	COLOR: #008000
}
.csharpcode .kwrd {
	COLOR: #0000ff
}
.csharpcode .str {
	COLOR: #006080
}
.csharpcode .op {
	COLOR: #0000c0
}
.csharpcode .preproc {
	COLOR: #cc6633
}
.csharpcode .asp {
	BACKGROUND-COLOR: #ffff00
}
.csharpcode .html {
	COLOR: #800000
}
.csharpcode .attr {
	COLOR: #ff0000
}
.csharpcode .alt {
	BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; WIDTH: 100%
}
.csharpcode .lnum {
	COLOR: #606060
}
&lt;/STYLE&gt;

&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Note: The reason I don’t use XML and a XML meta data provider as a configuration is because I wanted to make the configuration type safe. If we use XML we can only get an exception if we spell something wrong at runtime.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;BR&gt;If I want to add Action Filters to Action Methods I can write something like this:&lt;/P&gt;&lt;PRE class=csharpcode&gt;&amp;nbsp;&lt;/PRE&gt;&lt;PRE class=csharpcode&gt;ConfigActionFilter.ConfigController&amp;lt;HomeController&amp;gt;()
                              .AddFilterToController(&lt;SPAN class=kwrd&gt;new&lt;/SPAN&gt; HandleErrorAttribute())
                              .AddFilterToAction(c =&amp;gt; c.About(),
                                                 &lt;SPAN class=kwrd&gt;new&lt;/SPAN&gt; MyActionFilterAttribute(),
                                                 &lt;SPAN class=kwrd&gt;new&lt;/SPAN&gt; MyOtherActionFilter() { Metadata=10 })
                              .AddFilterToAction(c =&amp;gt; c.Index(),
                                                 &lt;SPAN class=kwrd&gt;new&lt;/SPAN&gt; MyActionFilterAttribute());&lt;/PRE&gt;
&lt;STYLE type=text/css&gt;.csharpcode {
	BACKGROUND-COLOR: #ffffff; FONT-FAMILY: consolas, "Courier New", courier, monospace; COLOR: black; FONT-SIZE: small
}
.csharpcode PRE {
	BACKGROUND-COLOR: #ffffff; FONT-FAMILY: consolas, "Courier New", courier, monospace; COLOR: black; FONT-SIZE: small
}
.csharpcode PRE {
	MARGIN: 0em
}
.csharpcode .rem {
	COLOR: #008000
}
.csharpcode .kwrd {
	COLOR: #0000ff
}
.csharpcode .str {
	COLOR: #006080
}
.csharpcode .op {
	COLOR: #0000c0
}
.csharpcode .preproc {
	COLOR: #cc6633
}
.csharpcode .asp {
	BACKGROUND-COLOR: #ffff00
}
.csharpcode .html {
	COLOR: #800000
}
.csharpcode .attr {
	COLOR: #ff0000
}
.csharpcode .alt {
	BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; WIDTH: 100%
}
.csharpcode .lnum {
	COLOR: #606060
}
&lt;/STYLE&gt;

&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I didn’t wanted to use a string for the ActionMethod (AddFilterToAction(“About”)) because it would not be type safe. I want to get a warning or error while typing the code, so instead I created an Expression. The AddFilterToAction takes a params of FilterAttributes, so I can easy add several of Action Filters to an Action Method. The AddFilterToController method will add Action Filter to the Controller, just like adding an Action Filter attribute to the class definition, so all Action Methods within the Controller will use the Action Filter.&lt;/P&gt;
&lt;P&gt;I created a Custom ControllerFactory so I could add my Custom ControllerActionInvoker to the Controller:&lt;BR&gt;&lt;BR&gt;&lt;BR&gt;&lt;/P&gt;&lt;PRE class=csharpcode&gt; &lt;SPAN class=kwrd&gt;public&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;class&lt;/SPAN&gt; ActionFilterConfigControllerFactory : DefaultControllerFactory
 {
        &lt;SPAN class=kwrd&gt;public&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;override&lt;/SPAN&gt; IController CreateController(RequestContext requestContext, &lt;SPAN class=kwrd&gt;string&lt;/SPAN&gt; controllerName)
        {
             ...&lt;/PRE&gt;&lt;PRE class=csharpcode&gt;&lt;STRONG&gt;&lt;EM&gt;                controllerInstance.ActionInvoker = &lt;SPAN class=kwrd&gt;new&lt;/SPAN&gt; ActionFilerConfigControllerActionInvoker();&lt;/EM&gt;&lt;/STRONG&gt;

            &lt;SPAN class=kwrd&gt;return&lt;/SPAN&gt; controller;
        }
 }&lt;/PRE&gt;
&lt;STYLE type=text/css&gt;.csharpcode {
	BACKGROUND-COLOR: #ffffff; FONT-FAMILY: consolas, "Courier New", courier, monospace; COLOR: black; FONT-SIZE: small
}
.csharpcode PRE {
	BACKGROUND-COLOR: #ffffff; FONT-FAMILY: consolas, "Courier New", courier, monospace; COLOR: black; FONT-SIZE: small
}
.csharpcode PRE {
	MARGIN: 0em
}
.csharpcode .rem {
	COLOR: #008000
}
.csharpcode .kwrd {
	COLOR: #0000ff
}
.csharpcode .str {
	COLOR: #006080
}
.csharpcode .op {
	COLOR: #0000c0
}
.csharpcode .preproc {
	COLOR: #cc6633
}
.csharpcode .asp {
	BACKGROUND-COLOR: #ffff00
}
.csharpcode .html {
	COLOR: #800000
}
.csharpcode .attr {
	COLOR: #ff0000
}
.csharpcode .alt {
	BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; WIDTH: 100%
}
.csharpcode .lnum {
	COLOR: #606060
}
&lt;/STYLE&gt;

&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The custom ControllerActionInvoker will make sure the Action Filter added by using my solution is added to the FilterInfo class. This is done by overriding the GetFilters method:&lt;BR&gt;&lt;BR&gt;&lt;BR&gt;&lt;/P&gt;&lt;PRE class=csharpcode&gt;&lt;SPAN class=kwrd&gt;public&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;class&lt;/SPAN&gt; ActionFilerConfigControllerActionInvoker : ControllerActionInvoker
{
        &lt;SPAN class=kwrd&gt;protected&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;override&lt;/SPAN&gt; FilterInfo GetFilters(ControllerContext controllerContext,
                                                 ActionDescriptor actionDescriptor)
        {
            var filters = &lt;SPAN class=kwrd&gt;base&lt;/SPAN&gt;.GetFilters(controllerContext, actionDescriptor);

            &lt;SPAN class=kwrd&gt;...&lt;/SPAN&gt;

            &lt;SPAN class=kwrd&gt;if&lt;/SPAN&gt; (ConfigActionFilter.Config.ContainsKey(controllerName))
                AddFiltersToFilerList(actionDescriptor, filters, controllerName);

            &lt;SPAN class=kwrd&gt;return&lt;/SPAN&gt; filters;
        }&lt;/PRE&gt;
&lt;STYLE type=text/css&gt;.csharpcode {
	BACKGROUND-COLOR: #ffffff; FONT-FAMILY: consolas, "Courier New", courier, monospace; COLOR: black; FONT-SIZE: small
}
.csharpcode PRE {
	BACKGROUND-COLOR: #ffffff; FONT-FAMILY: consolas, "Courier New", courier, monospace; COLOR: black; FONT-SIZE: small
}
.csharpcode PRE {
	MARGIN: 0em
}
.csharpcode .rem {
	COLOR: #008000
}
.csharpcode .kwrd {
	COLOR: #0000ff
}
.csharpcode .str {
	COLOR: #006080
}
.csharpcode .op {
	COLOR: #0000c0
}
.csharpcode .preproc {
	COLOR: #cc6633
}
.csharpcode .asp {
	BACKGROUND-COLOR: #ffff00
}
.csharpcode .html {
	COLOR: #800000
}
.csharpcode .attr {
	COLOR: #ff0000
}
.csharpcode .alt {
	BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; WIDTH: 100%
}
.csharpcode .lnum {
	COLOR: #606060
}
&lt;/STYLE&gt;

&lt;P&gt;}&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This project only a fun thing to do and I like the idea of having different options to add Action Filters, and this solution will make the Controller clean from Attributes and also have one place to add them. When I create my Controller I don’t need to worry or think about the cross-cutting concerns, I just add them later and into the Global.asax.&lt;/P&gt;
&lt;P&gt;I want to thanks &lt;A href="http://weblogs.asp.net/mikaelsoderstrom/" mce_href="http://weblogs.asp.net/mikaelsoderstrom/"&gt;Mikael Söderström&lt;/A&gt; for taking time to discuss this solution with him, and get some feedback and also “host” the source code for me.&lt;BR&gt;&lt;BR&gt;You can download the source code with an example here: &lt;A title=http://vinkr.net/misc/ActionFilterConfig.zip href="http://vinkr.net/misc/ActionFilterConfig.zip" mce_href="http://vinkr.net/misc/ActionFilterConfig.zip"&gt;http://vinkr.net/misc/ActionFilterConfig.zip&lt;/A&gt;&lt;/P&gt;
&lt;STYLE type=text/css&gt;.csharpcode {
	BACKGROUND-COLOR: #ffffff; FONT-FAMILY: consolas, "Courier New", courier, monospace; COLOR: black; FONT-SIZE: small
}
.csharpcode PRE {
	BACKGROUND-COLOR: #ffffff; FONT-FAMILY: consolas, "Courier New", courier, monospace; COLOR: black; FONT-SIZE: small
}
.csharpcode PRE {
	MARGIN: 0em
}
.csharpcode .rem {
	COLOR: #008000
}
.csharpcode .kwrd {
	COLOR: #0000ff
}
.csharpcode .str {
	COLOR: #006080
}
.csharpcode .op {
	COLOR: #0000c0
}
.csharpcode .preproc {
	COLOR: #cc6633
}
.csharpcode .asp {
	BACKGROUND-COLOR: #ffff00
}
.csharpcode .html {
	COLOR: #800000
}
.csharpcode .attr {
	COLOR: #ff0000
}
.csharpcode .alt {
	BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; WIDTH: 100%
}
.csharpcode .lnum {
	COLOR: #606060
}
&lt;/STYLE&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7248619" width="1" height="1"&gt;</content><author><name>Fredrik N</name><uri>http://weblogs.asp.net/members/Fredrik-N.aspx</uri></author><category term="ASP.Net" scheme="http://weblogs.asp.net/fredriknormen/archive/tags/ASP.Net/default.aspx" /><category term="ASP.NET MVC" scheme="http://weblogs.asp.net/fredriknormen/archive/tags/ASP.NET+MVC/default.aspx" /></entry><entry><title>Visual Studio 2010 Launch Countdown Sidebar Widget</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/fredriknormen/archive/2009/11/04/visual-studio-2010-launch-countdown-sidebar-widget.aspx" /><id>http://weblogs.asp.net/fredriknormen/archive/2009/11/04/visual-studio-2010-launch-countdown-sidebar-widget.aspx</id><published>2009-11-04T10:15:00Z</published><updated>2009-11-04T10:15:00Z</updated><content type="html">
&lt;STYLE type=text/css&gt;

div#widget { position: relative; width: 250px; height: 155px; }

body ul#cntdwn { width: 250px; height: 80px; background: transparent url(http://toysfortweets.com/visualstudiowidget/cntdwn-bg.png) no-repeat scroll left top; list-style-type: none; text-align: center; padding: 74px 0 0 0; margin: 0; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; }

body ul#cntdwn li { float: left; margin: 0 8px 0 0; background: transparent url(http://toysfortweets.com/visualstudiowidget/number-bg.png) no-repeat scroll left top; padding: 0 0 5px 7px; }

body ul#cntdwn li.first { margin-left: 20px; }

body ul#cntdwn li em { display: block;  color: #111; font-size: 1.6em; font-style: normal; font-weight: bold; background: transparent url(http://toysfortweets.com/visualstudiowidget/number-cap.png) no-repeat scroll right top; padding: 3px 7px 0 0; height: 35px; margin-bottom: -5px; }

div#widget a#link { display: block; width: 250px; height: 155px; position: absolute; top: 0; left: 0; }

&lt;/STYLE&gt;

&lt;SCRIPT language=javascript src="http://toysfortweets.com/visualstudiowidget/countdown.js" mce_src="http://toysfortweets.com/visualstudiowidget/countdown.js"&gt; &lt;/SCRIPT&gt;
&lt;BR&gt;&lt;BR&gt;Here is a&amp;nbsp;sidebar widget that will show the countdown&amp;nbsp;for Visual Studio 2010, launching on March 22, 2010.&lt;BR&gt;
&lt;P&gt;&amp;lt;style type="text/css"&amp;gt;&lt;BR&gt;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;div#widget { position: relative; width: 250px; height: 155px; }&lt;/P&gt;
&lt;P&gt;body ul#cntdwn { width: 250px; height: 80px; background: transparent url(&lt;A href="http://toysfortweets.com/visualstudiowidget/cntdwn-bg.png" mce_href="http://toysfortweets.com/visualstudiowidget/cntdwn-bg.png"&gt;http://toysfortweets.com/visualstudiowidget/cntdwn-bg.png&lt;/A&gt;) no-repeat scroll left top; list-style-type: none; text-align: center; padding: 74px 0 0 0; margin: 0; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; }&lt;/P&gt;
&lt;P&gt;body ul#cntdwn li { float: left; margin: 0 8px 0 0; background: transparent url(&lt;A href="http://toysfortweets.com/visualstudiowidget/number-bg.png" mce_href="http://toysfortweets.com/visualstudiowidget/number-bg.png"&gt;http://toysfortweets.com/visualstudiowidget/number-bg.png&lt;/A&gt;) no-repeat scroll left top; padding: 0 0 5px 7px; }&lt;/P&gt;
&lt;P&gt;body ul#cntdwn li.first { margin-left: 20px; }&lt;/P&gt;
&lt;P&gt;body ul#cntdwn li em { display: block;&amp;nbsp; color: #111; font-size: 1.6em; font-style: normal; font-weight: bold; background: transparent url(&lt;A href="http://toysfortweets.com/visualstudiowidget/number-cap.png" mce_href="http://toysfortweets.com/visualstudiowidget/number-cap.png"&gt;http://toysfortweets.com/visualstudiowidget/number-cap.png&lt;/A&gt;) no-repeat scroll right top; padding: 3px 7px 0 0; height: 35px; margin-bottom: -5px; }&lt;/P&gt;
&lt;P&gt;div#widget a#link { display: block; width: 250px; height: 155px; position: absolute; top: 0; left: 0; }&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;lt;/style&amp;gt; &lt;BR&gt;&amp;lt;script language="javascript" src="http://toysfortweets.com/visualstudiowidget/countdown.js" mce_src="http://toysfortweets.com/visualstudiowidget/countdown.js"&amp;gt; &amp;lt;/script&amp;gt; &lt;/P&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7246715" width="1" height="1"&gt;</content><author><name>Fredrik N</name><uri>http://weblogs.asp.net/members/Fredrik-N.aspx</uri></author><category term="VS 2010" scheme="http://weblogs.asp.net/fredriknormen/archive/tags/VS+2010/default.aspx" /></entry><entry><title>Introduction to Templates in ASP.NET MVC 2 Screen cast</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/fredriknormen/archive/2009/11/02/introduction-to-templates-in-asp-net-mvc-2-screen-cast.aspx" /><id>http://weblogs.asp.net/fredriknormen/archive/2009/11/02/introduction-to-templates-in-asp-net-mvc-2-screen-cast.aspx</id><published>2009-11-02T20:05:16Z</published><updated>2009-11-02T20:05:16Z</updated><content type="html">&lt;p&gt;I have recorded some screen casts during the last week for Microsoft, one is was published today on Channel 9 (The Screen cast is in Swedish, I will eventually try to record screen casts also in English, but when that happens, I don’t now). You can found the screen cast here:   &lt;br /&gt;    &lt;br /&gt;&lt;a title="http://channel9.msdn.com/posts/MSDNSweden/Introduktion-till-Template-i-ASPNET-MVC-2/" href="http://channel9.msdn.com/posts/MSDNSweden/Introduktion-till-Template-i-ASPNET-MVC-2/"&gt;http://channel9.msdn.com/posts/MSDNSweden/Introduktion-till-Template-i-ASPNET-MVC-2/&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;For those who can’t understand Swedish, here is a short summary of the screen cast.&lt;/p&gt;  &lt;p&gt;With ASP.NET MVC version 2.0 we can use templates. It will help us rendering forms etc out form the Model we passed to the View. We can easy modify templates to satisfy our needs. The simples way to use the Template feature is to use the Html’s DisplayForModel method:   &lt;br /&gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;%= Html.DisplayForModel() %&amp;gt;&lt;/p&gt;  &lt;p&gt;   &lt;br /&gt;This method will iterate through the ViewData.ModelMetadata.Properties to render the Model. The ModelMetadata hold information about the model, such as properties etc. The result will remind us about the DetailView control shipped with ASP.NET 2.0, but will put the name of the property at top, and then a new line with the value of the property, like this:    &lt;br /&gt;&lt;/p&gt;  &lt;p&gt;FirstName&lt;/p&gt;  &lt;p&gt;John&lt;/p&gt;  &lt;p&gt;LastName&lt;/p&gt;  &lt;p&gt;Doe&lt;/p&gt;  &lt;p&gt;   &lt;br /&gt;There is also a method to render a editable from, EditorForModel. By default the methods will use a default template, we can easy override the template. We do that by adding a ASP.NET MVC User Control to the ~/Views/ControllerName/DisplayTemplates or EditTemplates folder. If you want to override how a String should be “rendered”, then you simply add a String.ascx file to the Templates folders, here is an example of a DisplayTemplate:&lt;/p&gt; &lt;code&gt;   &lt;br /&gt;&amp;lt;%@ Control Language=&amp;quot;C#&amp;quot; Inherits=&amp;quot;System.Web.Mvc.ViewUserControl&amp;quot;%&amp;gt;     &lt;br /&gt;&lt;/code&gt;&lt;code&gt;&amp;lt;i&amp;gt;&amp;lt;%= Html.Encode(Model) %&amp;gt;&amp;lt;/i&amp;gt;&lt;/code&gt;  &lt;p&gt;   &lt;br /&gt;The above template will make the value of the rendered property to use italic:&lt;/p&gt;  &lt;p&gt;   &lt;br /&gt;FirstName&lt;/p&gt;  &lt;p&gt;&lt;em&gt;John&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;LastName&lt;/p&gt;  &lt;p&gt;&lt;em&gt;Doe&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;&lt;em&gt;&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;We can do several more stuffs with template, for more information check out the following blog post from &lt;a href="http://bradwilson.typepad.com/blog/2009/10/aspnet-mvc-2-templates-part-1-introduction.html"&gt;Brad Wilson&lt;/a&gt;:&lt;/p&gt;  &lt;li&gt;&lt;a href="http://bradwilson.typepad.com/blog/2009/10/aspnet-mvc-2-templates-part-1-introduction.html"&gt;Part 1: Introduction&lt;/a&gt; &lt;/li&gt;  &lt;li&gt;&lt;a href="http://bradwilson.typepad.com/blog/2009/10/aspnet-mvc-2-templates-part-2-modelmetadata.html"&gt;Part 2: ModelMetadata&lt;/a&gt;&lt;/li&gt;  &lt;li&gt;&lt;a href="http://bradwilson.typepad.com/blog/2009/10/aspnet-mvc-2-templates-part-3-default-templates.html"&gt;Part 3: Default Templates&lt;/a&gt;&lt;/li&gt;  &lt;li&gt;&lt;a href="http://bradwilson.typepad.com/blog/2009/10/aspnet-mvc-2-templates-part-4-custom-object-templates.html"&gt;Part 4: Custom Object Templates&lt;/a&gt;&lt;/li&gt;  &lt;li&gt;&lt;a href="http://bradwilson.typepad.com/blog/2009/10/aspnet-mvc-2-templates-part-5-master-page-templates.html"&gt;Part 5: Master Page Templates&lt;/a&gt;&lt;/li&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;You can find me on twitter: &lt;a href="http://www.twitter.com/fredrikn"&gt;http://www.twitter.com/fredrikn&lt;/a&gt;&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7245440" width="1" height="1"&gt;</content><author><name>Fredrik N</name><uri>http://weblogs.asp.net/members/Fredrik-N.aspx</uri></author><category term="ASP.Net" scheme="http://weblogs.asp.net/fredriknormen/archive/tags/ASP.Net/default.aspx" /><category term="VS 2010" scheme="http://weblogs.asp.net/fredriknormen/archive/tags/VS+2010/default.aspx" /><category term="ASP.NET MVC" scheme="http://weblogs.asp.net/fredriknormen/archive/tags/ASP.NET+MVC/default.aspx" /></entry><entry><title>Distributing domain entities over the wire</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/fredriknormen/archive/2009/10/31/distributing-domain-entities-over-the-wire.aspx" /><id>http://weblogs.asp.net/fredriknormen/archive/2009/10/31/distributing-domain-entities-over-the-wire.aspx</id><published>2009-10-31T18:12:46Z</published><updated>2009-10-31T18:12:46Z</updated><content type="html">&lt;p&gt;When we design our domain entities we don’t have a presentation layer or database in mind. The domain entities are core business objects located on the server or client side based of what kind of application we are building. Domain entities aren’t designed for distribution. When we realize that we need a distribution, we shouldn’t distribute the entities, instead collect the data we need to distribute and create a data transfer object (DTO) instead. Have the network in mind, a domain entity aren’t designed with a network in mind and of that reason not suitable for distribution. When we create our domain entities, they aren’t designed for presentation purpose, they are designed to fulfill business needs. You should be careful when you start thinking about returning a domain entity to the View when using a patterns like MVC, instead use DTO or a ViewModel, because once again the domain entities aren’t designed with presentation in mind, and aren’t often suitable for presentation purpose. It’s often better to map them to a DTO or ViewModel, objects that are suitable for presentation purpose or passed over the wire.   &lt;br /&gt;&lt;/p&gt;  &lt;p&gt;I often see demos and example codes where models are generated out from a database. Remember it you do that, your application’s design is driven by a relational database schema, do you really want a database to set the limit in your application design? I don’t. Developers are good at one thing, implementing business logic, that is what they do, that is what they are good at, that is what they should focus on (if we live in the perfect world ;)). We should work against our model. We shouldn’t care about how the database schema looks like. A database is a way to store information, and we have database administrator that are experts in the database area, let them handle the database schema and together with developers map the domain model to the database schema, with the use of an ORM, like Entity Framework 4.0 or nHibernate etc.&lt;/p&gt;  &lt;p&gt;   &lt;br /&gt;When it comes to WCF or Web Services, never distribute the domain entities, they aren’t designed for that kind of purpose in the first place(if we don’t use Distributed Domain Driven Design). There is a reason why we call the data sent from a Service as a message. A message is created with network in mind, that is why we use data contracts. When it comes to .NET RIA Services, don’t distribute the Entity Framework generated object or LINQ to SQL, they are generated out from a database schema, and it’s so easy to select whole tables and related tables to get what we want and then we distribute it and forget about the network between the client and server. In some cases we don’t even want to think about the network existence because it adds limit to the information and how we would like to work with objects. But we can’t hide the complexity how much we try, we have to realize that we do have a network, and have that in mind when we design our RIA. We can still on the server-side create our perfect domain model, but we shouldn’t distribute it. Instead transform peace of it into DTOs and only make sure we send the data we are needed. I have seen several examples where developers generate codes from Entity Framework or LINQ to SQL and returns it with .NET RIA Services. When I look at the examples I can see big object graphs passed over the wire and developers are using it as it was local objects, they start to requesting about Lazy Loading support in .NET RIA Services etc. Either they forgot about the network, or they have lack of experience. For&amp;#160; intranet, small database driven applications it can be ok to create a model out from a database schema and distribute it with .NET RIA Services, they don’t often even use business logic, and they don’t need a domain model. But when it comes to large application it’s not often an good idea to generate object out from a database schema and distribute it. In that case DTO is much better option. Not only to limit the data passed, but also because of separation of concerns. The best thing with .NET RIA Services is that it does support DTOs :) Microsoft are good at creating frameworks for developers, but sometimes they want to satisfy everyone, and that often leads to people will use the frameworks in a wrong way. WCF is probably one of the better technologies made from Microsoft, they have learned from the fail of DCOM. When we use WCF we have to create a data contract, which force us to think about what we are distributing, they have also add a small limit of how much data we can by default pass over the wire. I know that some developers think WCF is complex to use and not so easy to learn, but sometimes it shouldn’t be easy to create things that are complex, the complexity is there by some reasons, and it can’t be hidden.&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7244009" width="1" height="1"&gt;</content><author><name>Fredrik N</name><uri>http://weblogs.asp.net/members/Fredrik-N.aspx</uri></author><category term="Design" scheme="http://weblogs.asp.net/fredriknormen/archive/tags/Design/default.aspx" /><category term="RIA" scheme="http://weblogs.asp.net/fredriknormen/archive/tags/RIA/default.aspx" /><category term="RIA Services" scheme="http://weblogs.asp.net/fredriknormen/archive/tags/RIA+Services/default.aspx" /><category term="Entitis" scheme="http://weblogs.asp.net/fredriknormen/archive/tags/Entitis/default.aspx" /></entry><entry><title>VS 2010 Beta 2 and .Net 4.0 is now available for downloading from MSDN Sub.</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/fredriknormen/archive/2009/10/21/vs-2010-beta-2-and-net-4-0-is-now-available-for-downloading-from-msdn-sub.aspx" /><id>http://weblogs.asp.net/fredriknormen/archive/2009/10/21/vs-2010-beta-2-and-net-4-0-is-now-available-for-downloading-from-msdn-sub.aspx</id><published>2009-10-21T11:39:00Z</published><updated>2009-10-21T11:39:00Z</updated><content type="html">&lt;P mce_keep="true"&gt;Oh, I'm late.. but better late then never.. you can now download VS 2010 nad .Net 4.0 Beta 2, if you are a MSDN Subscriber.. You can read more about VS 2010 Beta 2 on &lt;A href="http://weblogs.asp.net/scottgu/archive/2009/10/19/vs-2010-and-net-4-0-beta-2.aspx" mce_href="http://weblogs.asp.net/scottgu/archive/2009/10/19/vs-2010-and-net-4-0-beta-2.aspx"&gt;Scott Guthrie's&lt;/A&gt; blog.&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;Wow, my shortest blog post ever!&lt;/P&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7234892" width="1" height="1"&gt;</content><author><name>Fredrik N</name><uri>http://weblogs.asp.net/members/Fredrik-N.aspx</uri></author><category term=".NET 4.0" scheme="http://weblogs.asp.net/fredriknormen/archive/tags/.NET+4.0/default.aspx" /><category term="VS 2010" scheme="http://weblogs.asp.net/fredriknormen/archive/tags/VS+2010/default.aspx" /></entry><entry><title>ASP.NET 4.0 Web Form routing</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/fredriknormen/archive/2009/10/14/asp-net-4-0-web-form-routing.aspx" /><id>http://weblogs.asp.net/fredriknormen/archive/2009/10/14/asp-net-4-0-web-form-routing.aspx</id><published>2009-10-14T07:43:26Z</published><updated>2009-10-14T07:43:26Z</updated><content type="html">&lt;p&gt;One of hundreds things I like about ASP.NET MVC, is the routing, a way to use clear and friendly URLs like: &lt;a href="http://www.server.com/Customer/List"&gt;www.server.com/Customer/List&lt;/a&gt;, instead of something like &lt;a href="http://www.server.com/Customers.aspx"&gt;www.server.com/Customers.aspx&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;The routing part is now also added to the ASP.NET Web Form 4.0, so we can now use routing to avoid pointing to a .aspx file and ugly query stings. &lt;a href="http://weblogs.asp.net/scottgu/archive/2009/10/13/url-routing-with-asp-net-4-web-forms-vs-2010-and-net-4-0-series.aspx"&gt;Scott Guthrie&lt;/a&gt; have wrote a blog post about it &lt;a href="http://weblogs.asp.net/scottgu/archive/2009/10/13/url-routing-with-asp-net-4-web-forms-vs-2010-and-net-4-0-series.aspx"&gt;here&lt;/a&gt;. I will only write a short post to introduce it.&lt;/p&gt;  &lt;p&gt;To define a route, we will use the Application_Start event of the Gloabal.asax file (a file which will be “executed” every time we visit a .aspx page). The Application_Start event will only be executed one time, and that is when the application starts (the first user visit our app). By using the static RouteTable class, we can add routes to the RouteTable’s Routes collection. This is done by using the MapPageRoute method. The MapPageRoute method can take some parameters, for example the name of the Route (to give a route an identifier so we can get and create routes in our code), the new URL where we also can specify parameters and route constraints etc. So for example if we have a URL look like this: &lt;a href="http://www.server.com/Customer.aspx?id=10"&gt;www.server.com/Customer.aspx?id=10&lt;/a&gt;, we can use the Route feature to use a URL like this instead: &lt;a href="http://www.server.com/Customer/10"&gt;www.server.com/Customer/10&lt;/a&gt;. The following code will setup this route:&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;void&lt;/span&gt; RegisterRoutes(RouteCollection routes)
{
      routes.MapPageRoute(
          &lt;span class="str"&gt;&amp;quot;viewCustomerDetails&amp;quot;&lt;/span&gt;,
         &lt;span class="str"&gt;&amp;quot;Customer/{ID}&amp;quot;&lt;/span&gt;,
        &lt;span class="str"&gt;&amp;quot;~/Customer.aspx&amp;quot;&lt;/span&gt;);
}

&lt;span class="kwrd"&gt;void&lt;/span&gt; Application_Start()
{
       RegisterRoutes(RouteTable.Routes);
}&lt;/pre&gt;
&lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;br /&gt;I like this feature and will use it in all of my Web apps, where I need to use Web Forms, I will mostly use the ASP.NET MVC framework ;)&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7229523" width="1" height="1"&gt;</content><author><name>Fredrik N</name><uri>http://weblogs.asp.net/members/Fredrik-N.aspx</uri></author></entry><entry><title>Some features I love in VS 2010</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/fredriknormen/archive/2009/10/08/some-features-i-love-in-vs-2010.aspx" /><id>http://weblogs.asp.net/fredriknormen/archive/2009/10/08/some-features-i-love-in-vs-2010.aspx</id><published>2009-10-08T12:12:00Z</published><updated>2009-10-08T12:12:00Z</updated><content type="html">&lt;P mce_keep="true"&gt;This post will not be so long, I want to write a little about some Visual Studio 2010 features I love. First of all the changes made to C# is great, the default value on parameters rocks! When I implement Frameworks, I often ended up with something like this:&lt;/P&gt;
&lt;P mce_keep="true"&gt;public void Log(string message)&lt;BR&gt;&lt;BR&gt;public void Log(string message, string category)&lt;/P&gt;
&lt;P mce_keep="true"&gt;public void Log(string message, string category, .......)&lt;/P&gt;
&lt;P mce_keep="true"&gt;The last method is the one that have the most of the code, the other method with few parameters, only calls the last one, and pass null or an empty string as values to the extra arguments:&lt;/P&gt;
&lt;P mce_keep="true"&gt;Log(message, null, ......)&lt;/P&gt;
&lt;P mce_keep="true"&gt;&lt;STRONG&gt;&lt;EM&gt;Note: The code above is not taken from a real example, only used as pseudo code.&lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;Now with C# 4.0, we can instead set a default value on a argument, which will get rid of the extra methods, for example:&lt;BR&gt;&lt;BR&gt;public void Log(string message, string category = null, .....)&lt;/P&gt;
&lt;P mce_keep="true"&gt;The dynamic&amp;nbsp;feature in C# is ok, but at the moment I will not use it. When we use the dynamic when we declare a varible, it will be evaluated first at runtime. It's a nice feature when we want C# to use stuff from other dynamic languages.&lt;/P&gt;
&lt;P mce_keep="true"&gt;dynamic something = ....&lt;/P&gt;
&lt;P mce_keep="true"&gt;something.Hello();&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&lt;STRONG&gt;Entity Framework 4.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;Will be great now when it will support POCO (Plain old clr object):&lt;/P&gt;
&lt;P mce_keep="true"&gt;public class Customer&lt;BR&gt;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public string FirstName&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; get { ... }&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set&amp;nbsp;{ ... }&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR&gt;}&lt;/P&gt;
&lt;P mce_keep="true"&gt;There are so many other features improvements to EF, need a new blog post for that, but the POCO support and the&amp;nbsp;model first&amp;nbsp;approached is better supported than the first version.&lt;/P&gt;
&lt;P mce_keep="true"&gt;&lt;STRONG&gt;ASP.NET AJAX 4.0&lt;/STRONG&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;I love the client-side binding, I have some blog post about it, so you can read about it here:&lt;/P&gt;
&lt;P mce_keep="true"&gt;&lt;A href="http://weblogs.asp.net/fredriknormen/archive/2009/09/16/asp-net-ajax-4-0-preview-5-working-with-converters-and-the-new-cdn.aspx"&gt;http://weblogs.asp.net/fredriknormen/archive/2009/09/16/asp-net-ajax-4-0-preview-5-working-with-converters-and-the-new-cdn.aspx&lt;/A&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&lt;A href="http://weblogs.asp.net/fredriknormen/archive/2009/09/11/keep-the-first-empty-item-in-a-listbox-when-using-asp-net-ajax-4-0-preview-5-and-observer.aspx"&gt;http://weblogs.asp.net/fredriknormen/archive/2009/09/11/keep-the-first-empty-item-in-a-listbox-when-using-asp-net-ajax-4-0-preview-5-and-observer.aspx&lt;/A&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&lt;A href="http://weblogs.asp.net/fredriknormen/archive/2009/09/11/asp-net-ajax-4-0-preview-5-available.aspx"&gt;http://weblogs.asp.net/fredriknormen/archive/2009/09/11/asp-net-ajax-4-0-preview-5-available.aspx&lt;/A&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&lt;STRONG&gt;Silverlight designer&lt;/STRONG&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;Visual Studio 2010 have now enabled the Silverlight designer, it was not enabled in the previous Visual Studio, so we can now easier and faster create our Silverlight apps, and no need to run Expression Blend and VS at the same time.&lt;/P&gt;
&lt;P mce_keep="true"&gt;&lt;STRONG&gt;Improvements for web developer&lt;/STRONG&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;Better Java-script intellisense. Easier to&amp;nbsp;add Server controls to the .aspx file. Something we need to add before was the runat="seerver" attribute, it's now directly added when we add a Server control in the source mode (not talking about to drag a control, it when we write the code).&lt;/P&gt;
&lt;P mce_keep="true"&gt;&lt;STRONG&gt;Code Contract&lt;/STRONG&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;I&amp;nbsp;like design-by-contract, think everyone should read about it. We can now use code contract in our code. What I have heard, we need the VSTS version for static checking. You can read more avout Code contract here: &lt;A href="http://msdn.microsoft.com/en-us/devlabs/dd491992.aspx"&gt;http://msdn.microsoft.com/en-us/devlabs/dd491992.aspx&lt;/A&gt;&lt;/P&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7225498" width="1" height="1"&gt;</content><author><name>Fredrik N</name><uri>http://weblogs.asp.net/members/Fredrik-N.aspx</uri></author><category term="Visual Studio 2010" scheme="http://weblogs.asp.net/fredriknormen/archive/tags/Visual+Studio+2010/default.aspx" /><category term=".NET 4.0" scheme="http://weblogs.asp.net/fredriknormen/archive/tags/.NET+4.0/default.aspx" /></entry><entry><title>Create an automatic scrollable image slider in Silverlight</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/fredriknormen/archive/2009/09/18/create-an-automatic-scrollable-image-slider-in-silverlight.aspx" /><id>http://weblogs.asp.net/fredriknormen/archive/2009/09/18/create-an-automatic-scrollable-image-slider-in-silverlight.aspx</id><published>2009-09-18T10:37:00Z</published><updated>2009-09-18T10:37:00Z</updated><content type="html">&lt;P&gt;I guess someone will send me an comment and say something like: “Why not simply use XXXX, why write your own control” ;) I know there are a lot of controls out there that will do stuff for me, but I want to know how they are created, and try to create my own solution to learn more etc.&lt;/P&gt;
&lt;P&gt;I’m working on a small and relative simple Silverlight app for my brother, and I wanted to make it possible for the users to see the images as thumbnails (he is a photographer on his spare time and want a site to show his works). The thumbnails should be placed after each other horizontal in a&amp;nbsp; scrollable list, the list should be scrollable automatically. &lt;BR&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://weblogs.asp.net/blogs/fredriknormen/image_3D0F1B4C.png" mce_href="http://weblogs.asp.net/blogs/fredriknormen/image_3D0F1B4C.png"&gt;&lt;IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; DISPLAY: inline; BORDER-TOP: 0px; BORDER-RIGHT: 0px" title=image border=0 alt=image src="http://weblogs.asp.net/blogs/fredriknormen/image_thumb_13B7D34E.png" width=642 height=528 mce_src="http://weblogs.asp.net/blogs/fredriknormen/image_thumb_13B7D34E.png"&gt;&lt;/A&gt; &lt;/P&gt;
&lt;P&gt;&lt;BR&gt;You can see the list of Thumbnails at the bottom of the image above. I wanted the list of Thumbnails to be scrollable, but not by moving a scrollbar, instead an automatic scrolling when the mouse is heading to the right or left side of the list. I was first thinking of using a Canvas and use the Canvas.Top and Left attached property to scroll the thumbnails, but I decided to take advantage of the ScrollViewer control. The problem with the ScrollViewer is that we don’t have a property to set the scrollers’s position, instead we have to use the ScrollToHorizontalOffset method. So I couldn’t define an animation for handling the scrolling, instead I decide to use the DispatchTimer class and handle the “animation” on my own. &lt;BR&gt;&lt;/P&gt;&lt;PRE class=csharpcode&gt;&lt;SPAN class=kwrd&gt;private&lt;/SPAN&gt; DispatcherTimer _thumbnailScrollTimer = &lt;SPAN class=kwrd&gt;new&lt;/SPAN&gt; DispatcherTimer();

&lt;SPAN class=kwrd&gt;public&lt;/SPAN&gt; AutomaticImageSlider()
{
      InitializeComponent();

       _thumbnailScrollTimer.Interval = &lt;SPAN class=kwrd&gt;new&lt;/SPAN&gt; TimeSpan(0, 0, 0, 0, 1);
       _thumbnailScrollTimer.Tick += &lt;SPAN class=kwrd&gt;new&lt;/SPAN&gt; EventHandler(_thumbnailScrollTimer_Tick);
}&lt;/PRE&gt;
&lt;P&gt;
&lt;STYLE type=text/css&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/STYLE&gt;
&lt;/P&gt;
&lt;P&gt;The reason I used the DispathTimer is because every time it ticks based on an interval an event is trigged, the event handler for the Tick will be executed on the UI thread. I set the interval of the Timer control to 1 millisecond, this value can of course be changed, based on how fast and often I want to update the ScrollViewer. I put my ScrollViewer inside of a StackPanel, and hooked up to the StackPanel’s MouseMove event. &lt;BR&gt;&lt;/P&gt;&lt;PRE class=csharpcode&gt;&lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;StackPanel&lt;/SPAN&gt;
        &lt;SPAN class=attr&gt;x:Name&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="thumbnailViewer"&lt;/SPAN&gt;
        &lt;SPAN class=attr&gt;MouseMove&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="thumbnailViewer_MouseMove"&lt;/SPAN&gt;
        &lt;SPAN class=attr&gt;HorizontalAlignment&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="Center"&lt;/SPAN&gt;
        &lt;SPAN class=attr&gt;VerticalAlignment&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="Bottom"&lt;/SPAN&gt;
        &lt;SPAN class=attr&gt;Background&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="Black"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;

            &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;ScrollViewer&lt;/SPAN&gt;
                &lt;SPAN class=attr&gt;x:Name&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="thumbnailViewerScroller"&lt;/SPAN&gt;
                &lt;SPAN class=attr&gt;Padding&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="0"&lt;/SPAN&gt;
                &lt;SPAN class=attr&gt;BorderThickness&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="0"&lt;/SPAN&gt;
                &lt;SPAN class=attr&gt;VerticalScrollBarVisibility&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="Hidden"&lt;/SPAN&gt;
                &lt;SPAN class=attr&gt;HorizontalScrollBarVisibility&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="Hidden"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
                
               &lt;SPAN class=rem&gt;&amp;lt;!-- Images here, I add the images dynamically --&amp;gt;&lt;/SPAN&gt;
            
            &lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;ScrollViewer&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;

&lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;StackPanel&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;STYLE type=text/css&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/STYLE&gt;

&lt;P&gt;I only wants to start the timer when I move the mouse over a specific part of the StackPanel, so when the mouse are in the middle part of the ScrollViewer the timer should be idle (stopped). The MouseMove event will check if the mouse is within a specific position and if it is, the ScollViewer should start to scroll until it reached the end of its content or the mouse is leaving the area. &lt;BR&gt;&lt;/P&gt;&lt;PRE class=csharpcode&gt;&lt;SPAN class=kwrd&gt;private&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;void&lt;/SPAN&gt; thumbnailViewer_MouseMove(&lt;SPAN class=kwrd&gt;object&lt;/SPAN&gt; sender, MouseEventArgs e)
 {
      var x = e.GetPosition(sender &lt;SPAN class=kwrd&gt;as&lt;/SPAN&gt; UIElement).X;

       &lt;SPAN class=kwrd&gt;if&lt;/SPAN&gt; (x &amp;gt;= 300 &amp;amp;&amp;amp; x &amp;lt;= 700)
       {
            _acceleration = 0;
            _thumbnailScrollTimer.Stop();
            _thumbnailScrollTimerStarted = &lt;SPAN class=kwrd&gt;false&lt;/SPAN&gt;;
       }
       &lt;SPAN class=kwrd&gt;else&lt;/SPAN&gt;
       {
            &lt;SPAN class=kwrd&gt;if&lt;/SPAN&gt; (x &amp;gt; 700)
                 _acceleration = (&lt;SPAN class=kwrd&gt;int&lt;/SPAN&gt;)(Math.Pow((x - 512), 1.5) / 1200);
            &lt;SPAN class=kwrd&gt;else&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;if&lt;/SPAN&gt; (x &amp;lt; 300)
                 _acceleration = -(&lt;SPAN class=kwrd&gt;int&lt;/SPAN&gt;)(Math.Pow((512 - x), 1.5) / 1200);

            &lt;SPAN class=kwrd&gt;if&lt;/SPAN&gt; (!_thumbnailScrollTimerStarted)
                 _thumbnailScrollTimer.Start();

            _thumbnailScrollTimerStarted = &lt;SPAN class=kwrd&gt;true&lt;/SPAN&gt;;
        }
  }&lt;/PRE&gt;
&lt;STYLE type=text/css&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/STYLE&gt;

&lt;P&gt;By using the MouseEventArgs’s GetPosition method, I can get the position of the mouse. If the mouse is between X 300 and 700, the ScrollView should stand still and the timer should be stopped. If the mouse X position is between 0 – 300, the ScrollViewer should start to scroll to the right direction, if the mouse X position is larger than 700, the ScrollViewer should start scrolling to the Left direction. I have a private field with the name _acceleration, it’s how fast the ScrollViewer should be moving. The acceleration will increased based on the mouse X position. This will create a smother and more user friendly scrolling. My acceleration calculation code is based on a fixed width of the ScrollViwer, the width is set to 1024 pixels. I use Math.Pow to make sure the acceleration should not be linear. As you can see, the MouseMove will start the timer. The Tick event of the timer will make sure to move the ScrollViewer’s scroller.&lt;/P&gt;&lt;PRE class=csharpcode&gt;&lt;SPAN class=kwrd&gt;void&lt;/SPAN&gt; _thumbnailScrollTimer_Tick(&lt;SPAN class=kwrd&gt;object&lt;/SPAN&gt; sender, EventArgs e)
{
     thumbnailViewerScroller.ScrollToHorizontalOffset(thumbnailViewerScroller.HorizontalOffset + _acceleration);

     &lt;SPAN class=kwrd&gt;if&lt;/SPAN&gt; (thumbnailViewerScroller.HorizontalOffset + _acceleration &amp;lt;= 0)
        _thumbnailScrollTimer.Stop();
}&lt;/PRE&gt;
&lt;STYLE type=text/css&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/STYLE&gt;

&lt;P&gt;I use one if statement to make sure the Timer will stop when the ScrollViewer’s scroller is at the beginning of the ScrollViewer. I should also have one if it reaches the end of the ScrollViewer, but I don’t really know when it reaches the end, the HorizontalOffset value it’s based on the ScrollerViewer’s content, and that content can vary.&lt;/P&gt;
&lt;P&gt;Here is the code of a full working example:&lt;/P&gt;
&lt;P&gt;MainPage.xaml&lt;/P&gt;&lt;PRE class=csharpcode&gt;&lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;UserControl&lt;/SPAN&gt; &lt;SPAN class=attr&gt;x:Class&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="SilverlightApplication7.MainPage"&lt;/SPAN&gt;
    &lt;SPAN class=attr&gt;xmlns&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="http://schemas.microsoft.com/winfx/2006/xaml/presentation"&lt;/SPAN&gt; 
    &lt;SPAN class=attr&gt;xmlns:x&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="http://schemas.microsoft.com/winfx/2006/xaml"&lt;/SPAN&gt;
    &lt;SPAN class=attr&gt;xmlns:d&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="http://schemas.microsoft.com/expression/blend/2008"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;xmlns:mc&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="http://schemas.openxmlformats.org/markup-compatibility/2006"&lt;/SPAN&gt; 
    &lt;SPAN class=attr&gt;mc:Ignorable&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="d"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;d:DesignWidth&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="640"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;d:DesignHeight&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="480"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
  &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;Grid&lt;/SPAN&gt; &lt;SPAN class=attr&gt;x:Name&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="LayoutRoot"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;


        &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;StackPanel&lt;/SPAN&gt;
        &lt;SPAN class=attr&gt;x:Name&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="thumbnailViewer"&lt;/SPAN&gt;
        &lt;SPAN class=attr&gt;MouseMove&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="thumbnailViewer_MouseMove"&lt;/SPAN&gt;
        &lt;SPAN class=attr&gt;Background&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="Black"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;Height&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="208"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;Width&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="1024"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;

            &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;ScrollViewer&lt;/SPAN&gt;
                &lt;SPAN class=attr&gt;x:Name&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="thumbnailViewerScroller"&lt;/SPAN&gt;
                &lt;SPAN class=attr&gt;Padding&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="0"&lt;/SPAN&gt;
                &lt;SPAN class=attr&gt;BorderThickness&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="0"&lt;/SPAN&gt;
                &lt;SPAN class=attr&gt;VerticalScrollBarVisibility&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="Hidden"&lt;/SPAN&gt;
                &lt;SPAN class=attr&gt;HorizontalScrollBarVisibility&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="Hidden"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;

                &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;StackPanel&lt;/SPAN&gt; &lt;SPAN class=attr&gt;Orientation&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="Horizontal"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
                    &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;Rectangle&lt;/SPAN&gt; &lt;SPAN class=attr&gt;Width&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="200"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;Height&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="200"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;Fill&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="Red"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;Margin&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="4"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;Rectangle&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
                    &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;Rectangle&lt;/SPAN&gt; &lt;SPAN class=attr&gt;Width&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="200"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;Height&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="200"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;Fill&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="Red"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;Margin&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="4"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;Rectangle&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
                    &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;Rectangle&lt;/SPAN&gt; &lt;SPAN class=attr&gt;Width&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="200"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;Height&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="200"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;Fill&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="Red"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;Margin&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="4"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;Rectangle&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
                    &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;Rectangle&lt;/SPAN&gt; &lt;SPAN class=attr&gt;Width&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="200"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;Height&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="200"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;Fill&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="Red"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;Margin&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="4"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;Rectangle&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
                    &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;Rectangle&lt;/SPAN&gt; &lt;SPAN class=attr&gt;Width&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="200"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;Height&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="200"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;Fill&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="Red"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;Margin&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="4"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;Rectangle&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
                    &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;Rectangle&lt;/SPAN&gt; &lt;SPAN class=attr&gt;Width&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="200"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;Height&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="200"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;Fill&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="Red"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;Margin&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="4"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;Rectangle&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
                    &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;Rectangle&lt;/SPAN&gt; &lt;SPAN class=attr&gt;Width&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="200"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;Height&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="200"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;Fill&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="Red"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;Margin&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="4"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;Rectangle&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
                    &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;Rectangle&lt;/SPAN&gt; &lt;SPAN class=attr&gt;Width&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="200"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;Height&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="200"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;Fill&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="Red"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;Margin&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="4"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;Rectangle&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
                    &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;Rectangle&lt;/SPAN&gt; &lt;SPAN class=attr&gt;Width&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="200"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;Height&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="200"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;Fill&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="Red"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;Margin&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="4"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;Rectangle&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
                &lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;StackPanel&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
            
            &lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;ScrollViewer&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;

        &lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;StackPanel&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
  &lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;Grid&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
&lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;UserControl&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;STYLE type=text/css&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/STYLE&gt;

&lt;P&gt;&lt;BR&gt;MainPage.xaml.cs &lt;BR&gt;&lt;/P&gt;&lt;PRE class=csharpcode&gt;&lt;SPAN class=kwrd&gt;using&lt;/SPAN&gt; System;
&lt;SPAN class=kwrd&gt;using&lt;/SPAN&gt; System.Collections.Generic;
&lt;SPAN class=kwrd&gt;using&lt;/SPAN&gt; System.Linq;
&lt;SPAN class=kwrd&gt;using&lt;/SPAN&gt; System.Net;
&lt;SPAN class=kwrd&gt;using&lt;/SPAN&gt; System.Windows;
&lt;SPAN class=kwrd&gt;using&lt;/SPAN&gt; System.Windows.Controls;
&lt;SPAN class=kwrd&gt;using&lt;/SPAN&gt; System.Windows.Documents;
&lt;SPAN class=kwrd&gt;using&lt;/SPAN&gt; System.Windows.Input;
&lt;SPAN class=kwrd&gt;using&lt;/SPAN&gt; System.Windows.Media;
&lt;SPAN class=kwrd&gt;using&lt;/SPAN&gt; System.Windows.Media.Animation;
&lt;SPAN class=kwrd&gt;using&lt;/SPAN&gt; System.Windows.Shapes;
&lt;SPAN class=kwrd&gt;using&lt;/SPAN&gt; System.Windows.Threading;

&lt;SPAN class=kwrd&gt;namespace&lt;/SPAN&gt; SilverlightApplication7
{
    &lt;SPAN class=kwrd&gt;public&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;partial&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;class&lt;/SPAN&gt; MainPage : UserControl
    {
        &lt;SPAN class=kwrd&gt;private&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;int&lt;/SPAN&gt; _acceleration = 0;
        &lt;SPAN class=kwrd&gt;private&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;bool&lt;/SPAN&gt; _thumbnailScrolltTimerStarted;
        &lt;SPAN class=kwrd&gt;private&lt;/SPAN&gt; DispatcherTimer _thumbnailScrollTimer = &lt;SPAN class=kwrd&gt;new&lt;/SPAN&gt; DispatcherTimer();

        &lt;SPAN class=kwrd&gt;public&lt;/SPAN&gt; MainPage()
        {
            InitializeComponent();

            _thumbnailScrollTimer.Interval = &lt;SPAN class=kwrd&gt;new&lt;/SPAN&gt; TimeSpan(0, 0, 0, 0, 1);
            _thumbnailScrollTimer.Tick += &lt;SPAN class=kwrd&gt;new&lt;/SPAN&gt; EventHandler(_thumbnailScrollTimer_Tick);

        }

        &lt;SPAN class=kwrd&gt;void&lt;/SPAN&gt; _thumbnailScrollTimer_Tick(&lt;SPAN class=kwrd&gt;object&lt;/SPAN&gt; sender, EventArgs e)
        {
            thumbnailViewerScroller.ScrollToHorizontalOffset(thumbnailViewerScroller.HorizontalOffset + _acceleration);

            &lt;SPAN class=kwrd&gt;if&lt;/SPAN&gt; (thumbnailViewerScroller.HorizontalOffset + _acceleration &amp;lt;= 0)
                _thumbnailScrollTimer.Stop();
        }


        &lt;SPAN class=kwrd&gt;private&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;void&lt;/SPAN&gt; thumbnailViewer_MouseMove(&lt;SPAN class=kwrd&gt;object&lt;/SPAN&gt; sender, MouseEventArgs e)
        {
            var x = e.GetPosition(sender &lt;SPAN class=kwrd&gt;as&lt;/SPAN&gt; UIElement).X;

            &lt;SPAN class=kwrd&gt;if&lt;/SPAN&gt; (x &amp;gt;= 300 &amp;amp;&amp;amp; x &amp;lt;= 700)
            {
                _acceleration = 0;
                _thumbnailScrollTimer.Stop();
                _thumbnailScrolltTimerStarted = &lt;SPAN class=kwrd&gt;false&lt;/SPAN&gt;;
            }
            &lt;SPAN class=kwrd&gt;else&lt;/SPAN&gt;
            {
                &lt;SPAN class=kwrd&gt;if&lt;/SPAN&gt; (x &amp;gt; 700)
                    _acceleration = (&lt;SPAN class=kwrd&gt;int&lt;/SPAN&gt;)(Math.Pow((x - 512), 1.5) / 1200);
                &lt;SPAN class=kwrd&gt;else&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;if&lt;/SPAN&gt; (x &amp;lt; 300)
                    _acceleration = -(&lt;SPAN class=kwrd&gt;int&lt;/SPAN&gt;)(Math.Pow((512 - x), 1.5) / 1200);

                &lt;SPAN class=kwrd&gt;if&lt;/SPAN&gt; (!_thumbnailScrolltTimerStarted)
                    _thumbnailScrollTimer.Start();

                _thumbnailScrolltTimerStarted = &lt;SPAN class=kwrd&gt;true&lt;/SPAN&gt;;
            }

        }
    }
}&lt;/PRE&gt;
&lt;STYLE type=text/css&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/STYLE&gt;

&lt;P&gt;Feel free to send me any comments and feedback, you can also find me on twitter: &lt;A href="http://www.twitter.com/fredrikn" mce_href="http://www.twitter.com/fredrikn"&gt;http://www.twitter.com/fredrikn&lt;/A&gt;&lt;/P&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7210188" width="1" height="1"&gt;</content><author><name>Fredrik N</name><uri>http://weblogs.asp.net/members/Fredrik-N.aspx</uri></author><category term="Silverlight" scheme="http://weblogs.asp.net/fredriknormen/archive/tags/Silverlight/default.aspx" /></entry><entry><title>ASP.NET AJAX 4.0 Preview 5 – Working with Converters and the new CDN</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/fredriknormen/archive/2009/09/16/asp-net-ajax-4-0-preview-5-working-with-converters-and-the-new-cdn.aspx" /><id>http://weblogs.asp.net/fredriknormen/archive/2009/09/16/asp-net-ajax-4-0-preview-5-working-with-converters-and-the-new-cdn.aspx</id><published>2009-09-16T21:01:00Z</published><updated>2009-09-16T21:01:00Z</updated><content type="html">&lt;P&gt;In this blog post I’m going to show you how you can use the new Converter feature during data binding, to make this post more special I have used the new Microsoft AJAX CDN (Content Delivery Network), so I don’t need to have the AJAX 4.0 script on my server. The example code I use in this post, will use the ASP.NET AJAX DataView and also Microsoft ADO.NET Data Services to retrieve data from the server. My fantasy isn’t so special good, but I decided to make a little “rental” application, where I will use ASP.NET AJAX to simply show a list of cars and the current rental status. The status of a rental car will be sent to the client as a string and can be of the following values, Approved, Not Approved and Pending. The little app I’m building for this post, will show the rental status as different colors for the user. &lt;BR&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://weblogs.asp.net/blogs/fredriknormen/image_2FA7CAA1.png" mce_href="http://weblogs.asp.net/blogs/fredriknormen/image_2FA7CAA1.png"&gt;&lt;IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; DISPLAY: inline; BORDER-TOP: 0px; BORDER-RIGHT: 0px" title=image border=0 alt=image src="http://weblogs.asp.net/blogs/fredriknormen/image_thumb_72A3990E.png" width=392 height=390 mce_src="http://weblogs.asp.net/blogs/fredriknormen/image_thumb_72A3990E.png"&gt;&lt;/A&gt; &lt;/P&gt;
&lt;P&gt;&lt;BR&gt;Green color will show that the rental of the car is approved, red will indicate not approved and yellow will indicate a pending status. My little database have one simple table, called Rental (lack of fantasy), with three columns, ID, Description and Status. I have used Entity Framework together with ADO.Net Data Source to get the data from the database. Here is the ADO.NET Data Service, I have added a Rental operation to only enable access to the operation to get Rental entities. &lt;BR&gt;&lt;/P&gt;&lt;PRE class=csharpcode&gt;&lt;SPAN class=kwrd&gt;public&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;class&lt;/SPAN&gt; RentalWebDataService : DataService&amp;lt;RentalModel.RentalEntities&amp;gt;
{
    &lt;SPAN class=kwrd&gt;public&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;static&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;void&lt;/SPAN&gt; InitializeService(IDataServiceConfiguration config)
    {
        config.SetEntitySetAccessRule(&lt;SPAN class=str&gt;"Rental"&lt;/SPAN&gt;, EntitySetRights.AllRead);
        config.SetServiceOperationAccessRule(&lt;SPAN class=str&gt;"Rental"&lt;/SPAN&gt;, ServiceOperationRights.AllRead);
    }

    [WebGet]
    &lt;SPAN class=kwrd&gt;public&lt;/SPAN&gt; IQueryable&amp;lt;RentalModel.Rental&amp;gt; Rental()
    {
        &lt;SPAN class=kwrd&gt;return&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;this&lt;/SPAN&gt;.CurrentDataSource.Rental;
    }
}&lt;/PRE&gt;
&lt;STYLE type=text/css&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/STYLE&gt;

&lt;P&gt;To use ASP.NET AJAX 4.0 Preview 5, I have not used my local scripts, instead use the new Microsoft AJAX CDN. The Microsoft CDN service provides caching support for AJAX libraries (including jQuery and ASP.NET AJAX) and are composed of “edge cache” servers, they are strategically placed around the world to make sure your application will use the nearest server to get the ASP.NET AJAX scripts, isn’t that cool?! The service is free and both for commercial and non-commercial purpose. To get a JavaScript from the Microsoft CDN, you can simply use the &amp;lt;script&amp;gt; tag to include the script from &lt;A href="http://ajax.microsoft.com/ajax" mce_href="http://ajax.microsoft.com/ajax"&gt;”http://ajax.microsoft.com/ajax&lt;/A&gt;”. Microsoft CND will use sub folders to versioning the different kind of scripts. The ASP.NET AJAX 4.0 Preview 5.0 script can be found under the /0909/ folder (the name of the folder represents the year and month when the ASP.NET AJAX was released). You can find the JavaScript and URLs here: &lt;A title=http://www.asp.net/ajax/cdn/ href="http://www.asp.net/ajax/cdn/" mce_href="http://www.asp.net/ajax/cdn/"&gt;http://www.asp.net/ajax/cdn/&lt;/A&gt; &lt;BR&gt;&lt;/P&gt;
&lt;P&gt;Note: ScriptManger can automatically request JavaScript files form the Microsoft CDN if the EnableCdn property of the ScriptManager is set to true.&lt;/P&gt;
&lt;P&gt;&lt;BR&gt;I have used the following code to include the ASP.NET AJAX 4.0 Preview 5.0 script in my demo, to make sure I can use Templates, and ADO.NET DataServices: &lt;BR&gt;&lt;/P&gt;&lt;PRE class=csharpcode&gt;&lt;SPAN class=html&gt;&amp;lt;script&lt;/SPAN&gt; &lt;SPAN class=attr&gt;src&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="http://ajax.microsoft.com/ajax/beta/0909/MicrosoftAjax.js"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;type&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="text/javascript"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;script&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;&lt;BR&gt;&lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;script&lt;/SPAN&gt; &lt;SPAN class=attr&gt;src&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="http://ajax.microsoft.com/ajax/beta/0909/MicrosoftAjaxTemplates.js"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;type&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="text/javascript"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;script&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
&amp;lt;script src=&lt;SPAN class=str&gt;"http://ajax.microsoft.com/ajax/beta/0909/MicrosoftAjaxAdoNet.js"&lt;/SPAN&gt; type=&lt;SPAN class=str&gt;"text/javascript"&lt;/SPAN&gt;&amp;gt;&lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;script&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;script&lt;/SPAN&gt; &lt;SPAN class=attr&gt;src&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="http://ajax.microsoft.com/ajax/beta/0909/MicrosoftAjaxDataContext.js"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;type&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="text/javascript"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;script&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;STYLE type=text/css&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/STYLE&gt;

&lt;P&gt;&lt;BR&gt;To use the ADO.NET Data Service (RentalWebDataSerivce) on the client-side, the ASP.NET AJAX $create shortcut can be used to create a ADO.Net DataContext object, the DataContex is the proxy class to access the ADO.Net Data Service: &lt;BR&gt;&lt;/P&gt;&lt;PRE class=csharpcode&gt;&lt;SPAN class=kwrd&gt;var&lt;/SPAN&gt; RentalService = {};

RentalService.dataContext = $create(Sys.Data.AdoNetDataContext,
                                         {
                                             serviceUri: &lt;SPAN class=str&gt;"RentalWebDataService.svc"&lt;/SPAN&gt;,
                                             mergeOption: Sys.Data.MergeOption.appendOnly
                                         });&lt;/PRE&gt;
&lt;STYLE type=text/css&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/STYLE&gt;

&lt;P&gt;The following is the template I have used to list the cars: &lt;BR&gt;&lt;/P&gt;&lt;PRE class=csharpcode&gt; &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;table&lt;/SPAN&gt; &lt;SPAN class=attr&gt;sys:attach&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="dataview"&lt;/SPAN&gt;
        &lt;SPAN class=attr&gt;class&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="sys-template"&lt;/SPAN&gt;
        &lt;SPAN class=attr&gt;dataview:dataprovider&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="{{ RentalService.dataContext }}"&lt;/SPAN&gt;
        &lt;SPAN class=attr&gt;dataview:fetchoperation&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="Rental"&lt;/SPAN&gt;
        &lt;SPAN class=attr&gt;dataview:autofetch&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="true"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;

        &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;tr&lt;/SPAN&gt; &lt;SPAN class=attr&gt;sys:if&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="$index==0"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
            &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;td&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;Booking No&lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;td&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
            &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;td&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;Description&lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;td&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
        &lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;tr&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
        
         &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;tr&lt;/SPAN&gt; &lt;SPAN class=attr&gt;sys:style-background-color&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="{binding Status, convert=convertStatusToColor, ColorType=Name}"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
             &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;td&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;{{ ID }}&lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;td&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
             &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;td&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;{{ Description }}&lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;td&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
         &lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;tr&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
&lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;table&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;STYLE type=text/css&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/STYLE&gt;

&lt;P&gt;&lt;BR&gt;Yes, I know, I use a table instead of a DIV, shame on me..&lt;/P&gt;
&lt;P&gt;To create a template the class=”sys-template” must be applied to the root element of the template, the sys:attached=”dataview” will indicate that I will use the ASP.NET AJAX 4.0 DataView features together with the template. To make sure the DataView will get its data from the RentalWebDataService, the dataview:dataprovider attribute is used and its value is set to the RentalService.dataContext object, the DataView’s autofecth property is also set to true, to automatically fetch data. The fetchoperation property will specify which operation of the RentalWebDataServices should be used when the DataView fetches the data.&lt;/P&gt;
&lt;P&gt;There are two ways to bind data within a template, for example the short {{ field }} expression or the {binding field} expression. As you can see I have used both expressions in the template, one for the background-color style (to bind a value to a specific style attribute, the sys:style-&amp;lt;style&amp;gt; attribute is used). The {{ ID }} and {{ Description }} shortcut will make sure to get the data from the Rental’s (The entity returned from the Rental operation of the RentalWebDataService ) ID and Description property. Take a look at the binding expression used for the &amp;lt;tr&amp;gt; background-color style: &lt;BR&gt;&lt;/P&gt;&lt;PRE class=csharpcode&gt;&lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;tr&lt;/SPAN&gt; &lt;SPAN class=attr&gt;sys:style-background-color&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="{binding Status, convert=convertStatusToColor, ColorType=Name}"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;STYLE type=text/css&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/STYLE&gt;

&lt;P&gt;&lt;BR&gt;There is now an option to specify a Converter, a method which will take the bounded value and pass it as an argument to the specified method and do a conversion and return a new whole value. The Status property in my case returns a string with different kind of status, Approved, NotApproved and Pending. What I want to do, is to convert those values into different colors as I mention earlier in my post. To do that I have used the new Converter feature. To set up a converter is easy just use the Sys.Binding.converters property and assign a method to it with two arguments, the value to convert and a binding argument (holds information about the binding). &lt;BR&gt;&lt;/P&gt;&lt;PRE class=csharpcode&gt;Sys.Binding.converters.convertStatusToColor = &lt;SPAN class=kwrd&gt;function&lt;/SPAN&gt;(status, binding)
{
     &lt;SPAN class=rem&gt;//do something then return the converted value&lt;/SPAN&gt;
}&lt;/PRE&gt;
&lt;STYLE type=text/css&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/STYLE&gt;

&lt;P&gt;One great thing with the converter, is the possibility to use expandos, for example in my code I have added a ColorType expando to specify if the color that returned from the converter should be a name or not. The binding argument of the converter method can be used to get the expando, for example:&lt;/P&gt;&lt;PRE class=csharpcode&gt;&lt;SPAN class=str&gt;"{binding Status, convert=convertStatusToColor, ColorType=Name}"&lt;/SPAN&gt;


Sys.Binding.converters.convertStatusToColor = function(status, binding)
{
    &lt;SPAN class=kwrd&gt;if&lt;/SPAN&gt;( binding.ColorName == &lt;SPAN class=str&gt;'Name'&lt;/SPAN&gt;)
          &lt;SPAN class=rem&gt;//....&lt;/SPAN&gt;
     &lt;SPAN class=rem&gt;//do something then return the converted value&lt;/SPAN&gt;
}&lt;/PRE&gt;
&lt;STYLE type=text/css&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/STYLE&gt;

&lt;P&gt;I have created the ugliest converter method ever made, here it is: &lt;BR&gt;&lt;/P&gt;&lt;PRE class=csharpcode&gt;Sys.Binding.converters.convertStatusToColor = &lt;SPAN class=kwrd&gt;function&lt;/SPAN&gt;(status, binding)
{
       &lt;SPAN class=kwrd&gt;if&lt;/SPAN&gt; (binding.ColorType == &lt;SPAN class=str&gt;'Name'&lt;/SPAN&gt;)
      {
             &lt;SPAN class=kwrd&gt;if&lt;/SPAN&gt; (status == &lt;SPAN class=str&gt;'Approved'&lt;/SPAN&gt;)
                    &lt;SPAN class=kwrd&gt;return&lt;/SPAN&gt; &lt;SPAN class=str&gt;'green'&lt;/SPAN&gt;;
                &lt;SPAN class=kwrd&gt;else&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;if&lt;/SPAN&gt; (status == &lt;SPAN class=str&gt;'NotApproved'&lt;/SPAN&gt;)
                    &lt;SPAN class=kwrd&gt;return&lt;/SPAN&gt; &lt;SPAN class=str&gt;'red'&lt;/SPAN&gt;;
                &lt;SPAN class=kwrd&gt;else&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;if&lt;/SPAN&gt; (status == &lt;SPAN class=str&gt;'Pending'&lt;/SPAN&gt;)
                    &lt;SPAN class=kwrd&gt;return&lt;/SPAN&gt; &lt;SPAN class=str&gt;'yellow'&lt;/SPAN&gt;;
                &lt;SPAN class=kwrd&gt;else&lt;/SPAN&gt;
                    &lt;SPAN class=kwrd&gt;return&lt;/SPAN&gt; &lt;SPAN class=str&gt;'white'&lt;/SPAN&gt;;
        }
        &lt;SPAN class=kwrd&gt;else&lt;/SPAN&gt;
       {
             &lt;SPAN class=kwrd&gt;if&lt;/SPAN&gt; (status == &lt;SPAN class=str&gt;"Approved"&lt;/SPAN&gt;)
                 &lt;SPAN class=kwrd&gt;return&lt;/SPAN&gt; &lt;SPAN class=str&gt;'#00ff00'&lt;/SPAN&gt;;
             &lt;SPAN class=kwrd&gt;else&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;if&lt;/SPAN&gt; (status == &lt;SPAN class=str&gt;"NotApproved"&lt;/SPAN&gt;)
                 &lt;SPAN class=kwrd&gt;return&lt;/SPAN&gt; &lt;SPAN class=str&gt;'#ff0000'&lt;/SPAN&gt;;
             &lt;SPAN class=kwrd&gt;else&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;if&lt;/SPAN&gt; (status == &lt;SPAN class=str&gt;'Pending'&lt;/SPAN&gt;)
                 &lt;SPAN class=kwrd&gt;return&lt;/SPAN&gt; &lt;SPAN class=str&gt;'#ffff00'&lt;/SPAN&gt;;
             &lt;SPAN class=kwrd&gt;else&lt;/SPAN&gt;
                 &lt;SPAN class=kwrd&gt;return&lt;/SPAN&gt; &lt;SPAN class=str&gt;'#ffffff'&lt;/SPAN&gt;;
        }
}&lt;/PRE&gt;
&lt;STYLE type=text/css&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/STYLE&gt;

&lt;P&gt;Well, it’s a simple method to convert the incoming string, and return a color for the &amp;lt;tr&amp;gt;’s background-color. Here is the whole client-side code: &lt;BR&gt;&lt;BR&gt;&lt;/P&gt;&lt;PRE class=csharpcode&gt;&lt;SPAN class=asp&gt;&amp;lt;%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %&amp;gt;&lt;/SPAN&gt;

&lt;SPAN class=kwrd&gt;&amp;lt;!&lt;/SPAN&gt;&lt;SPAN class=html&gt;DOCTYPE&lt;/SPAN&gt; &lt;SPAN class=attr&gt;html&lt;/SPAN&gt; &lt;SPAN class=attr&gt;PUBLIC&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;"-//W3C//DTD XHTML 1.0 Transitional//EN"&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;

&lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;html&lt;/SPAN&gt; &lt;SPAN class=attr&gt;xmlns&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="http://www.w3.org/1999/xhtml"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
&lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;head&lt;/SPAN&gt; &lt;SPAN class=attr&gt;runat&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="server"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
    &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;title&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;title&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
    &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;script&lt;/SPAN&gt; &lt;SPAN class=attr&gt;src&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="http://ajax.microsoft.com/ajax/beta/0909/MicrosoftAjax.js"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;type&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="text/javascript"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;script&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt; 
    &amp;lt;script src=&lt;SPAN class=str&gt;"http://ajax.microsoft.com/ajax/beta/0909/MicrosoftAjaxTemplates.js"&lt;/SPAN&gt; type=&lt;SPAN class=str&gt;"text/javascript"&lt;/SPAN&gt;&amp;gt;&amp;lt;/script&amp;gt;
    &amp;lt;script src=&lt;SPAN class=str&gt;"http://ajax.microsoft.com/ajax/beta/0909/MicrosoftAjaxAdoNet.js"&lt;/SPAN&gt; type=&lt;SPAN class=str&gt;"text/javascript"&lt;/SPAN&gt;&amp;gt;&amp;lt;/script&amp;gt;
    &amp;lt;script src=&lt;SPAN class=str&gt;"http://ajax.microsoft.com/ajax/beta/0909/MicrosoftAjaxDataContext.js"&lt;/SPAN&gt; type=&lt;SPAN class=str&gt;"text/javascript"&lt;/SPAN&gt;&amp;gt;&amp;lt;/script&amp;gt;


    &amp;lt;script type=&lt;SPAN class=str&gt;"text/javascript"&lt;/SPAN&gt;&amp;gt;

        &lt;SPAN class=kwrd&gt;var&lt;/SPAN&gt; RentalService = {};

        RentalService.dataContext = $create(Sys.Data.AdoNetDataContext,
                                         {
                                             serviceUri: &lt;SPAN class=str&gt;"RentalWebDataService.svc"&lt;/SPAN&gt;,
                                             mergeOption: Sys.Data.MergeOption.appendOnly
                                         });


        Sys.Binding.converters.convertStatusToColor = &lt;SPAN class=kwrd&gt;function&lt;/SPAN&gt;(status, binding) {

            &lt;SPAN class=kwrd&gt;if&lt;/SPAN&gt; (binding.ColorType == &lt;SPAN class=str&gt;'Name'&lt;/SPAN&gt;) {

                &lt;SPAN class=kwrd&gt;if&lt;/SPAN&gt; (status == &lt;SPAN class=str&gt;'Approved'&lt;/SPAN&gt;)
                    &lt;SPAN class=kwrd&gt;return&lt;/SPAN&gt; &lt;SPAN class=str&gt;'green'&lt;/SPAN&gt;;
                &lt;SPAN class=kwrd&gt;else&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;if&lt;/SPAN&gt; (status == &lt;SPAN class=str&gt;'NotApproved'&lt;/SPAN&gt;)
                    &lt;SPAN class=kwrd&gt;return&lt;/SPAN&gt; &lt;SPAN class=str&gt;'red'&lt;/SPAN&gt;;
                &lt;SPAN class=kwrd&gt;else&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;if&lt;/SPAN&gt; (status == &lt;SPAN class=str&gt;'Pending'&lt;/SPAN&gt;)
                    &lt;SPAN class=kwrd&gt;return&lt;/SPAN&gt; &lt;SPAN class=str&gt;'yellow'&lt;/SPAN&gt;;
                &lt;SPAN class=kwrd&gt;else&lt;/SPAN&gt;
                    &lt;SPAN class=kwrd&gt;return&lt;/SPAN&gt; &lt;SPAN class=str&gt;'white'&lt;/SPAN&gt;;
            }
            &lt;SPAN class=kwrd&gt;else&lt;/SPAN&gt; {
                &lt;SPAN class=kwrd&gt;if&lt;/SPAN&gt; (status == &lt;SPAN class=str&gt;"Approved"&lt;/SPAN&gt;)
                    &lt;SPAN class=kwrd&gt;return&lt;/SPAN&gt; &lt;SPAN class=str&gt;'#00ff00'&lt;/SPAN&gt;;
                &lt;SPAN class=kwrd&gt;else&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;if&lt;/SPAN&gt; (status == &lt;SPAN class=str&gt;"NotApproved"&lt;/SPAN&gt;)
                    &lt;SPAN class=kwrd&gt;return&lt;/SPAN&gt; &lt;SPAN class=str&gt;'#ff0000'&lt;/SPAN&gt;;
                &lt;SPAN class=kwrd&gt;else&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;if&lt;/SPAN&gt; (status == &lt;SPAN class=str&gt;'Pending'&lt;/SPAN&gt;)
                    &lt;SPAN class=kwrd&gt;return&lt;/SPAN&gt; &lt;SPAN class=str&gt;'#ffff00'&lt;/SPAN&gt;;
                &lt;SPAN class=kwrd&gt;else&lt;/SPAN&gt;
                    &lt;SPAN class=kwrd&gt;return&lt;/SPAN&gt; &lt;SPAN class=str&gt;'#ffffff'&lt;/SPAN&gt;;
            }
        }

    &lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;script&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
    
    &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;style&lt;/SPAN&gt; &lt;SPAN class=attr&gt;type&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="text/css"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
        .sys-template { display:none; }
    &lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;style&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;

&lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;head&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
&lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;body&lt;/SPAN&gt; &lt;SPAN class=attr&gt;xmlns:sys&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="javascript:Sys"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;xmlns:dataview&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="javascript:Sys.UI.DataView"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
    
    &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;table&lt;/SPAN&gt; &lt;SPAN class=attr&gt;sys:attach&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="dataview"&lt;/SPAN&gt;
        &lt;SPAN class=attr&gt;class&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="sys-template"&lt;/SPAN&gt;
        &lt;SPAN class=attr&gt;dataview:dataprovider&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="{{ RentalService.dataContext }}"&lt;/SPAN&gt;
        &lt;SPAN class=attr&gt;dataview:fetchoperation&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="Rental"&lt;/SPAN&gt;
        &lt;SPAN class=attr&gt;dataview:autofetch&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="true"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;

        &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;tr&lt;/SPAN&gt; &lt;SPAN class=attr&gt;sys:if&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="$index==0"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
            &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;td&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;Booking No&lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;td&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
            &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;td&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;Description&lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;td&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
        &lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;tr&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
        
         &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;tr&lt;/SPAN&gt; &lt;SPAN class=attr&gt;sys:style-background-color&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="{binding Status, convert=convertStatusToColor, ColorType=Name}"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
             &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;td&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;{{ ID }}&lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;td&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
             &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;td&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;{{ Description }}&lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;td&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
         &lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;tr&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
    &lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;table&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
    
&lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;body&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
&lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;html&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;STYLE type=text/css&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/STYLE&gt;

&lt;P&gt;&lt;STRONG&gt;Summary&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;In this blog post you have seen how to data bind and use the DataView to do client-side binding to a ADO.NET Data Service, you have also got introduced to the Microsoft AJAX NDC, if you want to get more information about the NDC, check out Scott Guthrie's blog: &lt;A title=http://weblogs.asp.net/scottgu/archive/2009/09/15/announcing-the-microsoft-ajax-cdn.aspx href="http://weblogs.asp.net/scottgu/archive/2009/09/15/announcing-the-microsoft-ajax-cdn.aspx" mce_href="http://weblogs.asp.net/scottgu/archive/2009/09/15/announcing-the-microsoft-ajax-cdn.aspx"&gt;http://weblogs.asp.net/scottgu/archive/2009/09/15/announcing-the-microsoft-ajax-cdn.aspx&lt;/A&gt;, you have also seen the new Preview 5 converter feature.&lt;/P&gt;
&lt;P&gt;To find more information about ASP.NET AJAX 4.0 Preview 5.0, you can check out my two earlier posts:&lt;/P&gt;
&lt;P&gt;&lt;A title=http://weblogs.asp.net/fredriknormen/archive/2009/09/11/asp-net-ajax-4-0-preview-5-available.aspx href="http://weblogs.asp.net/fredriknormen/archive/2009/09/11/asp-net-ajax-4-0-preview-5-available.aspx" mce_href="http://weblogs.asp.net/fredriknormen/archive/2009/09/11/asp-net-ajax-4-0-preview-5-available.aspx"&gt;http://weblogs.asp.net/fredriknormen/archive/2009/09/11/asp-net-ajax-4-0-preview-5-available.aspx&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;A title=http://weblogs.asp.net/fredriknormen/archive/2009/09/11/keep-the-first-empty-item-in-a-listbox-when-using-asp-net-ajax-4-0-preview-5-and-observer.aspx href="http://weblogs.asp.net/fredriknormen/archive/2009/09/11/keep-the-first-empty-item-in-a-listbox-when-using-asp-net-ajax-4-0-preview-5-and-observer.aspx" mce_href="http://weblogs.asp.net/fredriknormen/archive/2009/09/11/keep-the-first-empty-item-in-a-listbox-when-using-asp-net-ajax-4-0-preview-5-and-observer.aspx"&gt;http://weblogs.asp.net/fredriknormen/archive/2009/09/11/keep-the-first-empty-item-in-a-listbox-when-using-asp-net-ajax-4-0-preview-5-and-observer.aspx&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Jim, Dave and Bertrand Le Roy’s posts on Preview 5: &lt;BR&gt;&lt;A href="http://weblogs.asp.net/jimwang/archive/2009/09/11/asp-net-ajax-preview-5-and-updatepanel.aspx" mce_href="http://weblogs.asp.net/jimwang/archive/2009/09/11/asp-net-ajax-preview-5-and-updatepanel.aspx"&gt;http://weblogs.asp.net/jimwang/archive/2009/09/11/asp-net-ajax-preview-5-and-updatepanel.aspx&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://weblogs.asp.net/infinitiesloop/archive/2009/09/10/microsoft-ajax-4-preview-5-the-dataview-control.aspx" mce_href="http://weblogs.asp.net/infinitiesloop/archive/2009/09/10/microsoft-ajax-4-preview-5-the-dataview-control.aspx"&gt;http://weblogs.asp.net/infinitiesloop/archive/2009/09/10/microsoft-ajax-4-preview-5-the-dataview-control.aspx&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;A title=http://weblogs.asp.net/bleroy/archive/2009/09/14/building-a-class-browser-with-microsoft-ajax-4-0-preview-5.aspx href="http://weblogs.asp.net/bleroy/archive/2009/09/14/building-a-class-browser-with-microsoft-ajax-4-0-preview-5.aspx" mce_href="http://weblogs.asp.net/bleroy/archive/2009/09/14/building-a-class-browser-with-microsoft-ajax-4-0-preview-5.aspx"&gt;http://weblogs.asp.net/bleroy/archive/2009/09/14/building-a-class-browser-with-microsoft-ajax-4-0-preview-5.aspx&lt;/A&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;STYLE type=text/css&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/STYLE&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7208540" width="1" height="1"&gt;</content><author><name>Fredrik N</name><uri>http://weblogs.asp.net/members/Fredrik-N.aspx</uri></author><category term="ASP.Net" scheme="http://weblogs.asp.net/fredriknormen/archive/tags/ASP.Net/default.aspx" /><category term="AXAJ" scheme="http://weblogs.asp.net/fredriknormen/archive/tags/AXAJ/default.aspx" /><category term="CDN" scheme="http://weblogs.asp.net/fredriknormen/archive/tags/CDN/default.aspx" /><category term="ASP.NET AJAX" scheme="http://weblogs.asp.net/fredriknormen/archive/tags/ASP.NET+AJAX/default.aspx" /></entry><entry><title>Use a ResourceDictionay and an external resources located in an assembly</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/fredriknormen/archive/2009/09/16/use-a-resourcedictionay-and-an-external-resources-located-in-an-assembly.aspx" /><id>http://weblogs.asp.net/fredriknormen/archive/2009/09/16/use-a-resourcedictionay-and-an-external-resources-located-in-an-assembly.aspx</id><published>2009-09-16T12:09:00Z</published><updated>2009-09-16T12:09:00Z</updated><content type="html">&lt;P&gt;I have notice that some developers are asking questions about how to use a ResourceDictionary and reference it to a resource located in a separate assembly. Here is a simple step by step guide to make it possible, I assume you already have a Silverlight project created:&lt;/P&gt;
&lt;P&gt;1) Create a new Silverlight Class Library &lt;BR&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://weblogs.asp.net/blogs/fredriknormen/image_4F6F1194.png" mce_href="http://weblogs.asp.net/blogs/fredriknormen/image_4F6F1194.png"&gt;&lt;IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; DISPLAY: inline; BORDER-TOP: 0px; BORDER-RIGHT: 0px" title=image border=0 alt=image src="http://weblogs.asp.net/blogs/fredriknormen/image_thumb_191DE985.png" width=484 height=310 mce_src="http://weblogs.asp.net/blogs/fredriknormen/image_thumb_191DE985.png"&gt;&lt;/A&gt; &lt;/P&gt;
&lt;P&gt;&lt;BR&gt;2) Add a Silverlight Resource Dictionary file to the Class Library project &lt;BR&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://weblogs.asp.net/blogs/fredriknormen/image_17D950A6.png" mce_href="http://weblogs.asp.net/blogs/fredriknormen/image_17D950A6.png"&gt;&lt;IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; DISPLAY: inline; BORDER-TOP: 0px; BORDER-RIGHT: 0px" title=image border=0 alt=image src="http://weblogs.asp.net/blogs/fredriknormen/image_thumb_2B863A3A.png" width=501 height=302 mce_src="http://weblogs.asp.net/blogs/fredriknormen/image_thumb_2B863A3A.png"&gt;&lt;/A&gt; &lt;/P&gt;
&lt;P&gt;&lt;BR&gt;3) Add your styles to it and build &lt;BR&gt;&lt;BR&gt;&lt;BR&gt;&lt;A href="http://weblogs.asp.net/blogs/fredriknormen/image_4E66FBEA.png" mce_href="http://weblogs.asp.net/blogs/fredriknormen/image_4E66FBEA.png"&gt;&lt;IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; DISPLAY: inline; BORDER-TOP: 0px; BORDER-RIGHT: 0px" title=image border=0 alt=image src="http://weblogs.asp.net/blogs/fredriknormen/image_thumb_08E1FBBF.png" width=581 height=461 mce_src="http://weblogs.asp.net/blogs/fredriknormen/image_thumb_08E1FBBF.png"&gt;&lt;/A&gt; &lt;BR&gt;&lt;/P&gt;
&lt;P&gt;4) From your Silverlight Application, add a reference to the Silverlight Class Library Project or assembly file &lt;BR&gt;&lt;BR&gt;&lt;A href="http://weblogs.asp.net/blogs/fredriknormen/image_007E2668.png" mce_href="http://weblogs.asp.net/blogs/fredriknormen/image_007E2668.png"&gt;&lt;IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; DISPLAY: inline; BORDER-TOP: 0px; BORDER-RIGHT: 0px" title=image border=0 alt=image src="http://weblogs.asp.net/blogs/fredriknormen/image_thumb_586B7748.png" width=489 height=414 mce_src="http://weblogs.asp.net/blogs/fredriknormen/image_thumb_586B7748.png"&gt;&lt;/A&gt; &lt;BR&gt;&lt;/P&gt;
&lt;P&gt;5) In the Resource property of the App, or UserContorl etc add a ResourceDictionary element, set the source property by using the following pattern ”/&amp;lt;assembly&amp;gt;;component/&amp;lt;resource&amp;gt;.xaml”. If the name of your Silverligth Class Library is ”MyClassLib” and have a Resource Dictionary file called MyDictionary.xaml in the root folder of the Silverlight Class Library, the Source property should have the following value: &lt;/P&gt;
&lt;P&gt;&amp;lt;ResourceDictionary Source=”/MyClassLib;component/MyDictionary.xaml”/&amp;gt;&lt;/P&gt;
&lt;P&gt;&lt;BR&gt;&lt;A href="http://weblogs.asp.net/blogs/fredriknormen/image_29398BB1.png" mce_href="http://weblogs.asp.net/blogs/fredriknormen/image_29398BB1.png"&gt;&lt;IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; DISPLAY: inline; BORDER-TOP: 0px; BORDER-RIGHT: 0px" title=image border=0 alt=image src="http://weblogs.asp.net/blogs/fredriknormen/image_thumb_63B48B85.png" width=585 height=464 mce_src="http://weblogs.asp.net/blogs/fredriknormen/image_thumb_63B48B85.png"&gt;&lt;/A&gt; &lt;BR&gt;&lt;BR&gt;6) You can now use the styles.&lt;/P&gt;
&lt;P&gt;&lt;BR&gt;If you don’t have more than just a Dictionary Resources added to the Assembly, and want to share the resources to other Silverlight app, just use a simple .xaml file which you copy and share among the different Silverlight apps, easier to add and use, and you can avoid extra dependencies to an assembly and adding references. Only use an assembly with a resource if you want to protect the resource so others can’t change your original resource, or have controls or other logic added into your assembly which you are going to use in your Silverlight app.&lt;/P&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7207992" width="1" height="1"&gt;</content><author><name>Fredrik N</name><uri>http://weblogs.asp.net/members/Fredrik-N.aspx</uri></author><category term="Silverlight 3.0" scheme="http://weblogs.asp.net/fredriknormen/archive/tags/Silverlight+3.0/default.aspx" /></entry><entry><title>Silverlight and scaling</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/fredriknormen/archive/2009/09/15/silverlight-and-scaling.aspx" /><id>http://weblogs.asp.net/fredriknormen/archive/2009/09/15/silverlight-and-scaling.aspx</id><published>2009-09-15T14:00:00Z</published><updated>2009-09-15T14:00:00Z</updated><content type="html">&lt;P&gt;I have tried so many different ways to scale a Silverlight app while resizing the browser. When I almost got everything to work, the Grid control start to behave really strange, start to clip my app. Why should it be so hard to get scaling to work, why not just add a property to the Silverlight host, scaling=”enable”, and it will automatically scale our Silverlight app. After some time I got everything to work perfectly and thought maybe some other people would be interested in how to create a Silverlight app that can scale, so here is my solution. This post will ONLY focus on scaling the whole Silverlight host content with the ScalingTransform feature, to make the app fit into any kind of resolution. The code is tested on Silverlight 3.0.&lt;/P&gt;
&lt;P&gt;To get scaling to work we need to have a Canvas as our root element, if not, we can’t get it to work perfectly, if we for example should have used the Grid layout control as our root element, it will start cutting your app like a cutting machine, the worst possible scaling enemy. Best way to get an app scale perfectly is to not have a fixed size on the User Control and let the host control have the size set to 100%. We need to have a default size of our app, for example 1024x768 to make sure we have a number to use in our calculation to get the correct width and height ratio. Make sure to only add one child element to the Canvas, and that should be the “root” element of your content. For example: &lt;BR&gt;&lt;/P&gt;&lt;PRE class=csharpcode&gt;&lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;Canvas&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
        &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;Grid&lt;/SPAN&gt; &lt;SPAN class=attr&gt;x:Name&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="contentRoot"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
            &lt;SPAN class=rem&gt;&amp;lt;!-- Add your content here --&amp;gt;&lt;/SPAN&gt;
        &lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;Grid&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
&lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;Canvas&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;STYLE type=text/css&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/STYLE&gt;

&lt;P&gt;The child element of the Canvas, don’t need to be a Grid layout control, we can instead for example use a StackPanel or other layout control which we want to be our new “LayoutRoot” element (referring to the default Silvelright template, where the User Control’s first element is named “LayoutRoot”). If we want to set the first child element of the Canvas to a specific size, we must also make sure it will be our default (idle) size which will be used in the scaling calculation in our code. We can use different events to perform our scaling calculation and set the scaling, for example a FrameworkElement’s SizeChanged event, such as the UserControl.SizeChanged event (as long as the User Control doesn’t have a fixed size), we can also use the Application.Host.Content.Resized event (will only work if we don’t have a fixed size on our Silverlight host, will execute the first time the app is started, but will not be trigged when we resize the browser window). In this post I will use the Application.Host.Content.Resized event. We can hook up to the Resized event in the constructor of our app. &lt;BR&gt;&lt;/P&gt;&lt;PRE class=csharpcode&gt;&lt;SPAN class=kwrd&gt;public&lt;/SPAN&gt; ScaleableContent()
{
      Application.Current.Host.Content.Resized += &lt;SPAN class=kwrd&gt;new&lt;/SPAN&gt; EventHandler(Content_Resized);
}

&lt;SPAN class=kwrd&gt;void&lt;/SPAN&gt; Content_Resized(&lt;SPAN class=kwrd&gt;object&lt;/SPAN&gt; sender, EventArgs e)
{
}&lt;/PRE&gt;
&lt;STYLE type=text/css&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/STYLE&gt;

&lt;P&gt;&lt;BR&gt;For our default (idle) size for the scaling calculation we can either use a private field or get the information from our Canvas’s child element if we have given it a size. For a normal web page, the recommended size seems still to be 1024x768, so why not use that. I decided to use a private field of type Size. &lt;BR&gt;&lt;/P&gt;&lt;PRE class=csharpcode&gt;&lt;SPAN class=kwrd&gt;private&lt;/SPAN&gt; Size _contentActualSize = &lt;SPAN class=kwrd&gt;new&lt;/SPAN&gt; Size(1024, 768);&lt;BR&gt;&lt;BR&gt;&lt;/PRE&gt;
&lt;P&gt;When we resize our browser we need to get the ratio between our idle size and the browser window’s size. The formula for this is really simple, everyone should have learned it in school ;) We add the calculation code to the Resized event. &lt;BR&gt;&lt;/P&gt;&lt;PRE class=csharpcode&gt;var hostContentActualHeight = Application.Current.Host.Content.ActualHeight;
var hostContentActualWidth = Application.Current.Host.Content.ActualWidth;

var heightRatio = hostContentActualHeight / _contentActualSize.Height;
var widthRatio = hostContentActualWidth / _contentActualSize.Width;&lt;/PRE&gt;
&lt;STYLE type=text/css&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/STYLE&gt;

&lt;P&gt;&lt;BR&gt;The Application.Current.Host.Content.ActualHeight and ActualWidth will give us the browser’s content size (or to be correct the size of the host content). We divide it with our default size to get the ratio between our default size and the browser's content size. We use this ratio to create a ScalingTransform and set it the RenderTransform property of Canvas’s child element. &lt;BR&gt;&lt;/P&gt;&lt;PRE class=csharpcode&gt;var ratio = &lt;SPAN class=kwrd&gt;1.0&lt;/SPAN&gt;;

&lt;SPAN class=kwrd&gt;if&lt;/SPAN&gt; (heightRatio &amp;lt; widthRatio &amp;amp;&amp;amp; heightRatio &amp;lt; 1)
   ratio = heightRatio;
&lt;SPAN class=kwrd&gt;else &lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;if&lt;/SPAN&gt; (widthRatio &amp;lt; 1)
   ratio = widthRatio;&lt;BR&gt;
&lt;BR&gt;&lt;BR&gt;contentRoot.RenderTransform = new ScaleTransform() { ScaleY = ratio, ScaleX = ratio };
&lt;BR&gt;&lt;/PRE&gt;
&lt;STYLE type=text/css&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/STYLE&gt;

&lt;P&gt;The ScaleY and ScaleX property uses a decimal value, where 0.5 is 50% of the original size, and 1 is 100%, 2 is 200% etc. We only want to apply the smallest ratio, that is why we do a check if heightRatio is lesser than the widthRatio. If we don’t do this check, our resizing will not work correctly,&amp;nbsp; because we do the calculate of the X and Y scaling separately. In the code above there is also a check to only set the scaling if the width or height ratio is lesser than 1, it will only make sure our app will stay on 100% or less in scaling, to not expand the app. If you want it to expand and be larger than the default size, just remove the check form the code. Here is the final code: &lt;BR&gt;&lt;/P&gt;&lt;PRE class=csharpcode&gt;&lt;SPAN class=kwrd&gt;private&lt;/SPAN&gt; Size _contentActualSize = &lt;SPAN class=kwrd&gt;new&lt;/SPAN&gt; Size(1024, 768);

&lt;SPAN class=kwrd&gt;public&lt;/SPAN&gt; ScaleableContent()
{
      Application.Current.Host.Content.Resized += &lt;SPAN class=kwrd&gt;new&lt;/SPAN&gt; EventHandler(Content_Resized);
}

&lt;SPAN class=kwrd&gt;void&lt;/SPAN&gt; Content_Resized(&lt;SPAN class=kwrd&gt;object&lt;/SPAN&gt; sender, EventArgs e)
{
    var hostContentActualHeight = Application.Current.Host.Content.ActualHeight;
    var hostContentActualWidth = Application.Current.Host.Content.ActualWidth;

    var heightRatio = hostContentActualHeight / _contentActualSize.Height;
    var widthRatio = hostContentActualWidth / _contentActualSize.Width;

    var ratio = &lt;SPAN class=kwrd&gt;1.0&lt;/SPAN&gt;;

&lt;SPAN class=kwrd&gt;    if&lt;/SPAN&gt; (heightRatio &amp;lt; widthRatio &amp;amp;&amp;amp; heightRatio &amp;lt; 1)&lt;BR&gt;       ratio = heightRatio;&lt;BR&gt;&lt;SPAN class=kwrd&gt;    else &lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;if&lt;/SPAN&gt; (widthRatio &amp;lt; 1)&lt;BR&gt;       ratio = widthRatio; &lt;BR&gt;
     contentRoot.RenderTransform = new ScaleTransform() { ScaleY = ratio, ScaleX = ratio };
}&lt;/PRE&gt;
&lt;STYLE type=text/css&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/STYLE&gt;

&lt;P&gt;This code is kind of boring to add to every app where we want to use scaling, isn’t it? So what I did was to create a ScalableContent control. The ScalableContent control inherits from the Canvas control and only want one child element, the new “LayoutRoot” element, the element to add the ScaleTransform to. I also need to take care about some alignment issues, for example if we set the Canvas’s HorizontalAlignment property to center, it will start render the content from the center to the right, not align the content into the middle of the screen. So solve this I decided to use the Left margin, I could have used the Canvas.Left attached property, but didn’t. Here is the code of the Scalable control: &lt;BR&gt;&lt;/P&gt;&lt;PRE class=csharpcode&gt;&lt;SPAN class=kwrd&gt;public&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;class&lt;/SPAN&gt; ScalableContent : Canvas
{
     &lt;SPAN class=kwrd&gt;private&lt;/SPAN&gt; FrameworkElement _scaleableElement;


     &lt;SPAN class=kwrd&gt;public&lt;/SPAN&gt; ScalableContent()
     {
          &lt;SPAN class=kwrd&gt;this&lt;/SPAN&gt;.Loaded += (o,e) =&amp;gt;
                 {
                     &lt;SPAN class=kwrd&gt;if&lt;/SPAN&gt; (&lt;SPAN class=kwrd&gt;this&lt;/SPAN&gt;.Children != &lt;SPAN class=kwrd&gt;null&lt;/SPAN&gt; &amp;amp;&amp;amp; &lt;SPAN class=kwrd&gt;this&lt;/SPAN&gt;.Children.Count &amp;gt; 0)
                    {
                        &lt;SPAN class=kwrd&gt;if&lt;/SPAN&gt; (&lt;SPAN class=kwrd&gt;this&lt;/SPAN&gt;.Children.Count &amp;gt; 1)
                            &lt;SPAN class=kwrd&gt;throw&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;new&lt;/SPAN&gt; SystemException(&lt;SPAN class=str&gt;"ScalableContent can only have one child element"&lt;/SPAN&gt;);

                        _scaleableElement = &lt;SPAN class=kwrd&gt;this&lt;/SPAN&gt;.Children[0] &lt;SPAN class=kwrd&gt;as&lt;/SPAN&gt; FrameworkElement;

                        &lt;SPAN class=kwrd&gt;if&lt;/SPAN&gt; (_scaleableElement != &lt;SPAN class=kwrd&gt;null&lt;/SPAN&gt;)
                            Application.Current.Host.Content.Resized += &lt;SPAN class=kwrd&gt;new&lt;/SPAN&gt; EventHandler(Content_Resized);
                    }
                };
     }


     &lt;SPAN class=kwrd&gt;public&lt;/SPAN&gt; Size IdleSize { get; set; }


     &lt;SPAN class=kwrd&gt;void&lt;/SPAN&gt; Content_Resized(&lt;SPAN class=kwrd&gt;object&lt;/SPAN&gt; sender, EventArgs e)
     {
            var contentActualWidth = Application.Current.Host.Content.ActualWidth;
            var contnetActualHeight = Application.Current.Host.Content.ActualHeight;

            var heightRatio = contnetActualHeight / IdleSize.Height;
            var widthRatio = contentActualWidth / IdleSize.Width;

            var ratio = 1.0;

            &lt;SPAN class=kwrd&gt;if&lt;/SPAN&gt; (heightRatio &amp;lt; widthRatio &amp;amp;&amp;amp; heightRatio &amp;lt; 1)
                ratio = heightRatio;
            &lt;SPAN class=kwrd&gt;else&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;if&lt;/SPAN&gt; (widthRatio &amp;lt; 1)
                ratio = widthRatio;

            var margin = &lt;SPAN class=kwrd&gt;new&lt;/SPAN&gt; Thickness(0);

            &lt;SPAN class=kwrd&gt;if&lt;/SPAN&gt; (HorizontalAlignment == HorizontalAlignment.Center)
                margin.Left = -((IdleSize.Width * ratio) / 2);
            &lt;SPAN class=kwrd&gt;else&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;if&lt;/SPAN&gt; (HorizontalAlignment == HorizontalAlignment.Right)
                margin.Left = -(IdleSize.Width * ratio);

            &lt;SPAN class=kwrd&gt;if&lt;/SPAN&gt; (VerticalAlignment == VerticalAlignment.Center)
                margin.Top = -((IdleSize.Height * ratio) / 2);
            &lt;SPAN class=kwrd&gt;else&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;if&lt;/SPAN&gt; (VerticalAlignment == VerticalAlignment.Bottom)
                margin.Top = -(IdleSize.Height * ratio);

            _scaleableElement.RenderTransform = &lt;SPAN class=kwrd&gt;new&lt;/SPAN&gt; ScaleTransform() { ScaleX = ratio, ScaleY = ratio };;
            _scaleableElement.Margin = margin;
        }
}&lt;/PRE&gt;
&lt;STYLE type=text/css&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/STYLE&gt;

&lt;P&gt;Here is how to use it in a XAML file: &lt;BR&gt;&lt;/P&gt;&lt;PRE class=csharpcode&gt;&lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;uc:ScalableContent&lt;/SPAN&gt; &lt;SPAN class=attr&gt;VerticalAlignment&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="Top"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;HorizontalAlignment&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="Center"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;IdleSize&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="1024,880"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
    
    &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;Grid&lt;/SPAN&gt; &lt;SPAN class=attr&gt;x:Name&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="LayoutRoot"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;VerticalAlignment&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="Center"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;HorizontalAlignment&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="Center"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
    
         &lt;SPAN class=rem&gt;&amp;lt;!-- Content here --&amp;gt;&lt;/SPAN&gt;

    &lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;Grid&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;

&lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;uc:ScalableContent&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;STYLE type=text/css&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/STYLE&gt;

&lt;P&gt;The control has a IdleSize property, which can be used to set the default (idle) size. To make this control work perfectly, make sure to not give the UserControl a fixed size, nor the Host object or surrounding divs etc on the page where you host the Silverlight app.&lt;/P&gt;
&lt;P&gt;I hope this blog post will give some value to some people, the scaling can be tricky to solve if we don’t know where to look etc.&lt;/P&gt;
&lt;STYLE type=text/css&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/STYLE&gt;

&lt;STYLE type=text/css&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/STYLE&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7206630" width="1" height="1"&gt;</content><author><name>Fredrik N</name><uri>http://weblogs.asp.net/members/Fredrik-N.aspx</uri></author><category term="Silverlight" scheme="http://weblogs.asp.net/fredriknormen/archive/tags/Silverlight/default.aspx" /></entry><entry><title>Keep the first “empty” Item in a listbox when using ASP.NET AJAX 4.0 Preview 5 and Observer</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/fredriknormen/archive/2009/09/11/keep-the-first-empty-item-in-a-listbox-when-using-asp-net-ajax-4-0-preview-5-and-observer.aspx" /><id>http://weblogs.asp.net/fredriknormen/archive/2009/09/11/keep-the-first-empty-item-in-a-listbox-when-using-asp-net-ajax-4-0-preview-5-and-observer.aspx</id><published>2009-09-11T15:09:00Z</published><updated>2009-09-11T15:09:00Z</updated><content type="html">&lt;P&gt;I got a question as a comment on my &lt;A href="http://weblogs.asp.net/fredriknormen/archive/2009/09/11/asp-net-ajax-4-0-preview-5-available.aspx" mce_href="http://weblogs.asp.net/fredriknormen/archive/2009/09/11/asp-net-ajax-4-0-preview-5-available.aspx"&gt;previous post about the new features and changes to ASP.NET AJAX 4.0 Preview 5&lt;/A&gt;. I hope I understood the question right ;) It was about using a listbox and add an empty item at the top of the list, and keep it there when adding new items to an array that is bounded to the list, and by using the Observer feature. Maybe some more have or will have the same question, so I decided to write a blog post about it.&lt;/P&gt;
&lt;P&gt;In this blog post I will use a sys-template for the listbox, here is an example of a listbox template by using HTML &amp;lt;select&amp;gt; element:&lt;/P&gt;&lt;PRE class=csharpcode&gt;&lt;SPAN class=kwrd&gt;&lt;BR&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;select&lt;/SPAN&gt; &lt;SPAN class=attr&gt;sys:attach&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="dataview"&lt;/SPAN&gt;
        &lt;SPAN class=attr&gt;class&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="sys-template"&lt;/SPAN&gt;
        &lt;SPAN class=attr&gt;dataview:data&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="{{ customers }}"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
        &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;option&lt;/SPAN&gt; &lt;SPAN class=attr&gt;sys:value&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="{{ID}}"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;{{ Name }}&lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;/option&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
&lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;select&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;BR&gt;&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;BR&gt;I will in this example use the dataview feature to simply fill the Listbox with values form an array.&lt;/P&gt;
&lt;P&gt;If we want to use ASP.NET AJAX 4.0 and the dataview feature, we need to add the sys and dataview namespace to the &amp;lt;body&amp;gt; tag:&lt;/P&gt;&lt;PRE class=csharpcode&gt;&lt;SPAN class=kwrd&gt;&lt;BR&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;body&lt;/SPAN&gt;
    &lt;SPAN class=attr&gt;xmlns:sys&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="javascript:Sys"&lt;/SPAN&gt;
    &lt;SPAN class=attr&gt;xmlns:dataview&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="javascript:Sys.UI.DataView"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;STYLE type=text/css&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/STYLE&gt;

&lt;P&gt;&lt;BR&gt;&lt;STRONG&gt;&lt;EM&gt;Note: We don’t need to add the sys:activate=”*” attribute to the &amp;lt;body&amp;gt; element anymore.&lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;STYLE type=text/css&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/STYLE&gt;

&lt;P&gt;I will in this post use a simple hard coded javascript array for the customers bounded to the listbos, and here is my simple array together with a AddCustomer method: &lt;BR&gt;&lt;/P&gt;&lt;PRE class=csharpcode&gt;&lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;script&lt;/SPAN&gt; &lt;SPAN class=attr&gt;type&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="text/javascript"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;

    &lt;SPAN class=kwrd&gt;var&lt;/SPAN&gt; customers = [
                      { ID : &lt;SPAN class=str&gt;"JD"&lt;/SPAN&gt;, Name : &lt;SPAN class=str&gt;"John Doe"&lt;/SPAN&gt; },
                      { ID : &lt;SPAN class=str&gt;"JD2"&lt;/SPAN&gt;, Name : &lt;SPAN class=str&gt;"Jane Doe"&lt;/SPAN&gt;}
                    ];
&lt;BR&gt;&lt;/PRE&gt;&lt;PRE class=csharpcode&gt;    &lt;SPAN class=kwrd&gt;function&lt;/SPAN&gt; AddCustomer()
    {
        Sys.Observer.add(customers, { ID: &lt;SPAN class=str&gt;"JD2"&lt;/SPAN&gt;, Name: &lt;SPAN class=str&gt;"Some Doe"&lt;/SPAN&gt; });
    }
    
&lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;script&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE class=csharpcode&gt;&lt;SPAN class=kwrd&gt;&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;P&gt;
&lt;STYLE type=text/css&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/STYLE&gt;
The AddCustomer method will make sure to add a new customer to the customers array. The Sys.Observer is used to make sure the listbox which is bound to the customers array should be updated automatically when a new customer is added to the customers array.&lt;/P&gt;
&lt;P&gt;Here is the code for the whole solution so far: &lt;BR&gt;&lt;/P&gt;&lt;PRE class=csharpcode&gt;&lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;html&lt;/SPAN&gt; &lt;SPAN class=attr&gt;xmlns&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="http://www.w3.org/1999/xhtml"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
&lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;head&lt;/SPAN&gt; &lt;SPAN class=attr&gt;runat&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="server"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
    &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;title&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;title&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
    &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;script&lt;/SPAN&gt; &lt;SPAN class=attr&gt;type&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="text/javascript"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;src&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="Scripts/MicrosoftAjax.debug.js"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;script&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
    &amp;lt;script type=&lt;SPAN class=str&gt;"text/javascript"&lt;/SPAN&gt; src=&lt;SPAN class=str&gt;"Scripts/MicrosoftAjaxTemplates.debug.js"&lt;/SPAN&gt;&amp;gt;&amp;lt;/script&amp;gt;

    &amp;lt;script type=&lt;SPAN class=str&gt;"text/javascript"&lt;/SPAN&gt;&amp;gt;

        &lt;SPAN class=kwrd&gt;var&lt;/SPAN&gt; customers = [
                            { ID : &lt;SPAN class=str&gt;"JD"&lt;/SPAN&gt;, Name : &lt;SPAN class=str&gt;"John Doe"&lt;/SPAN&gt; },
                            { ID : &lt;SPAN class=str&gt;"JD2"&lt;/SPAN&gt;, Name : &lt;SPAN class=str&gt;"Jane Doe"&lt;/SPAN&gt;}
                        ];

        &lt;SPAN class=kwrd&gt;function&lt;/SPAN&gt; AddCustomer()
        {
            Sys.Observer.add(customers, { ID: &lt;SPAN class=str&gt;"JD2"&lt;/SPAN&gt;, Name: &lt;SPAN class=str&gt;"Some Doe"&lt;/SPAN&gt; });
        }
    
    &lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;script&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
    
    &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;style&lt;/SPAN&gt; &lt;SPAN class=attr&gt;type&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="text/css"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
    
        .sys-template { display:none; }
    
    &lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;style&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
&lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;head&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;

&lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;body&lt;/SPAN&gt;
    &lt;SPAN class=attr&gt;xmlns:sys&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="javascript:Sys"&lt;/SPAN&gt;
    &lt;SPAN class=attr&gt;xmlns:dataview&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="javascript:Sys.UI.DataView"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
    
    &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;form&lt;/SPAN&gt; &lt;SPAN class=attr&gt;id&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="form1"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;runat&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="server"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
    &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;div&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
    
    &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;select&lt;/SPAN&gt; &lt;SPAN class=attr&gt;sys:attach&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="dataview"&lt;/SPAN&gt;
        &lt;SPAN class=attr&gt;class&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="sys-template"&lt;/SPAN&gt;
        &lt;SPAN class=attr&gt;dataview:data&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="{{ customers }}"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
            &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;option&lt;/SPAN&gt; &lt;SPAN class=attr&gt;sys:value&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="{{ID}}"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;{{ Name }}&lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;/option&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
    &lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;select&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
    
   &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;input&lt;/SPAN&gt; &lt;SPAN class=attr&gt;type&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="button"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;onclick&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="AddCustomer();"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;value&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="Add item"&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;/&amp;gt;&lt;/SPAN&gt;
   
    &lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;div&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
    &lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;form&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
&lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;body&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
&lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;html&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;STYLE type=text/css&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/STYLE&gt;

&lt;P&gt;&lt;BR&gt;As you may already notice there is no empty item at the top of the listbox items. So we add one to the template:&lt;/P&gt;&lt;PRE class=csharpcode&gt;&lt;BR&gt;&lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;select&lt;/SPAN&gt; &lt;SPAN class=attr&gt;sys:attach&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="dataview"&lt;/SPAN&gt;
        &lt;SPAN class=attr&gt;class&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="sys-template"&lt;/SPAN&gt;
        &lt;SPAN class=attr&gt;dataview:data&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="{{ customers }}"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
            &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;option value=””&lt;/SPAN&gt; &lt;SPAN class=attr&gt;selected&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="selected"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;Select an Item&lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;/option&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
            &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;option&lt;/SPAN&gt; &lt;SPAN class=attr&gt;sys:value&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="{{ID}}"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;{{ Name }}&lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;/option&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
    &lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;select&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;STYLE type=text/css&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/STYLE&gt;

&lt;P&gt;&lt;BR&gt;If we run the code, we will notice that several “Select an Item” will be added to the listbox. What we want to do is to keep the first and “empty” item when a new customer is added to the customers array, we don’t want to have the “empty” list repeatable for each item in the list. To solve this we can use the sys:if attribute. We simply use it to see if the index of the currently bounded item is 0, if so, we add the “empty” item. By doing that we will make sure to only have one “empty” item added, and it will only&amp;nbsp; be added when the index is 0. &lt;/P&gt;&lt;PRE class=csharpcode&gt;&lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;select&lt;/SPAN&gt; &lt;SPAN class=attr&gt;sys:attach&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="dataview"&lt;/SPAN&gt;
        &lt;SPAN class=attr&gt;class&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="sys-template"&lt;/SPAN&gt;
        &lt;SPAN class=attr&gt;dataview:data&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="{{ customers }}"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
            &lt;STRONG&gt;&lt;EM&gt;&lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;option&lt;/SPAN&gt; &lt;SPAN class=attr&gt;sys:if&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="$index==0"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;sys:value&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;=""&lt;/SPAN&gt; &lt;SPAN class=attr&gt;selected&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="selected"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;Select an Item&lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;/option&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;&lt;/EM&gt;&lt;/STRONG&gt;
            &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;option&lt;/SPAN&gt; &lt;SPAN class=attr&gt;sys:value&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="{{ID}}"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;{{ Name }}&lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;/option&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
&lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;select&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;STYLE type=text/css&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/STYLE&gt;

&lt;P&gt;&lt;BR&gt;I hope this post may be useful for some of you, but I will be so happy to see more Silverlight developers ;)&lt;/P&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7200984" width="1" height="1"&gt;</content><author><name>Fredrik N</name><uri>http://weblogs.asp.net/members/Fredrik-N.aspx</uri></author><category term="ASP.Net" scheme="http://weblogs.asp.net/fredriknormen/archive/tags/ASP.Net/default.aspx" /><category term="AXAJ" scheme="http://weblogs.asp.net/fredriknormen/archive/tags/AXAJ/default.aspx" /></entry><entry><title>ASP.NET AJAX 4.0 Preview 5 available</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/fredriknormen/archive/2009/09/11/asp-net-ajax-4-0-preview-5-available.aspx" /><id>http://weblogs.asp.net/fredriknormen/archive/2009/09/11/asp-net-ajax-4-0-preview-5-available.aspx</id><published>2009-09-11T07:39:00Z</published><updated>2009-09-11T07:39:00Z</updated><content type="html">&lt;P&gt;Microsoft have recently released the Preview 5 of ASP.NET AJAX 4.0 on &lt;A href="http://aspnet.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=32770" mce_href="http://aspnet.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=32770"&gt;CodePlex&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;In Preview 5 of ASP.NET AJAX 4.0 you can see some improvements to the lient-side data story introduced in previous previews of ASP.NET AJAX. In this release, Microsoft have add support for the following features: 
&lt;P&gt;&lt;BR&gt;Dynamic and recursive templates &lt;/P&gt;
&lt;P&gt;Binding Converters&lt;/P&gt;
&lt;P&gt;UpdatePanel support&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;/STRONG&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here are some changes made from Preview 4 to 5&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;BR&gt;Declarative Attribute Changes&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;BR&gt;There is no need to include the sys:active attribute on the &amp;lt;body&amp;gt; element of a page containing declarative markup.&lt;/P&gt;&lt;PRE class=csharpcode&gt;&lt;SPAN class=kwrd&gt;&lt;BR&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;body&lt;/SPAN&gt;
    &lt;SPAN class=attr&gt;xmlns:sys&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="javascript:Sys"&lt;/SPAN&gt;
    &lt;SPAN class=attr&gt;xmlns:dataview&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="javascript:Sys.UI.DataView"&lt;/SPAN&gt;
    &lt;STRIKE&gt;&lt;SPAN class=attr&gt;sys:activate&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="*"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;&lt;/STRIKE&gt;&lt;/PRE&gt;
&lt;STYLE type=text/css&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/STYLE&gt;

&lt;P&gt;&lt;BR&gt;When binding to attributes before we could write something like this:&lt;BR&gt;&lt;/P&gt;&lt;PRE class=csharpcode&gt;&lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;ul&lt;/SPAN&gt; &lt;SPAN class=attr&gt;sys:attach&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="dataview"&lt;/SPAN&gt;
    &lt;SPAN class=attr&gt;class&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="sys-template"&lt;/SPAN&gt;
    &lt;SPAN class=attr&gt;dataview:data&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="{{ imagesArray }}"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
    &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;li&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
        &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;h3&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;{{ Name }}&lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;h3&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
        &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;div&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;{{ Description }}&lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;div&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
        &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;input&lt;/SPAN&gt; &lt;SPAN class=attr&gt;type&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="text"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;value&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="{{Name}}"&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;/&amp;gt;&lt;/SPAN&gt;
    &lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;li&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
&lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;ul&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;STYLE type=text/css&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/STYLE&gt;

&lt;P&gt;&lt;BR&gt;Now all attributes that contain the {{..}} or {binding ..} must now use the “sys” prefix:&lt;/P&gt;&lt;PRE class=csharpcode&gt;&lt;SPAN class=kwrd&gt;&lt;BR&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;input&lt;/SPAN&gt; &lt;SPAN class=attr&gt;type&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="text"&lt;/SPAN&gt; &lt;STRONG&gt;sys:&lt;/STRONG&gt;&lt;SPAN class=attr&gt;value&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="{{Name}}"&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;/&amp;gt;&lt;/SPAN&gt;
&lt;/PRE&gt;
&lt;STYLE type=text/css&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/STYLE&gt;

&lt;P&gt;Some changes has also been made to the “code” and “class” attributes, they are moved to into “Sys”&lt;BR&gt;&lt;BR&gt;code:if -&amp;gt; sys:if&lt;/P&gt;&lt;PRE class=csharpcode&gt;&lt;SPAN class=kwrd&gt;&lt;BR&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;thead&lt;/SPAN&gt; &lt;SPAN class=attr&gt;&lt;STRIKE&gt;code:if&lt;/STRIKE&gt;&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&lt;STRIKE&gt;="$index==0"&lt;/STRIKE&gt; &lt;SPAN class=attr&gt;sys:if&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="$index==0"&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
  &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;tr&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
    &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;th&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;Image&lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;th&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
    &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;th&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;Description&lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;th&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
 &lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;tr&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
&lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;thead&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
&lt;/PRE&gt;
&lt;STYLE type=text/css&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/STYLE&gt;

&lt;P&gt;code:before -&amp;gt; sys:codebefore&lt;BR&gt;code:after -&amp;gt; sys:codeafter&lt;BR&gt;&lt;/P&gt;
&lt;P&gt;The ‘class’ attributes have been moved into ‘sys’.&lt;BR&gt;&lt;BR&gt;class:foo -&amp;gt; sys:class-foo&lt;BR&gt;&lt;BR&gt;The ‘style’ attributes have been moved into ‘sys’.&lt;BR&gt;&lt;BR&gt;style:font-size=”8” -&amp;gt; sys:style-font-size=”8”&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;/STRONG&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Top Level Binding&lt;BR&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;In the previous version of ASP.NET AJAX 4.0, we could only use binding by using a template marked with sys-template, we can now instead use the&amp;nbsp; &lt;STRONG&gt;sys:value=”{binding &lt;EM&gt;field&lt;/EM&gt;, source={{&lt;EM&gt;source&lt;/EM&gt;}}}”&lt;/STRONG&gt;&amp;nbsp; attribute, for example:&lt;/P&gt;&lt;SPAN class=kwrd&gt;&lt;PRE class=csharpcode&gt;&lt;SPAN class=kwrd&gt;&lt;BR&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;html&lt;/SPAN&gt; &lt;SPAN class=attr&gt;xmlns&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="http://www.w3.org/1999/xhtml"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
&lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;head&lt;/SPAN&gt; &lt;SPAN class=attr&gt;runat&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="server"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
    &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;title&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;title&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
    &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;script&lt;/SPAN&gt; &lt;SPAN class=attr&gt;type&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="text/javascript"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;src&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="Scripts/MicrosoftAjax.debug.js"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;script&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
    &amp;lt;script type=&lt;SPAN class=str&gt;"text/javascript"&lt;/SPAN&gt; src=&lt;SPAN class=str&gt;"Scripts/MicrosoftAjaxTemplates.debug.js"&lt;/SPAN&gt;&amp;gt;&amp;lt;/script&amp;gt;

    &amp;lt;script type=&lt;SPAN class=str&gt;"text/javascript"&lt;/SPAN&gt;&amp;gt;

        &lt;SPAN class=kwrd&gt;var&lt;/SPAN&gt; customer = { Name : &lt;SPAN class=str&gt;"John Doe"&lt;/SPAN&gt; };
    
    &lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;script&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
    
&lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;head&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;

&lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;body&lt;/SPAN&gt; &lt;SPAN class=attr&gt;xmlns:sys&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="javascript:Sys"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
    
    &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;form&lt;/SPAN&gt; &lt;SPAN class=attr&gt;id&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="form1"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;runat&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="server"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
    &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;div&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;

         &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;input&lt;/SPAN&gt; &lt;SPAN class=attr&gt;type&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="text"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;sys:value&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="{binding Name,source={{customer}} }"&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;/&amp;gt;&lt;/SPAN&gt;
    
    &lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;div&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
    &lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;form&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
&lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;body&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
&lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;html&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;STYLE type=text/css&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/STYLE&gt;
&lt;PRE class=csharpcode&gt;&amp;nbsp;&lt;/PRE&gt;
&lt;P&gt;If we have two input field which is bound to the same source, for example&lt;BR&gt;&lt;/P&gt;&lt;PRE class=csharpcode&gt;&lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;input&lt;/SPAN&gt; &lt;SPAN class=attr&gt;id&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="text"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;type&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="text"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;sys:value&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="{binding Name, source={{customer}}}"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;/&amp;gt;&lt;/SPAN&gt;
&lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;input&lt;/SPAN&gt; &lt;SPAN class=attr&gt;id&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="Text1"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;type&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="text"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;sys:value&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="{binding Name, source={{customer}}}"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;/&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;STYLE type=text/css&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/STYLE&gt;

&lt;P&gt;&lt;BR&gt;and we change the value of field “Text1”, the value of “text” will be automatically changed.&lt;/P&gt;
&lt;P&gt;&lt;BR&gt;We can also use the Sys.Observer to update the binding value:&lt;BR&gt;&lt;/P&gt;&lt;PRE class=csharpcode&gt;&lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;html&lt;/SPAN&gt; &lt;SPAN class=attr&gt;xmlns&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="http://www.w3.org/1999/xhtml"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
&lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;head&lt;/SPAN&gt; &lt;SPAN class=attr&gt;runat&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="server"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
    &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;title&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;title&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
    &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;script&lt;/SPAN&gt; &lt;SPAN class=attr&gt;type&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="text/javascript"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;src&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="Scripts/MicrosoftAjax.debug.js"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;script&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
    &amp;lt;script type=&lt;SPAN class=str&gt;"text/javascript"&lt;/SPAN&gt; src=&lt;SPAN class=str&gt;"Scripts/MicrosoftAjaxTemplates.debug.js"&lt;/SPAN&gt;&amp;gt;&amp;lt;/script&amp;gt;

    &amp;lt;script type=&lt;SPAN class=str&gt;"text/javascript"&lt;/SPAN&gt;&amp;gt;

        &lt;SPAN class=kwrd&gt;var&lt;/SPAN&gt; customer = { Name: &lt;SPAN class=str&gt;"John Doe"&lt;/SPAN&gt; };
        
        &lt;SPAN class=kwrd&gt;function&lt;/SPAN&gt; clickMe()
        {
            &lt;SPAN class=rem&gt;//Will not update the fields&lt;/SPAN&gt;
            customer.Name = &lt;SPAN class=str&gt;"Hej"&lt;/SPAN&gt;;

            &lt;SPAN class=rem&gt;//Will update the fields&lt;/SPAN&gt;
            Sys.Observer.setValue(customer, &lt;SPAN class=str&gt;"Name"&lt;/SPAN&gt;, &lt;SPAN class=str&gt;"Jane Doe"&lt;/SPAN&gt;);
        }
    
    &lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;script&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
    
&lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;head&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;

&lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;body&lt;/SPAN&gt;   &lt;SPAN class=attr&gt;xmlns:sys&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="javascript:Sys"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
    
    &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;form&lt;/SPAN&gt; &lt;SPAN class=attr&gt;id&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="form1"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;runat&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="server"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
    &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;div&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
    
    &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;input&lt;/SPAN&gt; &lt;SPAN class=attr&gt;id&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="myTemplate"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;type&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="text"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;sys:value&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="{binding Name, source={{customer}}}"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;/&amp;gt;&lt;/SPAN&gt;
    &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;input&lt;/SPAN&gt; &lt;SPAN class=attr&gt;id&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="Text1"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;type&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="text"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;sys:value&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="{binding Name, source={{customer}}}"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;/&amp;gt;&lt;/SPAN&gt;
    
    &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;input&lt;/SPAN&gt; &lt;SPAN class=attr&gt;type&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="button"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;onclick&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="clickMe()"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;value&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="Click Me"&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;/&amp;gt;&lt;/SPAN&gt;
    
    &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;div&lt;/SPAN&gt; &lt;SPAN class=attr&gt;id&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="form"&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;/&amp;gt;&lt;/SPAN&gt;
    
    &lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;div&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
    &lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;form&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
&lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;body&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
&lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;html&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
&lt;/PRE&gt;
&lt;STYLE type=text/css&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/STYLE&gt;

&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Binding Converters and Expandos&lt;BR&gt;&lt;/STRONG&gt;&lt;BR&gt;Bindings now support converters by using the Sys.Binding.converters field.&lt;/P&gt;
&lt;P&gt;&lt;BR&gt;{ binding foo,convert=myconverter }&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;EM&gt;&lt;BR&gt;Note: There are no Converters out of the box&lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;BR&gt;Here is an example:&lt;BR&gt;&lt;/P&gt;&lt;PRE class=csharpcode&gt;&lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;html&lt;/SPAN&gt; &lt;SPAN class=attr&gt;xmlns&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="http://www.w3.org/1999/xhtml"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
&lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;head&lt;/SPAN&gt; &lt;SPAN class=attr&gt;runat&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="server"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
    &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;title&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;title&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
    &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;script&lt;/SPAN&gt; &lt;SPAN class=attr&gt;type&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="text/javascript"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;src&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="Scripts/MicrosoftAjax.debug.js"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;script&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
    &amp;lt;script type=&lt;SPAN class=str&gt;"text/javascript"&lt;/SPAN&gt; src=&lt;SPAN class=str&gt;"Scripts/MicrosoftAjaxTemplates.debug.js"&lt;/SPAN&gt;&amp;gt;&amp;lt;/script&amp;gt;

    &amp;lt;script type=&lt;SPAN class=str&gt;"text/javascript"&lt;/SPAN&gt;&amp;gt;

        &lt;SPAN class=kwrd&gt;var&lt;/SPAN&gt; customer = { Name: &lt;SPAN class=str&gt;"John Doe"&lt;/SPAN&gt;, Age : 31 };
        
        Sys.Binding.converters.myconverter = &lt;SPAN class=kwrd&gt;function&lt;/SPAN&gt;(valueToConvert, binding) {
            &lt;SPAN class=kwrd&gt;if&lt;/SPAN&gt; (valueToConvert &amp;gt;= 18)
                &lt;SPAN class=kwrd&gt;return&lt;/SPAN&gt; &lt;SPAN class=str&gt;"checked"&lt;/SPAN&gt;;
            &lt;SPAN class=kwrd&gt;else&lt;/SPAN&gt;
                &lt;SPAN class=kwrd&gt;return&lt;/SPAN&gt; &lt;SPAN class=str&gt;""&lt;/SPAN&gt;;
        }
    
    &lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;script&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
    
    &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;style&lt;/SPAN&gt; &lt;SPAN class=attr&gt;type&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="text/css"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
    
        .sys-template { display:none; }
    
    &lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;style&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
&lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;head&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;

&lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;body&lt;/SPAN&gt;
    &lt;SPAN class=attr&gt;xmlns:sys&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="javascript:Sys"&lt;/SPAN&gt;
    &lt;SPAN class=attr&gt;xmlns:dataview&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="javascript:Sys.UI.DataView"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
    
    &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;form&lt;/SPAN&gt; &lt;SPAN class=attr&gt;id&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="form1"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;runat&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="server"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
    &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;div&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
    
    &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;input&lt;/SPAN&gt; &lt;SPAN class=attr&gt;id&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="isAdult"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;type&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="checkbox"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;sys:checked&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="{binding Age, source={{customer}}, &lt;STRONG&gt;convert=myconverter}&lt;/STRONG&gt;"&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;/&amp;gt;&lt;/SPAN&gt;
    
    &lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;div&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
    &lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;form&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
&lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;body&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
&lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;html&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;STYLE type=text/css&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/STYLE&gt;

&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;We can also set expandos, for example:&lt;/P&gt;
&lt;P&gt;&lt;BR&gt;{binding foo,convert=format,format=MM/dd} &lt;/P&gt;
&lt;P&gt;&lt;BR&gt;Sys.Binding.converters.format = function(value, binding) {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // binding.format === MM/dd&lt;BR&gt;} 
&lt;P&gt;&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&lt;/SPAN&gt;&lt;STRONG&gt;&lt;/STRONG&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Binding Updates&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;BR&gt;We can now use the sys:innettext and sys:innerhtml to make sure it will show us the HTML code in the browser or as pure HTML. For example if we have a variable “foo” and withthe value “&amp;lt;p&amp;gt;Silverligth Rocks!&amp;lt;/p&amp;gt;”, we maybe want it to be displayed as normal text in the browser, if that is the case we can use sys:innettext:&lt;/P&gt;&lt;PRE class=csharpcode&gt;&lt;SPAN class=kwrd&gt;&lt;BR&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;div&lt;/SPAN&gt; &lt;SPAN class=attr&gt;sys:innertext&lt;/SPAN&gt;=”{{ &lt;SPAN class=attr&gt;foo&lt;/SPAN&gt; }}”&lt;SPAN class=kwrd&gt;&amp;gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;div&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
&lt;/PRE&gt;
&lt;STYLE type=text/css&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/STYLE&gt;

&lt;P&gt;&lt;BR&gt;If we want it to result as a normal HTML we can instead use the innerhtml:&lt;/P&gt;&lt;PRE class=csharpcode&gt;&lt;SPAN class=kwrd&gt;&lt;BR&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;div&lt;/SPAN&gt; &lt;SPAN class=attr&gt;sys:innerhtml&lt;/SPAN&gt;=”{{ &lt;SPAN class=attr&gt;foo&lt;/SPAN&gt; }}”&lt;SPAN class=kwrd&gt;&amp;gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;div&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
&lt;/PRE&gt;
&lt;STYLE type=text/css&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/STYLE&gt;

&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Compatibility with the ASP.NET UpdatePanel&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;BR&gt;Preview 4 of the ASP.NET AJAX 4.0 didn’t support UpdatePanel in ASP.NET 3.5. But in the preview 5 will now work with either 3.5 or 4.0 on the server. To make sure the Preview 5 should work with an UpdatePanel, you need to replace the partial rendering script MicrosoftAjaxWebForms.js wtih the 4.0 version.&lt;PRE class=csharpcode&gt;&lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;asp:ScriptManager&lt;/SPAN&gt; &lt;SPAN class=attr&gt;runat&lt;/SPAN&gt;=”&lt;SPAN class=attr&gt;server&lt;/SPAN&gt;”&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
    &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;Scripts&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
        &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;asp:ScriptReference&lt;/SPAN&gt; &lt;SPAN class=attr&gt;Name&lt;/SPAN&gt;=”&lt;SPAN class=attr&gt;MicrosoftAjax&lt;/SPAN&gt;.&lt;SPAN class=attr&gt;js&lt;/SPAN&gt;” &lt;SPAN class=attr&gt;Path&lt;/SPAN&gt;=”~/&lt;SPAN class=attr&gt;scripts&lt;/SPAN&gt;/&lt;SPAN class=attr&gt;MicrosoftAjax&lt;/SPAN&gt;.&lt;SPAN class=attr&gt;js&lt;/SPAN&gt;” &lt;SPAN class=kwrd&gt;/&amp;gt;&lt;/SPAN&gt;
        &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;asp:ScriptReference&lt;/SPAN&gt; &lt;SPAN class=attr&gt;Name&lt;/SPAN&gt;=”&lt;SPAN class=attr&gt;MicrosoftAjaxWebForms&lt;/SPAN&gt;.&lt;SPAN class=attr&gt;js&lt;/SPAN&gt;” &lt;SPAN class=attr&gt;Path&lt;/SPAN&gt;=”~/&lt;SPAN class=attr&gt;scripts&lt;/SPAN&gt;/&lt;SPAN class=attr&gt;MicrosoftAjaxWebForms&lt;/SPAN&gt;.&lt;SPAN class=attr&gt;js&lt;/SPAN&gt;” &lt;SPAN class=kwrd&gt;/&amp;gt;&lt;/SPAN&gt;
    &lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;Scripts&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
&lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;asp:ScriptManager&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
&lt;/PRE&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Supported Browsers&lt;BR&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;The ASP.NET AJAX 4.0 Preview 5 is tested on the following browsers (I know a lot of people are asking this kind of questions ;))&lt;/P&gt;
&lt;P&gt;&lt;BR&gt;Microsoft Internet Explorer 6 
&lt;P&gt;Microsoft Internet Explorer 7 
&lt;P&gt;Microsoft Internet Explorer 8 RC1 
&lt;P&gt;Mozilla Firefox 3 and 3.5 
&lt;P&gt;Apple Safari 4 
&lt;P&gt;Opera 10 
&lt;P&gt;Chrome 2 
&lt;P&gt;&lt;STRONG&gt;How to use the ASP.NET AJAX 4.0 Preview 5 in your applications&lt;/STRONG&gt; 
&lt;P&gt;&lt;BR&gt;If we want to use the ASP.NET AJAX 4.0 Preview 5, we need to reference to the new script files, we can do this by using the &amp;lt;script&amp;gt; tag or adding ScriptReferernces to the ScriptManager control:&lt;BR&gt;&lt;PRE class=csharpcode&gt;&lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;asp:ScriptManager&lt;/SPAN&gt; &lt;SPAN class=attr&gt;ID&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="sm"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;runat&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="server"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
    &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;Scripts&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
        &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;asp:ScriptReference&lt;/SPAN&gt; &lt;SPAN class=attr&gt;Name&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="MicrosoftAjax.js"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;Path&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="~/scripts/MicrosoftAjax.js"&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;/&amp;gt;&lt;/SPAN&gt;
        &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;asp:ScriptReference&lt;/SPAN&gt; &lt;SPAN class=attr&gt;ScriptMode&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="Inherit"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;Path&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="~/scripts/MicrosoftAjaxTemplates.js"&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;/&amp;gt;&lt;/SPAN&gt;
        &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;asp:ScriptReference&lt;/SPAN&gt; &lt;SPAN class=attr&gt;ScriptMode&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="Inherit"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;Path&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="~/scripts/MicrosoftAjaxAdoNet.js"&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;/&amp;gt;&lt;/SPAN&gt;
        &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;asp:ScriptReference&lt;/SPAN&gt; &lt;SPAN class=attr&gt;ScriptMode&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="Inherit"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;Path&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="~/scripts/MicrosoftAjaxDataContext.js"&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;/&amp;gt;&lt;/SPAN&gt;
    &lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;Scripts&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
&lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;asp:ScriptManager&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
&lt;BR&gt;&lt;/PRE&gt;&lt;PRE class=csharpcode&gt;Example using &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;script&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt; tags:
&lt;/PRE&gt;&lt;PRE class=csharpcode&gt;&lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;script&lt;/SPAN&gt; &lt;SPAN class=attr&gt;type&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="text/javascript"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;src&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="../scripts/MicrosoftAjax.debug.js"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;script&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
&lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;script&lt;/SPAN&gt; &lt;SPAN class=attr&gt;type&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="text/javascript"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;src&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="../scripts/MicrosoftAjaxTemplates.debug.js"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;script&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
&lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;script&lt;/SPAN&gt; &lt;SPAN class=attr&gt;type&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="text/javascript"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;src&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="../scripts/MicrosoftAjaxAdoNet.debug.js"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;script&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;script&lt;/SPAN&gt; &lt;SPAN class=attr&gt;type&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="text/javascript"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;src&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="../scripts/MicrosoftAjaxDataContext.debug.js"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;script&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;STYLE type=text/css&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/STYLE&gt;

&lt;STYLE type=text/css&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/STYLE&gt;

&lt;STYLE type=text/css&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/STYLE&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7200439" width="1" height="1"&gt;</content><author><name>Fredrik N</name><uri>http://weblogs.asp.net/members/Fredrik-N.aspx</uri></author><category term="ASP.Net" scheme="http://weblogs.asp.net/fredriknormen/archive/tags/ASP.Net/default.aspx" /><category term="AXAJ" scheme="http://weblogs.asp.net/fredriknormen/archive/tags/AXAJ/default.aspx" /></entry><entry><title>.NET RIA Services Exception handling</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/fredriknormen/archive/2009/08/20/net-ria-services-exception-handling.aspx" /><id>http://weblogs.asp.net/fredriknormen/archive/2009/08/20/net-ria-services-exception-handling.aspx</id><published>2009-08-20T09:30:00Z</published><updated>2009-08-20T09:30:00Z</updated><content type="html">&lt;P&gt;&lt;STRONG&gt;&lt;EM&gt;Note: This post is based on the July preview of the .NET RIA Services, so changes may happen in a future release of the framework&lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;At the moment I’m updating a code example for my &lt;A href="http://www.cornerstone.se/Web/Templates/CoursePage.aspx?id=2513&amp;amp;course=COUR2007090715261701796076&amp;amp;epslanguage=SV" mce_href="http://www.cornerstone.se/Web/Templates/CoursePage.aspx?id=2513&amp;amp;course=COUR2007090715261701796076&amp;amp;epslanguage=SV"&gt;Silverlight 3.0 course&lt;/A&gt; and have added some exception handling to the code. I also got a question about how to handle exception while calling the Load operation of the DomainService class. So I decided to write a blog post about it, maybe someone more have the same question.&lt;/P&gt;
&lt;P&gt;By default if you make a call to a DomainService query method, you will not get an exception on the client-side, if you don’t adding some extra code. Lets pretend that the following code is your DomainService and Query method:&lt;BR&gt;&lt;/P&gt;&lt;PRE class=csharpcode&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN class=kwrd&gt;public&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;class&lt;/SPAN&gt; MyDomainService : DomainService
{
      &lt;SPAN class=kwrd&gt;public&lt;/SPAN&gt; IEnumerable&amp;lt;Customer&amp;gt; GetCustomers()
      {
           //Code that can throw an exception;
       }
}&lt;BR&gt;&lt;BR&gt;&lt;/FONT&gt;&lt;/PRE&gt;
&lt;P&gt;
&lt;STYLE type=text/css&gt;.csharpcode {
	BACKGROUND-COLOR: #ffffff; FONT-FAMILY: consolas, "Courier New", courier, monospace; COLOR: black; FONT-SIZE: small
}
.csharpcode PRE {
	BACKGROUND-COLOR: #ffffff; FONT-FAMILY: consolas, "Courier New", courier, monospace; COLOR: black; FONT-SIZE: small
}
.csharpcode PRE {
	MARGIN: 0em
}
.csharpcode .rem {
	COLOR: #008000
}
.csharpcode .kwrd {
	COLOR: #0000ff
}
.csharpcode .str {
	COLOR: #006080
}
.csharpcode .op {
	COLOR: #0000c0
}
.csharpcode .preproc {
	COLOR: #cc6633
}
.csharpcode .asp {
	BACKGROUND-COLOR: #ffff00
}
.csharpcode .html {
	COLOR: #800000
}
.csharpcode .attr {
	COLOR: #ff0000
}
.csharpcode .alt {
	BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; WIDTH: 100%
}
.csharpcode .lnum {
	COLOR: #606060
}
&lt;/STYLE&gt;
&lt;/P&gt;
&lt;P&gt;The method above will throw an exception. If you on the client-side want to “call/use” the GetCustomers method, you will use the generated DomainContext class’s Load method: &lt;BR&gt;&lt;/P&gt;&lt;PRE class=csharpcode&gt;&lt;FONT face="Courier New"&gt;&lt;BR&gt;var d = &lt;SPAN class=kwrd&gt;new&lt;/SPAN&gt; MyDomainContext();

var loadOperation = d.Load&amp;lt;Customer&amp;gt;(d.GetCustomersQuery(), MyCallBack, &lt;SPAN class=kwrd&gt;null&lt;/SPAN&gt;);

LayoutRoot.DataContext = d.Customers;&lt;/FONT&gt;&lt;/PRE&gt;
&lt;STYLE type=text/css&gt;.csharpcode {
	BACKGROUND-COLOR: #ffffff; FONT-FAMILY: consolas, "Courier New", courier, monospace; COLOR: black; FONT-SIZE: small
}
.csharpcode PRE {
	BACKGROUND-COLOR: #ffffff; FONT-FAMILY: consolas, "Courier New", courier, monospace; COLOR: black; FONT-SIZE: small
}
.csharpcode PRE {
	MARGIN: 0em
}
.csharpcode .rem {
	COLOR: #008000
}
.csharpcode .kwrd {
	COLOR: #0000ff
}
.csharpcode .str {
	COLOR: #006080
}
.csharpcode .op {
	COLOR: #0000c0
}
.csharpcode .preproc {
	COLOR: #cc6633
}
.csharpcode .asp {
	BACKGROUND-COLOR: #ffff00
}
.csharpcode .html {
	COLOR: #800000
}
.csharpcode .attr {
	COLOR: #ff0000
}
.csharpcode .alt {
	BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; WIDTH: 100%
}
.csharpcode .lnum {
	COLOR: #606060
}
&lt;/STYLE&gt;

&lt;P&gt;&lt;BR&gt;&lt;BR&gt;When this code is executed, you will not get any exception, so the user or you may think that no exception have occurred. But that isn’t the case. So what I’m going to write about now, is different way you can check if an exception occurred (Wouldn’t it be nice if we only could get an exception instead of adding extra code to check if an exception is thrown ;)).&lt;/P&gt;
&lt;P&gt;The LoadOperation class has two properties we can use, HasError and Error. To check if we got an exception we can use the HasError property, if we want to get information about an exception, we can use the Error property. The first example I’m going to use, will only display an exception for the client.&lt;/P&gt;
&lt;P&gt;On the client-side I have a StackPanel called myErrorPanel, it also have a TextBlock where the Text property is bound to a property path “Error.Message”.&lt;/P&gt;&lt;PRE class=csharpcode&gt;&lt;SPAN class=kwrd&gt;&lt;BR&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;StackPanel&lt;/SPAN&gt; &lt;SPAN class=attr&gt;x:Name&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="myErrorPanel"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
      &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;TextBlock&lt;/SPAN&gt; &lt;SPAN class=attr&gt;Text&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="{Binding Path=Error.Message}"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;TextBlock&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
&lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;StackPanel&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;P&gt;
&lt;STYLE type=text/css&gt;.csharpcode {
	BACKGROUND-COLOR: #ffffff; FONT-FAMILY: consolas, "Courier New", courier, monospace; COLOR: black; FONT-SIZE: small
}
.csharpcode PRE {
	BACKGROUND-COLOR: #ffffff; FONT-FAMILY: consolas, "Courier New", courier, monospace; COLOR: black; FONT-SIZE: small
}
.csharpcode PRE {
	MARGIN: 0em
}
.csharpcode .rem {
	COLOR: #008000
}
.csharpcode .kwrd {
	COLOR: #0000ff
}
.csharpcode .str {
	COLOR: #006080
}
.csharpcode .op {
	COLOR: #0000c0
}
.csharpcode .preproc {
	COLOR: #cc6633
}
.csharpcode .asp {
	BACKGROUND-COLOR: #ffff00
}
.csharpcode .html {
	COLOR: #800000
}
.csharpcode .attr {
	COLOR: #ff0000
}
.csharpcode .alt {
	BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; WIDTH: 100%
}
.csharpcode .lnum {
	COLOR: #606060
}
&lt;/STYLE&gt;
&lt;/P&gt;
&lt;P&gt;&lt;BR&gt;In the code-behind we can now write the following code which will bound the LoadOperation to the myErrorPanel: &lt;BR&gt;&lt;/P&gt;&lt;PRE class=csharpcode&gt;&lt;FONT face="Courier New"&gt;&lt;BR&gt;var d = &lt;SPAN class=kwrd&gt;new&lt;/SPAN&gt; MyDomainContext();

var loadOperation = d.Load&amp;lt;Customer&amp;gt;(d.GetCustomersQuery());

LayoutRoot.DataContext = d.Customers;
myErrorPanel.DataContext = loadOperation;&lt;/FONT&gt;&lt;/PRE&gt;
&lt;STYLE type=text/css&gt;.csharpcode {
	BACKGROUND-COLOR: #ffffff; FONT-FAMILY: consolas, "Courier New", courier, monospace; COLOR: black; FONT-SIZE: small
}
.csharpcode PRE {
	BACKGROUND-COLOR: #ffffff; FONT-FAMILY: consolas, "Courier New", courier, monospace; COLOR: black; FONT-SIZE: small
}
.csharpcode PRE {
	MARGIN: 0em
}
.csharpcode .rem {
	COLOR: #008000
}
.csharpcode .kwrd {
	COLOR: #0000ff
}
.csharpcode .str {
	COLOR: #006080
}
.csharpcode .op {
	COLOR: #0000c0
}
.csharpcode .preproc {
	COLOR: #cc6633
}
.csharpcode .asp {
	BACKGROUND-COLOR: #ffff00
}
.csharpcode .html {
	COLOR: #800000
}
.csharpcode .attr {
	COLOR: #ff0000
}
.csharpcode .alt {
	BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; WIDTH: 100%
}
.csharpcode .lnum {
	COLOR: #606060
}
&lt;/STYLE&gt;

&lt;P&gt;&lt;BR&gt;If the Load method of our DominContext has an error, the Error Message will be displayed for the User. By using this solution, we will not have any idea if an error has occurred during the Load operation, if it does it will only be shown for the User. The StackPanel will also take up some space on the user interface, so to solve it we can for example add a Converter, and bound the HasError to the StackPanel’s Visibility property. The following two other solution will instead show us, how we can use a callback method and the LoadOperation’s Complteted event to have a better control if an exception is thrown during the Load operation.&lt;/P&gt;
&lt;P&gt;The DomainContext’s Load method can take a callback as an parameter, by using a callback, we will get a notification when the Load operation is completed, and we can also see if there was any error during the Load operation. The following code will use a callback and check if an error has occurred: &lt;BR&gt;&lt;/P&gt;&lt;PRE class=csharpcode&gt;&lt;FONT face="Courier New"&gt;&lt;BR&gt;var d = &lt;SPAN class=kwrd&gt;new&lt;/SPAN&gt; MyDomainContext();

var loadOperation = d.Load&amp;lt;Customer&amp;gt;(d.GetCustomersQuery(), MyCallBack, &lt;SPAN class=kwrd&gt;null&lt;/SPAN&gt;);

...


&lt;SPAN class=kwrd&gt;void&lt;/SPAN&gt; MyCallBack(LoadOperation&amp;lt;Customer&amp;gt; loadOperation)
{
       &lt;SPAN class=kwrd&gt;if&lt;/SPAN&gt; (loadOperation.HasError)
            //Handle the error
}&lt;/FONT&gt;&lt;/PRE&gt;
&lt;STYLE type=text/css&gt;.csharpcode {
	BACKGROUND-COLOR: #ffffff; FONT-FAMILY: consolas, "Courier New", courier, monospace; COLOR: black; FONT-SIZE: small
}
.csharpcode PRE {
	BACKGROUND-COLOR: #ffffff; FONT-FAMILY: consolas, "Courier New", courier, monospace; COLOR: black; FONT-SIZE: small
}
.csharpcode PRE {
	MARGIN: 0em
}
.csharpcode .rem {
	COLOR: #008000
}
.csharpcode .kwrd {
	COLOR: #0000ff
}
.csharpcode .str {
	COLOR: #006080
}
.csharpcode .op {
	COLOR: #0000c0
}
.csharpcode .preproc {
	COLOR: #cc6633
}
.csharpcode .asp {
	BACKGROUND-COLOR: #ffff00
}
.csharpcode .html {
	COLOR: #800000
}
.csharpcode .attr {
	COLOR: #ff0000
}
.csharpcode .alt {
	BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; WIDTH: 100%
}
.csharpcode .lnum {
	COLOR: #606060
}
&lt;/STYLE&gt;

&lt;P&gt;&lt;BR&gt;The following solution will use the LoadOptions’s Completed event to check if an error has occurred: &lt;BR&gt;&lt;/P&gt;&lt;PRE class=csharpcode&gt;&lt;FONT face="Courier New"&gt;&lt;BR&gt;var d = &lt;SPAN class=kwrd&gt;new&lt;/SPAN&gt; MyDomainContext();

var loadOperation = d.Load&amp;lt;Customer&amp;gt;(d.GetCustomersQuery());
loadOption.Completed += &lt;SPAN class=kwrd&gt;new&lt;/SPAN&gt; EventHandler(loadOption_Completed);

...


&lt;SPAN class=kwrd&gt;void&lt;/SPAN&gt; loadOption_Completed(&lt;SPAN class=kwrd&gt;object&lt;/SPAN&gt; sender, EventArgs e)
{
      &lt;SPAN class=kwrd&gt;if&lt;/SPAN&gt; (((LoadOperation)sender).HasError)
            //handle the error
}&lt;/FONT&gt;&lt;/PRE&gt;
&lt;P&gt;
&lt;STYLE type=text/css&gt;.csharpcode {
	BACKGROUND-COLOR: #ffffff; FONT-FAMILY: consolas, "Courier New", courier, monospace; COLOR: black; FONT-SIZE: small
}
.csharpcode PRE {
	BACKGROUND-COLOR: #ffffff; FONT-FAMILY: consolas, "Courier New", courier, monospace; COLOR: black; FONT-SIZE: small
}
.csharpcode PRE {
	MARGIN: 0em
}
.csharpcode .rem {
	COLOR: #008000
}
.csharpcode .kwrd {
	COLOR: #0000ff
}
.csharpcode .str {
	COLOR: #006080
}
.csharpcode .op {
	COLOR: #0000c0
}
.csharpcode .preproc {
	COLOR: #cc6633
}
.csharpcode .asp {
	BACKGROUND-COLOR: #ffff00
}
.csharpcode .html {
	COLOR: #800000
}
.csharpcode .attr {
	COLOR: #ff0000
}
.csharpcode .alt {
	BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; WIDTH: 100%
}
.csharpcode .lnum {
	COLOR: #606060
}
&lt;/STYLE&gt;
&lt;/P&gt;
&lt;P&gt;&lt;BR&gt;If you wonder what solution I prefer, it would be the one that uses a callback. I do want to see some changes to the .NET RIA Services Load operations, like specifying a callback just for handling exceptions, and a default generated callback added to the DominaContext, which will be called if no callback is used, by doing so, we could get an exception when the Load fails without adding some extra code.&lt;/P&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7174776" width="1" height="1"&gt;</content><author><name>Fredrik N</name><uri>http://weblogs.asp.net/members/Fredrik-N.aspx</uri></author><category term="Silverlight 3.0" scheme="http://weblogs.asp.net/fredriknormen/archive/tags/Silverlight+3.0/default.aspx" /><category term=".NET RIA Services" scheme="http://weblogs.asp.net/fredriknormen/archive/tags/.NET+RIA+Services/default.aspx" /><category term="RIA" scheme="http://weblogs.asp.net/fredriknormen/archive/tags/RIA/default.aspx" /></entry></feed>