<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://weblogs.asp.net/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Fredrik Normén</title><link>http://weblogs.asp.net/fredriknormen/default.aspx</link><description>Any fool can write code that a computer can understand. Good programmers write code that humans can understand - Fowler</description><dc:language>en</dc:language><generator>CommunityServer 2007 SP1 (Build: 20510.895)</generator><item><title>Will .NET RIA Services be the Silver Bullet!</title><link>http://weblogs.asp.net/fredriknormen/archive/2009/04/30/will-net-ria-services-be-the-silver-bullet.aspx</link><pubDate>Thu, 30 Apr 2009 06:30:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7066229</guid><dc:creator>Fredrik N</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/fredriknormen/rsscomments.aspx?PostID=7066229</wfw:commentRss><comments>http://weblogs.asp.net/fredriknormen/archive/2009/04/30/will-net-ria-services-be-the-silver-bullet.aspx#comments</comments><description>&lt;P&gt;I have spend some time on the Silverligth.net forum and in the .NET RIA Services thread.. and just created a replay on a post about RIA Architecture and design.. I have some concerns regarding to how developers are using .NET RIA Services etc.. maybe it’s not a big deal.. but I will try to share my concerns and made a copy of my replay and created it as a blog post. I look forward to your comments. To get basic understanding about about my view of a RIA Architecture and also .NET RIA Servers, I prefer you read my two other blog post before you read this blog post.&lt;/P&gt;
&lt;P&gt;&lt;A href="http://weblogs.asp.net/fredriknormen/archive/2009/04/19/ria-architecture-with-silverlight-in-mind.aspx" mce_href="http://weblogs.asp.net/fredriknormen/archive/2009/04/19/ria-architecture-with-silverlight-in-mind.aspx"&gt;RIA Architecture with Silverlight in mind&lt;/A&gt; &lt;BR&gt;&lt;BR&gt;&lt;A href="http://weblogs.asp.net/fredriknormen/archive/2009/04/18/a-different-view-of-the-net-ria-services.aspx" mce_href="http://weblogs.asp.net/fredriknormen/archive/2009/04/18/a-different-view-of-the-net-ria-services.aspx"&gt;A different view of the .Net RIA Services&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Developers are so desire to use a perfect and great domain model to work with. It will help us a lot..(I will claim that a domain model is not a silver bullet, it's a way we prefer to work these days, and I prefer it too). We are used to work that way, we like to work that way.. so why not do it and why not in a distributed system? There are some technologies that tried to make sure we could work with object in a distributed system, like DCOM, CORBA and RMI etc. Now we have .NET RIA Services.. &lt;BR&gt;&lt;BR&gt;When I have read threads in&amp;nbsp;Silverlight.Net forum, I notice that developers tries to create complex models and want a server side model to also be used on the client side. Nothing strange, it’s how we will work, right? So what is the main problem? Well, developers creates complex models, and do it in one place (on the server side), and the .NET RIA Services can "copy" by using code-gen this model to the client-side. Developers can still work with the entities as it was locally, because it is what we want to do, it make it a lot easier for use to build our apps.. we are used to it! But one of the problems with systems like DCOM, RMI, CORBA and sort of .NET RIA Services is that they tend to try and hide the fact that we are actually talking across a network. Everyone that uses these technologies knows that we are talking across a network, but it’s so easy to forget about it, because of the possibility to use object in a way we want to. The way they hide it, is that we don’t need to care about knowing about it. It’s the plumbing that is removed from us. So we can create our model, and suddenly we have it on the client side and can work with it as it was “locally”. We have one place where we create our shared domain model and we can forget about the network (not saying that everyone does, but regarding to some post in this forum, I think they are). &lt;BR&gt;&lt;BR&gt;By adding inheritance, lazy-loading (which we want to use, to solve some problems) etc, will only make sure we try more and more to work in a way we are used to, even with a distributed system, and we will get blinded and don’t see the network. We don’t want to see it, because it will affect how we wants to work, and it make sure we can’t do what we wants to do.. so we just remove it from our mind, we hide it, we don’t see it, we pretend it wasn’t there. I love the sounds of it, it would be perfect if we don’t need to think about it. Because if it was never there, we can work in the way we want to work, right?&lt;/P&gt;
&lt;P&gt;As long as developers know and have the network in mind and create a model based on it, I will be satisfied, but it will probably not happen. The same mistakes have done before, and we are only repeating our self. Designing a system that uses both network capabilities and object oriented design techniques to their fullest advantage is still possible and desirable, and engineers will try to solve this. Some day they may succeed, maybe the final version of .NET RIA Services will be the ONE! But as long as there isn’t a Silver bullet yet! I will try to remind people about the network and the distribution.&lt;BR&gt;&lt;BR&gt;EDIT: Only to not get comments regarding the hidden stuff:&lt;/P&gt;
&lt;P&gt;I know that .NET RIA Services team is not trying to “hide” the distributin, but the way people wants to use it, to solve a common problem, and what they are requested and tries to do, concerns me.. and what most developers wants (if it will be available), will make sure the distribution will become “hidden”.&lt;/P&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7066229" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/fredriknormen/archive/tags/.NET+RIA+Services/default.aspx">.NET RIA Services</category><category domain="http://weblogs.asp.net/fredriknormen/archive/tags/RIA/default.aspx">RIA</category></item><item><title>RIA Architecture with Silverlight in mind</title><link>http://weblogs.asp.net/fredriknormen/archive/2009/04/19/ria-architecture-with-silverlight-in-mind.aspx</link><pubDate>Sun, 19 Apr 2009 10:47:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7050077</guid><dc:creator>Fredrik N</dc:creator><slash:comments>10</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/fredriknormen/rsscomments.aspx?PostID=7050077</wfw:commentRss><comments>http://weblogs.asp.net/fredriknormen/archive/2009/04/19/ria-architecture-with-silverlight-in-mind.aspx#comments</comments><description>&lt;P&gt;Rich Internet Application (RIA) is an interesting topic. More and more business apps are moving into to the cloud, and more and more will have better User Experience (Ux). According to Gartner Research, nearly 60 percent of all new application development will include RIA technology by 2010. Today we can use different technologies to build a RIA, for example, AJAX, Flash and Silverlight etc. When it comes to AJAX we will soon reach the top of what we can do with it, because of the limitation of HTML, Client-side scripts and the browsers etc. That makes Silverlight and Flash more interesting regarding to me. But what is RIA? RIA It’s an internet applications that looks and feels like desktop applications, it also provide most of the maintainability and deployment benefits of Web applications. A RIA client can have state, so to increase User Experience, the user can work with data for a while until it will be passed down to the server for processing. Because the client side of a RIA can have state and work with data for a while, it’s extra important to have concurrency in mind. Some other users can have changed the data during the time we have worked with our copy. When developing RIA Clients we need to have several things in mind, for example a RIA is often running within an execution container in the Browser, so people can hit the refresh button or use the back and forward buttons, which can be reload the whole app and the current state can be gone. When we creates a large RIA, we can’t let users wait for hours until the application is loaded and started, so we need to load views etc on demand, and split them into small “modules”. Developing a RIA is not like developing a stateless ASP.NET app.&lt;/P&gt;
&lt;P&gt;In this post I will write about the architecture and design I use when building a RIA with Silverlight.&lt;/P&gt;
&lt;P&gt;The following is a figure of an Architecture of a typical RIA implementation: &lt;BR&gt;&lt;BR&gt;&lt;BR&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://weblogs.asp.net/blogs/fredriknormen/RIA_arch_1C52C1AD.jpg" mce_href="http://weblogs.asp.net/blogs/fredriknormen/RIA_arch_1C52C1AD.jpg"&gt;&lt;IMG style="BORDER-RIGHT-WIDTH: 0px; DISPLAY: inline; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" title=RIA_arch border=0 alt=RIA_arch src="http://weblogs.asp.net/blogs/fredriknormen/RIA_arch_thumb_4D05C958.jpg" width=299 height=484 mce_src="http://weblogs.asp.net/blogs/fredriknormen/RIA_arch_thumb_4D05C958.jpg"&gt;&lt;/A&gt; &lt;/P&gt;
&lt;P&gt;The Presentation Layers purpose is to make sure users gets the best possible User Experience. The Presentation Layer of a RIA should not include too much business logic, instead it will communicate with a Web Server to perform business operations. This is done by accessing a Application Service Layer which in turn will communicate with the Domain Model [Evans DDD]. In this post I will focus more on the Application Service Layer and the Presentation layer, rather then the other layers or tiers.&lt;STRONG&gt; &lt;BR&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;H2&gt;Business Logic, where to place it?&lt;/H2&gt;
&lt;P&gt;Because a RIA often look and feel like a desktop application, and can have state, it can be appealing to add a lot of business logic to the Presentation Layer. But try to not do that. The only kind of business logic that should be in the Presentation Layer is user input validations, and business logic that can increase user experience and increases performance overall, for example by avoiding communications to the Web Server or some expensive business operations, which can for example improve the UI responsiveness. Start with your business logic implementation on&amp;nbsp; the server and expose them through services. It will make sure you don’t start adding a lot of business logic to the client at the first place. One problem with the business logic is that same business logic can exists on both the client and server side. For example validations. To address this issue you can for example use the Microsoft .NET RIA Services. If you don’t want to use the .NET RIA Services, make sure you group the business logic into a separate assembly, which you can share both with the Server and client, or at least make sure you reuse the same kind of code and language, so you can easily replace the code when changes is made to the business logic on the server and should also be changed on the client side. Some logic should never be on the client side, such as highly sensitive business logic. Add it to the server for security reasons. If the client side are going to need a lot of business logic that can be changed often, make sure to add it to a downloadable module. It will make it easy to replace the logic without re-downloading the entire RIA application.&lt;/P&gt;
&lt;H2&gt;How to share Business logic between tier with .Net RIA Services&lt;/H2&gt;
&lt;P&gt;The .NET RIA Services lets us create a DomainService where we can add our CRUD operations and custom queries. We can also use metadata to add shared validation logic and also add code that should be shared between the client and the server. .NET RIA Services will locate our DomainServices, metadata and shared code, and generate client-side classes for us. The following code is a simple DomainService which will return a list of an “Entity” (You can find more about design considerations etc when creating entities later in this post): &lt;BR&gt;&lt;BR&gt;&lt;/P&gt;
&lt;DIV&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;[EnableClientAccess()]
&lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;class&lt;/SPAN&gt; UserService : DomainService
{
    &lt;SPAN style="COLOR: #0000ff"&gt;private&lt;/SPAN&gt; UserDataService _userDataService = &lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt; UserDataService();

    [Query(PreserveName=&lt;SPAN style="COLOR: #0000ff"&gt;true&lt;/SPAN&gt;)]
    &lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; IEnumerable&amp;lt;User&amp;gt; Followers()
    {
        &lt;SPAN style="COLOR: #0000ff"&gt;return&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;this&lt;/SPAN&gt;._userDataService.Users;
    }
}&lt;/PRE&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;BR&gt;Here is en implementation of the User Entity:&lt;/P&gt;
&lt;DIV&gt;&lt;BR&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;partial&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;class&lt;/SPAN&gt; User
{
   [Key]
   &lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; ID { get; set; }

   &lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; Name { get; set; }

   &lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; Description { get; set; }
}&lt;/PRE&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;BR&gt;To add validations that are applied on both tiers we can create a metadata class: &lt;BR&gt;&lt;BR&gt;&lt;/P&gt;
&lt;DIV&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;[MetadataType(&lt;SPAN style="COLOR: #0000ff"&gt;typeof&lt;/SPAN&gt;(UserMetaData))]
&lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;partial&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;class&lt;/SPAN&gt; User
{
    &lt;SPAN style="COLOR: #0000ff"&gt;internal&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;sealed&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;class&lt;/SPAN&gt; UserMetaData
    {
        [Required]
        &lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; Name;

        [Required]
        [StringLength(255, MinimumLength = 0)]
        &lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; Description;
    }
}&lt;/PRE&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;BR&gt;The above metadata class will make sure that the generated Entity for the client-side will have the validations specified by using attributes. When it comes to validation, make sure to validate both on the client side to improve user experience, and server side validation for security. The magic to share business logic between the client and server is by using code generation. There is only one place the business logic is added, and it’s on the server side, but can be shared with the client side without adding duplications. &lt;BR&gt;&lt;BR&gt;&lt;BR&gt;&lt;/P&gt;
&lt;H2&gt;Communication&lt;/H2&gt;
&lt;P&gt;To increase the user experience and performance, the communication from the client side to the server must be made asynchronous. If not we can block the UI thread. If long running code is needed, it’s worth to consider if a background thread should be used or not. Here is an example how the Silverlight’s BackgroudWorker can be used to run a thread in the background: &lt;BR&gt;&lt;BR&gt;&lt;BR&gt;&lt;/P&gt;
&lt;DIV&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; MainPage()
{
    InitializeComponent();

    var bw = &lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt; BackgroundWorker();
    bw.RunWorkerCompleted += bw_RunWorkerCompleted;
    bw.DoWork += bw_DoWork;
    bw.RunWorkerAsync();
}

&lt;SPAN style="COLOR: #0000ff"&gt;void&lt;/SPAN&gt; bw_DoWork(&lt;SPAN style="COLOR: #0000ff"&gt;object&lt;/SPAN&gt; sender, DoWorkEventArgs e)
{
    &lt;SPAN style="COLOR: #008000"&gt;//perform the work&lt;/SPAN&gt;
    e.Result = result of the operation &lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt; any
}

&lt;SPAN style="COLOR: #0000ff"&gt;void&lt;/SPAN&gt; bw_RunWorkerCompleted(&lt;SPAN style="COLOR: #0000ff"&gt;object&lt;/SPAN&gt; sender, RunWorkerCompletedEventArgs e)
{
    &lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt; (e.Error != &lt;SPAN style="COLOR: #0000ff"&gt;null&lt;/SPAN&gt;)
       &lt;SPAN style="COLOR: #008000"&gt;//handle exception&lt;/SPAN&gt;

    &lt;SPAN style="COLOR: #008000"&gt;//get the result from e.Result and do for example update UI&lt;/SPAN&gt;
}&lt;/PRE&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;EM&gt;Note: When performing operations in a background thread, it can be advisable to show the user the progress of the operation (if the user should see any result after the operation is completed). The BackgroundWorker class has a ProgressChanged support.&lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;To communicate to the Server, WCF, APS.NET WebServices, .NET RIA Services, ADO.NET Data Service, WebClient etc can be used. When passing data from server to the client or back, try to remember that there can be some bandwidth limitations. When creating a distributed system, objects shouldn’t be distributed. So don’t distribute your domain model’s entity. Instead create new kind of “resources”. For example by using formats like JSON, XML or DataContracts, and only pass the data that is needed by the presentation layer. Try to focus on what data a specific View needs. If you need to save data on the client-side for offline support, make sure to use the Isolated Storage or the new SaveFileDialog added to Silverlight 3.0. Don’t use a local databases, instead make sure you make a call to a Service. If it would be catastrophic to lose state data on the client, make sure to store it on the server. Try to minimize the number of round-trips to the server. Make sure to filter all data at server rather than at the client to reduce the amount of data that must be sent over the network. By using .NET RIA Services, we can without adding new methods to the DomainService, make sure a Query is passed as an argument to the server and the server will do the filtering. Try to avoid creating too much queries on the client side, if you have common quires witch is located on several Views on the client side, make sure you add a common query as a method to a DomainService instead. It will make it much easier for you to maintain&amp;nbsp; the application. &lt;BR&gt;&lt;/P&gt;
&lt;P&gt;The following is an example of how WebClient together with XDocument can be used to retrieve data from the server, with a REST like way: &lt;BR&gt;&lt;BR&gt;&lt;/P&gt;
&lt;DIV&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; MainPage()
{
     InitializeComponent();

     var wc = &lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt; WebClient();

     wc.OpenReadCompleted += wc_OpenReadCompleted;
     wc.OpenReadAsync(&lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt; Uri(&lt;SPAN style="COLOR: #006080"&gt;"/User/Followers"&lt;/SPAN&gt;, UriKind.Relative));
}

&lt;SPAN style="COLOR: #0000ff"&gt;void&lt;/SPAN&gt; wc_OpenReadCompleted(&lt;SPAN style="COLOR: #0000ff"&gt;object&lt;/SPAN&gt; sender, OpenReadCompletedEventArgs e)
{
    XDocument xmlUsers = XDocument.Load(e.Result);

    var users = from user &lt;SPAN style="COLOR: #0000ff"&gt;in&lt;/SPAN&gt; xmlUsers.Descendants(&lt;SPAN style="COLOR: #006080"&gt;"user"&lt;/SPAN&gt;)
                select &lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt;
                       {
                         ID = (&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt;)user.Element(&lt;SPAN style="COLOR: #006080"&gt;"ID"&lt;/SPAN&gt;).Value,
                         Name = (&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt;)user.Element(&lt;SPAN style="COLOR: #006080"&gt;"Name"&lt;/SPAN&gt;).Value,
                         Description = (&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt;)user.Element(&lt;SPAN style="COLOR: #006080"&gt;"Description"&lt;/SPAN&gt;).Value
                       }; 

}&lt;/PRE&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;BR&gt;&lt;BR&gt;The “/User/Followers” URI used by the WebClient, can for example be a REST API created by using ASP.NET MVC: &lt;BR&gt;&lt;BR&gt;&lt;BR&gt;&lt;/P&gt;
&lt;DIV&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;class&lt;/SPAN&gt; UserController : Controller
{
    &lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; ActionResult Followers()
    {
        var userDataService = &lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt; UserDataService();

        &lt;SPAN style="COLOR: #0000ff"&gt;return&lt;/SPAN&gt; View(userDataService.Users);
    }
}

Followers.aspx 

&amp;lt;%@ Page Language=&lt;SPAN style="COLOR: #006080"&gt;"C#"&lt;/SPAN&gt; 
         Inherits=&lt;SPAN style="COLOR: #006080"&gt;"System.Web.Mvc.ViewPage&amp;lt;List&amp;lt;Models.User&amp;gt;&amp;gt;"&lt;/SPAN&gt; %&amp;gt; 
&amp;lt;users type=&lt;SPAN style="COLOR: #006080"&gt;"array"&lt;/SPAN&gt;&amp;gt; 
    &amp;lt;% &lt;SPAN style="COLOR: #0000ff"&gt;foreach&lt;/SPAN&gt; (var user &lt;SPAN style="COLOR: #0000ff"&gt;in&lt;/SPAN&gt; ViewData.Model) { %&amp;gt;
        &amp;lt;user&amp;gt; 
            &amp;lt;id&amp;gt;&amp;lt;%= Html.Encode(user.ID)%&amp;gt;&amp;lt;/id&amp;gt; 
            &amp;lt;name&amp;gt;&amp;lt;%= Html.Encode(user.Name)%&amp;gt;&amp;lt;/name&amp;gt; 
            &amp;lt;description&amp;gt;&amp;lt;%= Html.Encode(user.Description)%&amp;gt;&amp;lt;/description&amp;gt; 
        &amp;lt;/user&amp;gt;
    &amp;lt;% } %&amp;gt; 
    &amp;lt;/user&amp;gt; 
&amp;lt;/users&amp;gt;&lt;/PRE&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;BR&gt;The following is how we can use a WCF Service to retrieve data from the server. The WCF Service is part of the Application Service Layer: &lt;BR&gt;&lt;BR&gt;&lt;BR&gt;&lt;/P&gt;
&lt;DIV&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;[DataContract]
&lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;class&lt;/SPAN&gt; User
{
    [DataMember]
    &lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; ID { get; set; }

    [DataMember]
    &lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; Name { get; set; }

    [DataMember]
    &lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; Description { get; set; }
}&lt;/PRE&gt;
&lt;DIV&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;P&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;class&lt;/SPAN&gt; UserService
{
    &lt;SPAN style="COLOR: #0000ff"&gt;private&lt;/SPAN&gt; UserDataService _userDataService = &lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt; UserDataService();

    [OperationContract]
    &lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; IEnumerable&amp;lt;User&amp;gt; GetFollowers()
    {
        &lt;SPAN style="COLOR: #0000ff"&gt;return&lt;/SPAN&gt; _userDataService.Users;
    }
}&lt;/P&gt;
&lt;/PRE&gt;&lt;/DIV&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;P&gt;MainPage.xaml.cs &lt;BR&gt;&lt;BR&gt;&lt;/P&gt;
&lt;DIV&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; MainPage()
     {
         InitializeComponent();

         var us = &lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt; UserServiceClient();
         us.GetFollowersCompleted += us_GetFollowersCompleted;
         us.GetFollowersAsync();
         
         
         myGrid.ItemsSource = _uc.Users;
         _uc.Followers(_uc.Users.AsQueryable&amp;lt;User&amp;gt;().Where( c =&amp;gt; c.ID == &lt;SPAN style="COLOR: #006080"&gt;"1"&lt;/SPAN&gt;) , &lt;SPAN style="COLOR: #0000ff"&gt;null&lt;/SPAN&gt;);

     }

     &lt;SPAN style="COLOR: #0000ff"&gt;void&lt;/SPAN&gt; us_GetFollowersCompleted(&lt;SPAN style="COLOR: #0000ff"&gt;object&lt;/SPAN&gt; sender, GetFollowersCompletedEventArgs e)
     {
         myGird.ItemSource = e.Result;
     }&lt;/PRE&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;BR&gt;As you can see in the above code, a DataContract is created, this contract should only return the information that the client needs. To minimize the data sent to the client over the network, it can be good to create data contracts for each View (Client side “forms”), but be pragmatic. If we will have more than one View that need the same data, we can reuse the same contracts if the different is only one or two properties, it may be unnecessarily to create two data contracts to reduce the data sent over the wire. But still have bandwidth in mind. I often create one Service per View, and if there are some other Views that should reuse the exact same kind of operations I reuse the Service, or create a new Service which in turn will access the other Service. It depends on the app and the Views etc.&lt;/P&gt;
&lt;P&gt;To make a call to a WCF Service, a Service Reference is needed to locate the Service and to create a client-side proxy class to make it easy to communicate with the Service.&lt;/P&gt;
&lt;P&gt;In the first example in this post I showed some .NET RIA Services code, where I created a DomainService. When the solution is build a generated proxy class will be created and added to the Silverlight project. This class is called a DomainContext. Here is an example where .NET RIA Services DomainContext is used to communicate to the DomainService: &lt;BR&gt;&lt;BR&gt;&lt;BR&gt;&lt;/P&gt;
&lt;DIV&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;partial&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;class&lt;/SPAN&gt; MainPage : UserControl
{
    UserContext _uc = &lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt; UserContext();

    &lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; MainPage()
    {
        InitializeComponent();

        var us = &lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt; UserServiceClient();
        us.GetFollowersCompleted += us_GetFollowersCompleted;
        us.GetFollowersAsync();
        
        myGrid.ItemsSource = _uc.Users;
        _uc.Followers();

    }

    &lt;SPAN style="COLOR: #0000ff"&gt;void&lt;/SPAN&gt; us_GetFollowersCompleted(&lt;SPAN style="COLOR: #0000ff"&gt;object&lt;/SPAN&gt; sender, GetFollowersCompletedEventArgs e)
    {
        myGird.ItemSource = e.Result;
    }
}&lt;/PRE&gt;&lt;/DIV&gt;
&lt;P mce_keep="true"&gt;&lt;BR&gt;Now when you have seen some different ways to communicate with a Service form the Client, we can focus more on the data passed to the client from the server and back..&lt;/P&gt;
&lt;H2&gt;Data&lt;/H2&gt;
&lt;P&gt;When creating a distributed system we should never distribute an object. So don’t try to pass entities from the Domain Model to the client side. Instead create a new model only for presentation purpose. For example with DataContracts or if you are using REST a resource, or a thin object only used for presentation purpose if you are using .NET RIA Services. Here is a figure over how I often build my applications: &lt;BR&gt;&lt;BR&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://weblogs.asp.net/blogs/fredriknormen/ria_arch2_67D1EF64.jpg" mce_href="http://weblogs.asp.net/blogs/fredriknormen/ria_arch2_67D1EF64.jpg"&gt;&lt;IMG style="BORDER-RIGHT-WIDTH: 0px; DISPLAY: inline; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" title=ria_arch2 border=0 alt=ria_arch2 src="http://weblogs.asp.net/blogs/fredriknormen/ria_arch2_thumb_38A003CD.jpg" width=587 height=484 mce_src="http://weblogs.asp.net/blogs/fredriknormen/ria_arch2_thumb_38A003CD.jpg"&gt;&lt;/A&gt; &lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;EM&gt;Note: The View Model is not the Pattern ViewModel. It’s a model created for presentation purpose only, for example a DataContract, or at .NET RIA Services Entity etc.&lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;One of the important part when creating a RIA, is to focus on the “model” that the View should use. If we for example should list all Customers, and we only need display three properties, we creates a class/resource or DataContract for that purpose, for example:&lt;/P&gt;
&lt;DIV&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;partial&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;class&lt;/SPAN&gt; Customer
{
   [Key]
   &lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; ID { get; set; }

   &lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; Name { get; set; }

   &lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; Country { get; set; }
}&lt;/PRE&gt;&lt;/DIV&gt;
&lt;P mce_keep="true"&gt;&lt;BR&gt;If we need more detail about a Customer, we create a new class with the properties needed:&lt;/P&gt;
&lt;DIV&gt;&lt;BR&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;P&gt;&lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;partial&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;class&lt;/SPAN&gt; CustomerDetail
{
  [Key]
  &lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; ID { get; set; }

  &lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; Name { get; set; }

  &lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; Country { get; set; }

  &lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; Description { get; set; }

  &lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; Email { get; set; }&lt;/P&gt;
&lt;P&gt;  ...
}&lt;/P&gt;
&lt;/PRE&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;BR&gt;When building RIA, performance and bandwidth is something we should have in consideration, so it’s not sure a user will show detailed information about a Customer, so in this case we make sure we have two methods in our Application Service Layer, GetCustomer and GetCustomers. The GetCustomer will return the CustomerDetail class and the GetCustomers the Customer class. If we know that a user will show all the information of a customer, and will get a set of Customers to always work with. We can create a method that will return a list of CustomerDetails. If we create a small applications for few users and it’s an intranet application, the bandwidth may not be a problem, so in that case we can return more data that isn’t needed in specific scenario but is needed for other scenarios to reduce the number of classes created etc. So everything depends on!&lt;/P&gt;
&lt;H2&gt;Presentation Layer Pattern&lt;/H2&gt;
&lt;P&gt;I often use a UI patterns like the Presentation Model/ViewModel pattern. The MVC pattern could be used, but I prefer the Presentation Model pattern in a RIA. If you are interested in how a Presentation Model could look like when using Silveright, you can read the following post on my blog: &lt;A href="http://weblogs.asp.net/fredriknormen/archive/2009/01/30/how-the-presentation-model-could-look-like-when-using-silverlight-2-0.aspx" mce_href="http://weblogs.asp.net/fredriknormen/archive/2009/01/30/how-the-presentation-model-could-look-like-when-using-silverlight-2-0.aspx"&gt;http://weblogs.asp.net/fredriknormen/archive/2009/01/30/how-the-presentation-model-could-look-like-when-using-silverlight-2-0.aspx&lt;/A&gt;&lt;/P&gt;
&lt;H2&gt;The end&lt;/H2&gt;
&lt;P&gt;There is so much to write about when it comes to the topic of this blog post but I hope you have found some useful tip. If there is something you don’t agree on, please let me know, I only share my experience ;)&lt;/P&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7050077" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/fredriknormen/archive/tags/Design/default.aspx">Design</category><category domain="http://weblogs.asp.net/fredriknormen/archive/tags/Architect/default.aspx">Architect</category><category domain="http://weblogs.asp.net/fredriknormen/archive/tags/Silverlight+3.0/default.aspx">Silverlight 3.0</category><category domain="http://weblogs.asp.net/fredriknormen/archive/tags/.NET+RIA+Services/default.aspx">.NET RIA Services</category><category domain="http://weblogs.asp.net/fredriknormen/archive/tags/RIA/default.aspx">RIA</category></item><item><title>A different view of the .Net RIA Services</title><link>http://weblogs.asp.net/fredriknormen/archive/2009/04/18/a-different-view-of-the-net-ria-services.aspx</link><pubDate>Sat, 18 Apr 2009 08:21:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7049581</guid><dc:creator>Fredrik N</dc:creator><slash:comments>5</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/fredriknormen/rsscomments.aspx?PostID=7049581</wfw:commentRss><comments>http://weblogs.asp.net/fredriknormen/archive/2009/04/18/a-different-view-of-the-net-ria-services.aspx#comments</comments><description>&lt;P&gt;Some of you have probably heard about the Microsoft .Net RIA Services, if not you can find some info &lt;A href="http://blogs.msdn.com/brada/archive/2009/03/19/what-is-net-ria-services.aspx" mce_href="http://blogs.msdn.com/brada/archive/2009/03/19/what-is-net-ria-services.aspx"&gt;here&lt;/A&gt;.&amp;nbsp;In this post I will show you a different view of the .Net RIA Services, how it can be used to create a RESTfull Service, or at least try ;)&lt;/P&gt;
&lt;P&gt;REST Services is about “nouns” (resources, like friends, customers etc) with few “verbs” for example create, read, update and destroy. We can easily create a “resource”, where the resource can be in different kind of formats like JSON, XAML, RSS etc. It’s more or less up to us what kind of formats we want to use. If we take a look at Twitter, the REST API they use can return a resource in different formats. When we create the resource, we need to create the response value (A Response value is the value returned from a REST API, it’s a resource in a specific format). If we want to get all of our Followers by using one of the Twitter’s REST API, we simply use the following URL: &lt;A title=http://twitter.com/statuses/followers.xml href="http://twitter.com/statuses/followers.xml" mce_href="http://twitter.com/statuses/followers.xml"&gt;http://twitter.com/statuses/followers.xml&lt;/A&gt; the .xml at the end specify the resource “followers” format. The response value is something like this: &lt;BR&gt;&lt;BR&gt;&lt;/P&gt;
&lt;DIV&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&amp;lt;?xml version=&lt;SPAN style="COLOR: #006080"&gt;"1.0"&lt;/SPAN&gt; encoding=&lt;SPAN style="COLOR: #006080"&gt;"UTF-8"&lt;/SPAN&gt; ?&amp;gt; 
&amp;lt;users type=&lt;SPAN style="COLOR: #006080"&gt;"array"&lt;/SPAN&gt;&amp;gt;
   &amp;lt;user&amp;gt;
     &amp;lt;id&amp;gt;1111111&amp;lt;/id&amp;gt; 
     &amp;lt;name&amp;gt;John Doe&amp;lt;/name&amp;gt; 
     &amp;lt;location&amp;gt;Stockholm&amp;lt;/location&amp;gt; 
     &amp;lt;description /&amp;gt; 
     &amp;lt;profile_image_url&amp;gt;&amp;lt;/profile_image_url&amp;gt; 
     ...

   &amp;lt;/user&amp;gt;

   ...

&amp;lt;/users&amp;gt;&lt;/PRE&gt;&lt;/DIV&gt;
&lt;P mce_keep="true"&gt;The resource is something the developers of the API have decided. If we want to use the .NET RIA Services we can simply define the resource of the response value like a simple POCO class. Like this: &lt;/P&gt;
&lt;DIV&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;partial&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;class&lt;/SPAN&gt; User
{
    [Key]
    &lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; ID { get; set; }

    &lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; Name { get; set; }

    &lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; Description { get; set; }
}&lt;/PRE&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;EM&gt;&lt;BR&gt;Note: The KeyAttribute is needed to specify a way to specify a property which will work as an identity for the “entity”. &lt;/EM&gt;&lt;/STRONG&gt;&lt;STRONG&gt;&lt;EM&gt;When using the .Net RIA Services the the classes we can create are referred as a Entity in a model. So we create a “model” more or less, but don’t see the User class as an entity in a Model, instead as a resource used by a specific REST API.&lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;By default .NET RIA Services will “serialize” the above class to a JSON format similar to this: &lt;BR&gt;&lt;BR&gt;&lt;/P&gt;
&lt;DIV&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;{
   &lt;SPAN style="COLOR: #006080"&gt;"__type"&lt;/SPAN&gt;:&lt;SPAN style="COLOR: #006080"&gt;"User:http://schemas.datacontract.org/2004/07/SilverlightApplication8.Web.DataModel"&lt;/SPAN&gt;,
   &lt;SPAN style="COLOR: #006080"&gt;"ID"&lt;/SPAN&gt;:&lt;SPAN style="COLOR: #006080"&gt;"1"&lt;/SPAN&gt;,
   &lt;SPAN style="COLOR: #006080"&gt;"Name"&lt;/SPAN&gt;:&lt;SPAN style="COLOR: #006080"&gt;"John Doe"&lt;/SPAN&gt;,
   &lt;SPAN style="COLOR: #006080"&gt;"Description"&lt;/SPAN&gt;:&lt;SPAN style="COLOR: #006080"&gt;"John Doe\u0027s description"&lt;/SPAN&gt;
}&lt;/PRE&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;BR&gt;Remember that this post is a different view of the .Net RIA Services, so once again try to see the POCO as a simple resource, not as an object which we will distribute (We all know that we shouldn’t distribute objects). &lt;/P&gt;
&lt;P&gt;Now when the resource is created, we can simply create a “fake” object which will return a list of it. &lt;BR&gt;&lt;BR&gt;&lt;/P&gt;
&lt;DIV&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;class&lt;/SPAN&gt; UserDataService
{
    &lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; IEnumerable&amp;lt;User&amp;gt; Users
    {
       get
       {
           &lt;SPAN style="COLOR: #0000ff"&gt;return&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt; List&amp;lt;User&amp;gt;()
                  {
                      &lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt; User()
                      {
                          ID = &lt;SPAN style="COLOR: #006080"&gt;"1"&lt;/SPAN&gt;,
                          Name = &lt;SPAN style="COLOR: #006080"&gt;"John Doe"&lt;/SPAN&gt;,
                          Description = &lt;SPAN style="COLOR: #006080"&gt;"John Doe's description"&lt;/SPAN&gt;
                      },
                      &lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt; User()
                      {
                          ID = &lt;SPAN style="COLOR: #006080"&gt;"2"&lt;/SPAN&gt;,
                          Name = &lt;SPAN style="COLOR: #006080"&gt;"Jane Doe"&lt;/SPAN&gt;,
                          Description = &lt;SPAN style="COLOR: #006080"&gt;"Jane Doe's description"&lt;/SPAN&gt;
                      }
                  };
        }
    }
}&lt;/PRE&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;BR&gt;&lt;STRONG&gt;&lt;EM&gt;Note: I couldn’t find a good name for this class, it looks like its a some kind of data access class but it isn’t. It’s more like taking a existing model and transform it to a resource. &lt;BR&gt;&lt;BR&gt;&lt;/EM&gt;&lt;/STRONG&gt;The next step is to create our REST API, in this case we can for example call it Followers, the same name as Twitter uses to get Followers. We can for example use ASP.NET MVC or a normal WebForm as a REST Service to get our resource.&lt;/P&gt;
&lt;P&gt;The following is a REST Service where ASP.NET MVC is used with a Controller named UserController with and an Action method called Followers. &lt;BR&gt;&lt;BR&gt;&lt;BR&gt;&lt;/P&gt;
&lt;DIV&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;class&lt;/SPAN&gt; UserController : Controller
{
    &lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; ActionResult Followers()
    {
        var userDataService = &lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt; UserDataService();

        &lt;SPAN style="COLOR: #0000ff"&gt;return&lt;/SPAN&gt; View(userDataService.Users);
    }
}&lt;/PRE&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;BR&gt;Followers.aspx &lt;BR&gt;&lt;BR&gt;&lt;BR&gt;&lt;/P&gt;
&lt;DIV&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&amp;lt;%@ Page Language=&lt;SPAN style="COLOR: #006080"&gt;"C#"&lt;/SPAN&gt; 
         Inherits=&lt;SPAN style="COLOR: #006080"&gt;"System.Web.Mvc.ViewPage&amp;lt;List&amp;lt;Models.User&amp;gt;&amp;gt;"&lt;/SPAN&gt; %&amp;gt; 
&amp;lt;users type=&lt;SPAN style="COLOR: #006080"&gt;"array"&lt;/SPAN&gt;&amp;gt; 
    &amp;lt;% &lt;SPAN style="COLOR: #0000ff"&gt;foreach&lt;/SPAN&gt; (var user &lt;SPAN style="COLOR: #0000ff"&gt;in&lt;/SPAN&gt; ViewData.Model) { %&amp;gt;
        &amp;lt;user&amp;gt; 
            &amp;lt;id&amp;gt;&amp;lt;%= Html.Encode(user.ID)%&amp;gt;&amp;lt;/id&amp;gt; 
            &amp;lt;name&amp;gt;&amp;lt;%= Html.Encode(user.Name)%&amp;gt;&amp;lt;/name&amp;gt; 
            &amp;lt;description&amp;gt;&amp;lt;%= Html.Encode(user.Description)%&amp;gt;&amp;lt;/description&amp;gt; 
        &amp;lt;/user&amp;gt;
    &amp;lt;% } %&amp;gt; 
    &amp;lt;/user&amp;gt; 
&amp;lt;/users&amp;gt;&lt;/PRE&gt;&lt;/DIV&gt;
&lt;P&gt;We can get the Followers by simply use the following URL:&amp;nbsp;&amp;nbsp; &lt;A href="http://%3cservername%3e/User/Followers" mce_href="http://&lt;servername&gt;/User/Followers"&gt;/User/Followers"&amp;gt;http://&amp;lt;servername&amp;gt;/User/Followers&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;To call the REST Service and it’s API, we can for example use the Silverlight’s WebClient class. We can also use the XDocument to get the data out from the resource: &lt;BR&gt;&lt;BR&gt;&lt;/P&gt;
&lt;DIV&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; MainPage()
{
     InitializeComponent();

     var wc = &lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt; WebClient();

     wc.OpenReadCompleted += wc_OpenReadCompleted;
     wc.OpenReadAsync(&lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt; Uri(&lt;SPAN style="COLOR: #006080"&gt;"/User/Followers"&lt;/SPAN&gt;, UriKind.Relative));
}

&lt;SPAN style="COLOR: #0000ff"&gt;void&lt;/SPAN&gt; wc_OpenReadCompleted(&lt;SPAN style="COLOR: #0000ff"&gt;object&lt;/SPAN&gt; sender, OpenReadCompletedEventArgs e)
{
    XDocument xmlUsers = XDocument.Load(e.Result);

    var users = from user &lt;SPAN style="COLOR: #0000ff"&gt;in&lt;/SPAN&gt; xmlUsers.Descendants(&lt;SPAN style="COLOR: #006080"&gt;"user"&lt;/SPAN&gt;)
                select &lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt;
                       {
                         ID = (&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt;)user.Element(&lt;SPAN style="COLOR: #006080"&gt;"ID"&lt;/SPAN&gt;).Value,
                         Name = (&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt;)user.Element(&lt;SPAN style="COLOR: #006080"&gt;"Name"&lt;/SPAN&gt;).Value,
                         Description = (&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt;)user.Element(&lt;SPAN style="COLOR: #006080"&gt;"Description"&lt;/SPAN&gt;).Value
                       }; 

}&lt;/PRE&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;BR&gt;If we use the above solution we need to do some plumbing. We first need to do a request to our URL to get the followers, then we need to read from the XML and get the values and map it to a type (if we want to work with a typed result). In this case wouldn’t it be nice to avoid some plumbing and instead use a solution where we simply use a typed API (not a string), and also get the result as typed classes with properties?&lt;/P&gt;
&lt;P&gt;Instead of doing all the plumbing, we can use the .Net RIA Services to create a REST Service. To create and implement our REST Service and API, we create a DomainService. A DomainService within the .NET RIA Services is a class where we add our CURD API and we can also add shared domain methods etc. To create a DoaminService we create a new class which will inherits from the .NET RIA Service’s DomainService base class. We will also add our Followers API to the DomainService: &lt;BR&gt;&lt;BR&gt;&lt;BR&gt;&lt;/P&gt;
&lt;DIV&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;[EnableClientAccess()]
&lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;class&lt;/SPAN&gt; UserService : DomainService
{
    &lt;SPAN style="COLOR: #0000ff"&gt;private&lt;/SPAN&gt; UserDataService _userDataService = &lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt; UserDataService();

    [Query(PreserveName=&lt;SPAN style="COLOR: #0000ff"&gt;true&lt;/SPAN&gt;)]
    &lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; IEnumerable&amp;lt;User&amp;gt; Followers()
    {
        &lt;SPAN style="COLOR: #0000ff"&gt;return&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;this&lt;/SPAN&gt;._userDataService.Users;
    }
}&lt;/PRE&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;EM&gt;&lt;BR&gt;Note: The EnableClientAccessAttribute is only used to make sure .NET RIA Services creates a client-side proxy for our DomainService, this proxy is called a DomainContext. The QueryAttribute with the property PreserverName, will make sure the generated DomainContext for the DomainService will preserver the name Followers. Normally we should add a method called “GetFollowers”, and the .NET RIA Services code generation will generate a method for the DomainContext called “LoadFollowers”.&lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;The Followers method will use the UserDataService’s Users method to get all the followers and return them.&lt;/P&gt;
&lt;P&gt;When we build our solution, the .NET RIA Services will generate a DomainContext for our Silverlight app, a proxy class which will make it easier for us to “call” the DominService. The generated DomainContext will communicate to the service through an AXD called DomainService.axd using REST. After we have created our DomainService, we can if we wants to, do a direct call to the DomainService.axd and use it as a REST Service: &lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;EM&gt;http://&amp;lt;servername&amp;gt;/DataService.axd/SilverlightApplication8-Web-DataModel-UserService/Followers&lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;When we enter the above URL we will get a response value in a JSON format like this: &lt;BR&gt;&lt;BR&gt;&lt;/P&gt;
&lt;DIV&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;{
    &lt;SPAN style="COLOR: #006080"&gt;"__type"&lt;/SPAN&gt;:&lt;SPAN style="COLOR: #006080"&gt;"DataServiceResult:DomainServices"&lt;/SPAN&gt;,
    &lt;SPAN style="COLOR: #006080"&gt;"IsDomainServiceException"&lt;/SPAN&gt;:&lt;SPAN style="COLOR: #0000ff"&gt;false&lt;/SPAN&gt;,
    &lt;SPAN style="COLOR: #006080"&gt;"Results"&lt;/SPAN&gt;:
        [
            {
                &lt;SPAN style="COLOR: #006080"&gt;"__type"&lt;/SPAN&gt;:&lt;SPAN style="COLOR: #006080"&gt;"User:http://schemas.datacontract.org/2004/07/SilverlightApplication8.Web.DataModel"&lt;/SPAN&gt;,
                &lt;SPAN style="COLOR: #006080"&gt;"ID"&lt;/SPAN&gt;:&lt;SPAN style="COLOR: #006080"&gt;"1"&lt;/SPAN&gt;,
                &lt;SPAN style="COLOR: #006080"&gt;"Name"&lt;/SPAN&gt;:&lt;SPAN style="COLOR: #006080"&gt;"John Doe"&lt;/SPAN&gt;,
                &lt;SPAN style="COLOR: #006080"&gt;"Description"&lt;/SPAN&gt;:&lt;SPAN style="COLOR: #006080"&gt;"John Doe\u0027s description"&lt;/SPAN&gt;
            },
            {
                &lt;SPAN style="COLOR: #006080"&gt;"__type"&lt;/SPAN&gt;:&lt;SPAN style="COLOR: #006080"&gt;"User:http://schemas.datacontract.org/2004/07/SilverlightApplication8.Web.DataModel"&lt;/SPAN&gt;,
                &lt;SPAN style="COLOR: #006080"&gt;"ID"&lt;/SPAN&gt;:&lt;SPAN style="COLOR: #006080"&gt;"2"&lt;/SPAN&gt;,
                &lt;SPAN style="COLOR: #006080"&gt;"Name"&lt;/SPAN&gt;:&lt;SPAN style="COLOR: #006080"&gt;"Jane Doe"&lt;/SPAN&gt;,
                &lt;SPAN style="COLOR: #006080"&gt;"Description"&lt;/SPAN&gt;:&lt;SPAN style="COLOR: #006080"&gt;"Jane Doe\u0027s description"&lt;/SPAN&gt;}
        ],
    &lt;SPAN style="COLOR: #006080"&gt;"TotalCount"&lt;/SPAN&gt;:-2
}&lt;/PRE&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;EM&gt;Note: The DomainService.axd will by default using the JavaScriptSerializer.&lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;The DomainSevice.axd will take the first “parameter” “SilverlightApplication8-Web-DataModel-UserService”&amp;nbsp; and replace “-“ to “.” to get the DomainService to instantiate. In this case it will be the UserService. It will then call a method with the same name as the last “parameter” of the URL, in this case “Followers” and use the JavaScriptSerializer to serialize the result of the Followers method.&lt;/P&gt;
&lt;P&gt;By using a class we create our resource. We have used the .NET RIA Services to create a REST Service with the API Followers to return a list of Users. We can then use the DomainService.axd to call our REST API. To make it simple for us to call the REST API and get a list of Users, we can now use the generated client-side proxy class (DomainContext) in our Silverlight project. It will give us a typed API and also a typed resource. So we don’t need to use the WebClient or a JSON Serializer on the client-side, the generated DomainContext for our DominService, will handle that for us. The following code is the code-behind file of the MainPage.xaml in a Silverlight app: &lt;BR&gt;&lt;BR&gt;&lt;BR&gt;&lt;/P&gt;
&lt;DIV&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;partial&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;class&lt;/SPAN&gt; MainPage : UserControl
{
    UserContext _uc = &lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt; UserContext();

    &lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; MainPage()
    {
        InitializeComponent();

        myGrid.ItemsSource = _uc.Users;
        _uc.Followers();

    }
}&lt;/PRE&gt;&lt;/DIV&gt;
&lt;P&gt;To make a call to the Followers API, we simply instantiate the generated DomainContext class “UserContext” and make a call to the Followers API. Every “entity/resource” we creates and returns from the DomainService will be added to the DomainContext as properties. So to get the User class after we make a call to the Followers method, we can use the Users property. When we call the Followers method, an asynchronous call to the DomainService will be made. The DomainContext will use REST behind the scene and call the DomainService.axd.&lt;/P&gt;
&lt;P&gt;Wouldn’t it be nice if we could instead of getting a whole list of Users, make it possible to define a query which will only returns the Users we want based on a criteria? It’s possible, and that is really cool: &lt;BR&gt;&lt;BR&gt;&lt;BR&gt;&lt;/P&gt;
&lt;DIV&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; MainPage()
{
    InitializeComponent();

    myGrid.ItemsSource = _uc.Users;
    _uc.Followers(_uc.Users.AsQueryable&amp;lt;User&amp;gt;().Where( c =&amp;gt; c.ID == &lt;SPAN style="COLOR: #006080"&gt;"1"&lt;/SPAN&gt;) , &lt;SPAN style="COLOR: #0000ff"&gt;null&lt;/SPAN&gt;);
}&lt;/PRE&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;BR&gt;By default all “Query” methods added to the DomainService, takes a IQueryable as an argument. So we can pass a query as an argument. So now we can use the DomainContext as a proxy to call a RESTful Service and also define a query.&lt;/P&gt;
&lt;P&gt;In this post, I wanted to give you a “different” view of .NET RIA Services, more or less to make sure you know how it works behind the scene, and also how it can be used to define a resource and a RESTful Service, because behind the scene .NET RIA Services uses REST.&lt;/P&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7049581" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/fredriknormen/archive/tags/Silverlight+3.0/default.aspx">Silverlight 3.0</category><category domain="http://weblogs.asp.net/fredriknormen/archive/tags/.NET+RIA+Services/default.aspx">.NET RIA Services</category><category domain="http://weblogs.asp.net/fredriknormen/archive/tags/REST+Service/default.aspx">REST Service</category><category domain="http://weblogs.asp.net/fredriknormen/archive/tags/RIA/default.aspx">RIA</category></item><item><title>Silverlight 3,0 Split styles and templates into different files and merge resources</title><link>http://weblogs.asp.net/fredriknormen/archive/2009/03/31/silverlight-3-0-split-style-and-template-into-different-files-and-merge-resources.aspx</link><pubDate>Tue, 31 Mar 2009 19:22:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7016533</guid><dc:creator>Fredrik N</dc:creator><slash:comments>5</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/fredriknormen/rsscomments.aspx?PostID=7016533</wfw:commentRss><comments>http://weblogs.asp.net/fredriknormen/archive/2009/03/31/silverlight-3-0-split-style-and-template-into-different-files-and-merge-resources.aspx#comments</comments><description>&lt;P&gt;Silverlight 3.0 now support a way to merge resources. So now we can split resources into different files. The following is a example of a simple resource file (ResourceA.xaml): &lt;BR&gt;&lt;/P&gt;
&lt;DIV&gt;&lt;BR&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&amp;lt;ResourceDictionary
    xmlns=&lt;SPAN style="COLOR: #006080"&gt;"http://schemas.microsoft.com/winfx/2006/xaml/presentation"&lt;/SPAN&gt;
    xmlns:x=&lt;SPAN style="COLOR: #006080"&gt;"http://schemas.microsoft.com/winfx/2006/xaml"&lt;/SPAN&gt;&amp;gt;

    &amp;lt;Style x:Name=&lt;SPAN style="COLOR: #006080"&gt;"MyButtonStyle"&lt;/SPAN&gt; TargetType=&lt;SPAN style="COLOR: #006080"&gt;"Button"&lt;/SPAN&gt;&amp;gt;
        &amp;lt;Setter Property=&lt;SPAN style="COLOR: #006080"&gt;"Background"&lt;/SPAN&gt; Value=&lt;SPAN style="COLOR: #006080"&gt;"red"&lt;/SPAN&gt;/&amp;gt;
    &amp;lt;/Style&amp;gt;

&amp;lt;/ResourceDictionary&amp;gt;&lt;/PRE&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;BR&gt;When you create a resource file, make sure the Build Action is set to Resource for the file.&lt;/P&gt;
&lt;P&gt;If you want to globally want to merge different resource file you can for example do it on a application level by using the App.xaml file. To merge a Resource file, you need to use the ResourceDictionary object and it’s MergedDictionaries property, which takes ResourceDictionary objects as values. By using the ResourceDictionary’s Source property, you can specify the source for a resource file: &lt;BR&gt;&lt;BR&gt;&lt;BR&gt;&lt;/P&gt;
&lt;DIV&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&amp;lt;Application.Resources&amp;gt;

    &amp;lt;ResourceDictionary&amp;gt;
        &amp;lt;ResourceDictionary.MergedDictionaries&amp;gt;
            &amp;lt;ResourceDictionary Source=&lt;SPAN style="COLOR: #006080"&gt;"ResourceA.xaml"&lt;/SPAN&gt;/&amp;gt;
            &amp;lt;ResourceDictionary Source=&lt;SPAN style="COLOR: #006080"&gt;"ResourceB.xaml"&lt;/SPAN&gt;/&amp;gt;
        &amp;lt;/ResourceDictionary.MergedDictionaries&amp;gt;
    &amp;lt;/ResourceDictionary&amp;gt;

&amp;lt;/Application.Resources&amp;gt;&lt;/PRE&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;BR&gt;You can of course use a resource file on a User Control level: &lt;BR&gt;&lt;BR&gt;&lt;BR&gt;&lt;/P&gt;
&lt;DIV&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&amp;lt;UserControl x:Class=&lt;SPAN style="COLOR: #006080"&gt;"SilverlightApplication6.MainPage"&lt;/SPAN&gt;
    xmlns=&lt;SPAN style="COLOR: #006080"&gt;"http://schemas.microsoft.com/winfx/2006/xaml/presentation"&lt;/SPAN&gt; 
    xmlns:x=&lt;SPAN style="COLOR: #006080"&gt;"http://schemas.microsoft.com/winfx/2006/xaml"&lt;/SPAN&gt;
    xmlns:m=&lt;SPAN style="COLOR: #006080"&gt;"clr-namespace:SilverlightApplication6.MyControl"&lt;/SPAN&gt;
    Width=&lt;SPAN style="COLOR: #006080"&gt;"400"&lt;/SPAN&gt; Height=&lt;SPAN style="COLOR: #006080"&gt;"300"&lt;/SPAN&gt;&amp;gt;
    &amp;lt;UserControl.Resources&amp;gt;
        &amp;lt;ResourceDictionary&amp;gt;
            &amp;lt;ResourceDictionary.MergedDictionaries&amp;gt;
                &amp;lt;ResourceDictionary Source=&lt;SPAN style="COLOR: #006080"&gt;"ResourceA.xaml"&lt;/SPAN&gt;/&amp;gt;
            &amp;lt;/ResourceDictionary.MergedDictionaries&amp;gt;
        &amp;lt;/ResourceDictionary&amp;gt;
    &amp;lt;/UserControl.Resources&amp;gt;
    
    &amp;lt;Grid x:Name=&lt;SPAN style="COLOR: #006080"&gt;"LayoutRoot"&lt;/SPAN&gt; Background=&lt;SPAN style="COLOR: #006080"&gt;"White"&lt;/SPAN&gt;&amp;gt;

        &amp;lt;StackPanel&amp;gt;
            &amp;lt;Button Style=&lt;SPAN style="COLOR: #006080"&gt;"{StaticResource MyButtonStyle}"&lt;/SPAN&gt;/&amp;gt;
            &amp;lt;Button Style=&lt;SPAN style="COLOR: #006080"&gt;"{StaticResource MyButtonStyleB}"&lt;/SPAN&gt;/&amp;gt;
        &amp;lt;/StackPanel&amp;gt;

    &amp;lt;/Grid&amp;gt;
&amp;lt;/UserControl&amp;gt;&lt;/PRE&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;BR&gt;If you only need to “include” on resource file, you don’t need to use the MergedDictionaries property. Here is an example where only one resource file is used: &lt;BR&gt;&lt;BR&gt;&lt;BR&gt;&lt;/P&gt;
&lt;DIV&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&amp;lt;UserControl.Resources&amp;gt;
    &amp;lt;ResourceDictionary Source=&lt;SPAN style="COLOR: #006080"&gt;"ResourceA.xaml"&lt;/SPAN&gt;/&amp;gt;
&amp;lt;/UserControl.Resources&amp;gt;&lt;/PRE&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;BR&gt;A resource file can in turn merge other resource files: &lt;BR&gt;&lt;BR&gt;&lt;BR&gt;&lt;/P&gt;
&lt;DIV&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&amp;lt;ResourceDictionary
    xmlns=&lt;SPAN style="COLOR: #006080"&gt;"http://schemas.microsoft.com/winfx/2006/xaml/presentation"&lt;/SPAN&gt;
    xmlns:x=&lt;SPAN style="COLOR: #006080"&gt;"http://schemas.microsoft.com/winfx/2006/xaml"&lt;/SPAN&gt;&amp;gt;

    &amp;lt;ResourceDictionary.MergedDictionaries&amp;gt;
        &amp;lt;ResourceDictionary Source=&lt;SPAN style="COLOR: #006080"&gt;"ResourceB.xaml"&lt;/SPAN&gt;/&amp;gt;
    &amp;lt;/ResourceDictionary.MergedDictionaries&amp;gt;
    
    &amp;lt;Style x:Name=&lt;SPAN style="COLOR: #006080"&gt;"MyButtonStyle"&lt;/SPAN&gt; TargetType=&lt;SPAN style="COLOR: #006080"&gt;"Button"&lt;/SPAN&gt;&amp;gt;
        &amp;lt;Setter Property=&lt;SPAN style="COLOR: #006080"&gt;"Background"&lt;/SPAN&gt; Value=&lt;SPAN style="COLOR: #006080"&gt;"red"&lt;/SPAN&gt;/&amp;gt;
    &amp;lt;/Style&amp;gt;

&amp;lt;/ResourceDictionary&amp;gt;&lt;/PRE&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;BR&gt;Now I only want to see a way to skip adding the Style attribute to a control, and instead only use the TargetType attribute on a style, and all types should use that style: &lt;BR&gt;&lt;BR&gt;&lt;BR&gt;&lt;/P&gt;
&lt;DIV&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&amp;lt;Style TargetType=&lt;SPAN style="COLOR: #006080"&gt;"Button"&lt;/SPAN&gt;&amp;gt;
    &amp;lt;Setter Property=&lt;SPAN style="COLOR: #006080"&gt;"Background"&lt;/SPAN&gt; Value=&lt;SPAN style="COLOR: #006080"&gt;"red"&lt;/SPAN&gt;/&amp;gt;
&amp;lt;/Style&amp;gt;&lt;/PRE&gt;&lt;/DIV&gt;
&lt;P&gt;Wouldn’t that be something?&lt;/P&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7016533" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/fredriknormen/archive/tags/Resources/default.aspx">Resources</category><category domain="http://weblogs.asp.net/fredriknormen/archive/tags/Silverlight+3.0/default.aspx">Silverlight 3.0</category><category domain="http://weblogs.asp.net/fredriknormen/archive/tags/Styles/default.aspx">Styles</category></item><item><title>I’m going to talk about Silverlight 3.0 and .Net RIA Services</title><link>http://weblogs.asp.net/fredriknormen/archive/2009/03/31/i-m-going-to-talk-about-silverlight-3-0-and-net-ria-services.aspx</link><pubDate>Tue, 31 Mar 2009 04:45:30 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7014089</guid><dc:creator>Fredrik N</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/fredriknormen/rsscomments.aspx?PostID=7014089</wfw:commentRss><comments>http://weblogs.asp.net/fredriknormen/archive/2009/03/31/i-m-going-to-talk-about-silverlight-3-0-and-net-ria-services.aspx#comments</comments><description>&lt;p&gt;For my Swedish readers. If you are interested to see some of the new features in Silverlight 3.0 and also the .Net RIA Services and out-of-‘browser feature, I’m going to talk about it on &lt;a href="http://www.cornerstone.se/sv/ExpertZone/developersummit/2009/"&gt;Developer Summit&lt;/a&gt; in Stockholm 15-16 April. I’m responsible for the Web track and there are be sessions about ASP.Net 4.0 AJAX, Dynamic Data, Building Web sites with Entity Framework etc. You can find more about the web sessions here: &lt;a title="http://www.cornerstone.se/sv/ExpertZone/developersummit/2009/Startsida/Webb/" href="http://www.cornerstone.se/sv/ExpertZone/developersummit/2009/Startsida/Webb/"&gt;http://www.cornerstone.se/sv/ExpertZone/developersummit/2009/Startsida/Webb/&lt;/a&gt;&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7014089" width="1" height="1"&gt;</description></item><item><title>Some features I would like to see in the ASP.Net “vNext”</title><link>http://weblogs.asp.net/fredriknormen/archive/2009/03/26/some-features-i-would-like-to-see-in-the-asp-net-vnext.aspx</link><pubDate>Thu, 26 Mar 2009 08:31:29 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7003194</guid><dc:creator>Fredrik N</dc:creator><slash:comments>3</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/fredriknormen/rsscomments.aspx?PostID=7003194</wfw:commentRss><comments>http://weblogs.asp.net/fredriknormen/archive/2009/03/26/some-features-i-would-like-to-see-in-the-asp-net-vnext.aspx#comments</comments><description>&lt;p&gt;I would also like to see a template for the MVP pattern.&lt;/p&gt;  &lt;p&gt;There are so many apps using Web Forms, and most people I have talked to want to update the apps to use the MVC, which is not easy at all.. they want to do it to make it easier to write tests. By having a MVP for Web Forms, it will be easier for them to upgrade their apps and make it possible to write unit test etc.&lt;/p&gt;  &lt;p&gt;I want the Cache object to use providers, so it's possible to use it with a distributed cache (for example Velocity) to enable it for Web Farms. Many developers are using the Session now to cache stuff in a Web Farm environment, but the Cache object is more powerful, but it stores the info InProc.&lt;/p&gt;  &lt;p&gt;I want to make it possible on a TextBox level to turn off &amp;quot;HTML Validation&amp;quot; (ValidationRequest), not for the whole page.&lt;/p&gt;  &lt;p&gt;Add a size limitation for the Session as default, several developers are adding Search results to the Session. I think it should be great with a limitation so developers need to increase the size of the Session object. That will probably make them rethink, and reduce the use of Sessions.&lt;/p&gt;  &lt;p&gt;I want to see the runat=&amp;quot;server&amp;quot; attribute removed from controls. &lt;/p&gt;  &lt;p&gt;Add support for custom tags, where a tag is bound to a specific class, for example:&lt;/p&gt;  &lt;p&gt;&amp;lt;my:CustomTag DataSource=&amp;quot;&amp;lt;%= Model %&amp;gt;&amp;quot;/&amp;gt;&lt;/p&gt;  &lt;p&gt;By letting us to add/create custom tags, we could easily create controls for the ASP.Net MVC Views and a custom tag solution can solve more than just creating controls.&lt;/p&gt;  &lt;p&gt;Add better chrome support for WebParts, for example using templates. I created a solution for it a long time ago on my old blog: &lt;a href="http://fredrik.nsquared2.com/viewpost.aspx?PostID=248"&gt;http://fredrik.nsquared2.com/viewpost.aspx?PostID=248&lt;/a&gt;, I think it will make several SharePoint WebParts developers happy ;)&lt;/p&gt;  &lt;p&gt;What would you like to see in the next version of ASP.Net?&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7003194" width="1" height="1"&gt;</description></item><item><title>How to create a simple ObjectDataSource Control for Silverlight 3.0 and use Element Binding.</title><link>http://weblogs.asp.net/fredriknormen/archive/2009/03/21/how-to-create-a-simple-objectdatasource-control-for-silverlight-3-0-and-use-element-binding.aspx</link><pubDate>Sat, 21 Mar 2009 09:08:13 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6984787</guid><dc:creator>Fredrik N</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/fredriknormen/rsscomments.aspx?PostID=6984787</wfw:commentRss><comments>http://weblogs.asp.net/fredriknormen/archive/2009/03/21/how-to-create-a-simple-objectdatasource-control-for-silverlight-3-0-and-use-element-binding.aspx#comments</comments><description>&lt;p&gt;While I was sitting here a Saturday morning and was thinking about what to do, I decided to simply create a light weight ObjectDataSource for fun, only to have a blog post to write ;)&lt;/p&gt;  &lt;p&gt;As you may now the every XAML element are objects, so it’s easy to add extra controls and functionality to XAML. Here is a simple example of a ObjectDataSource control with only one feature, to call a single method and populate a DataGrid control:   &lt;br /&gt;&lt;/p&gt;  &lt;div&gt;   &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&amp;lt;data:DataGrid ItemsSource=&lt;span style="color: #006080"&gt;&amp;quot;{Binding Data, ElementName=dds}&amp;quot;&lt;/span&gt; &amp;gt;&amp;lt;/data:DataGrid&amp;gt;
        
&amp;lt;ds:ObjectDataSource x:Name=&lt;span style="color: #006080"&gt;&amp;quot;dds&amp;quot;&lt;/span&gt; LoadMethodName=&lt;span style="color: #006080"&gt;&amp;quot;GetStrings&amp;quot;&lt;/span&gt;&amp;gt;
   &amp;lt;ds:ObjectDataSource.SourceObject&amp;gt;
      &amp;lt;o:MyObject/&amp;gt;
   &amp;lt;/ds:ObjectDataSource.SourceObject&amp;gt;
&amp;lt;/ds:ObjectDataSource&amp;gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;
  &lt;br /&gt;Silverlight 3.0 supports Element Binding, so I bind the Data property of my ObjectDataSource to the DataGrid’s ItemSource. The ObjectDataSource has two properties, LoadMethodName, to specify the method to get the data that should be added to the DataGrid. The SourceObject takes an object of any kind, and in this case it’s the object that has the specified LoadMethodName:

  &lt;br /&gt;&lt;/p&gt;

&lt;div&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; MyObject
{
   &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; IEnumerable&amp;lt;&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;&amp;gt; GetStrings()
   {
      &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; List&amp;lt;String&amp;gt;() { &lt;span style="color: #006080"&gt;&amp;quot;test&amp;quot;&lt;/span&gt;, &lt;span style="color: #006080"&gt;&amp;quot;test1&amp;quot;&lt;/span&gt;, &lt;span style="color: #006080"&gt;&amp;quot;test2&amp;quot;&lt;/span&gt; };
   }
}&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;The implementation of the ObjectDataSource is kind of simple, it only make sure to invoke the LoadMethodName when the SourceObject property is set to the ObjectDataSource:
  &lt;br /&gt;&lt;/p&gt;

&lt;div&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; ObjectDataSource : Control, INotifyPropertyChanged
{
    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;event&lt;/span&gt; PropertyChangedEventHandler PropertyChanged;

    &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;object&lt;/span&gt; _sourceObject;
    &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;object&lt;/span&gt; _data;

    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;object&lt;/span&gt; SourceObject
    {
       get { &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; _sourceObject; }
       set
       {
            &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;._sourceObject = &lt;span style="color: #0000ff"&gt;value&lt;/span&gt;;
            &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.Data = &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;._sourceObject.GetType().InvokeMember(
                                  LoadMethodName, 
                                  System.Reflection.BindingFlags.InvokeMethod, 
                                  &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;, 
                                  &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;._sourceObject, 
                                   &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;);
       }
    }

       
    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; LoadMethodName { set; get; }


    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;object&lt;/span&gt; Data
    {
       get { &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;._data; }
       set
       {
           &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;._data = &lt;span style="color: #0000ff"&gt;value&lt;/span&gt;;
           RaisePropertyChanged(&lt;span style="color: #006080"&gt;&amp;quot;Data&amp;quot;&lt;/span&gt;);
       }
    }


    &lt;span style="color: #0000ff"&gt;protected&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; RaisePropertyChanged(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; propertyName)
    {
       var propertyChanged = &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.PropertyChanged;

       &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (propertyChanged != &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;)
           propertyChanged(&lt;span style="color: #0000ff"&gt;this&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; PropertyChangedEventArgs(propertyName));
    }
}&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;This ObjectDataSource is not a sophisticated one, as you may see, and very simple implemented, and doesn’t even do an asynchronous call.&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6984787" width="1" height="1"&gt;</description></item><item><title>HTML is so 1990</title><link>http://weblogs.asp.net/fredriknormen/archive/2009/03/20/html-is-so-1990.aspx</link><pubDate>Fri, 20 Mar 2009 20:40:28 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6982298</guid><dc:creator>Fredrik N</dc:creator><slash:comments>11</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/fredriknormen/rsscomments.aspx?PostID=6982298</wfw:commentRss><comments>http://weblogs.asp.net/fredriknormen/archive/2009/03/20/html-is-so-1990.aspx#comments</comments><description>&lt;p&gt;Yesterday I was on a meeting with some people from Microsoft and other companies working with social media and communication etc. We talked about the future of the web. I have developed web applications since 1995 or something like that and I’m so tired of is HTML, CSS and client-side script. During the last years people have done incredible web application with technology like AJAX to increase user experience. But HTML, Client-side script and the Browser we are using have limitations, it takes time to build application with rich and good user experience, some stuff are impossible to do because of a limitation both in the HTML, CSS, Client-side script and browser to create Rich Internet Applications. We need a new solutions, a new better way to build applications, and we have two “tools” we can use today to create richer web/internet applications, Flash and Silverlight.&lt;/p&gt;  &lt;p&gt;More and more applications are moving to the web and more and more need better user experience. For me the Internet Browsers are moving far far away from me, I start to use more richer client-side tools. For example Messenger, TweetDeck, LiveWriter, Blog readers, RSS readers etc. I don’t use the Browser as much as I did before, for example I don’t use the Browser to write my blog post or publish pictures to the cloud, I use richer applications. Now when Silverlight 3.0 can run out-of-browser, and the increasing demands on richer clients and also the need to create better user experience I think we need to start moving forward. The Browser and HTML will still exists in the near future, but I think it’s time for web developers to take the next step toward RIA.&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6982298" width="1" height="1"&gt;</description></item><item><title>on Twitter</title><link>http://weblogs.asp.net/fredriknormen/archive/2009/03/20/on-twitter.aspx</link><pubDate>Fri, 20 Mar 2009 08:00:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6981132</guid><dc:creator>Fredrik N</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/fredriknormen/rsscomments.aspx?PostID=6981132</wfw:commentRss><comments>http://weblogs.asp.net/fredriknormen/archive/2009/03/20/on-twitter.aspx#comments</comments><description>&lt;P mce_keep="true"&gt;For some month ago I just created a Twitter account, and suddenly some poeple found me.. I didn't told anyone that I was on Twitter because I didn't know if I'm going to use it. But now when I got some fre followers I suddenly had to write something ;)&lt;/P&gt;
&lt;P mce_keep="true"&gt;So if you like to read my short and probably meaningless messages on twitter, you can find me @ http://twitter.com/fredrikn&lt;/P&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6981132" width="1" height="1"&gt;</description></item><item><title>Change IE8 to IE7 compatible mode with meta tags</title><link>http://weblogs.asp.net/fredriknormen/archive/2009/03/19/change-ie8-to-ie7-compatible-mode-with-meta-tags.aspx</link><pubDate>Thu, 19 Mar 2009 13:25:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6979292</guid><dc:creator>Fredrik N</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/fredriknormen/rsscomments.aspx?PostID=6979292</wfw:commentRss><comments>http://weblogs.asp.net/fredriknormen/archive/2009/03/19/change-ie8-to-ie7-compatible-mode-with-meta-tags.aspx#comments</comments><description>&lt;P mce_keep="true"&gt;I got some questions regarding how to make sure IE8 will run in IE7 mode by default when visiting a site without changing the IE8 options.&lt;/P&gt;
&lt;P mce_keep="true"&gt;There is a meta tag which can be used to force IE8 to "display" a site in IE7 mode:&lt;/P&gt;
&lt;DIV class=example&gt;Turn the mode to IE7:&lt;/DIV&gt;
&lt;DIV class=example&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class=example&gt;&lt;STRONG&gt;&amp;lt;meta http-equiv="X-UA-Compatible" content="IE=7"&amp;gt;&lt;/STRONG&gt; &lt;/DIV&gt;
&lt;DIV class=example&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class=example&gt;Make sure IE8 emulate IE7:&lt;/DIV&gt;
&lt;DIV class=example&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class=example&gt;&lt;SPAN class=example&gt;&lt;STRONG&gt;&amp;lt;meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7"/&amp;gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6979292" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/fredriknormen/archive/tags/IE8/default.aspx">IE8</category><category domain="http://weblogs.asp.net/fredriknormen/archive/tags/HTML/default.aspx">HTML</category></item><item><title>How the Presentation Model could look like when using Silverlight 2.0 (Part 6)</title><link>http://weblogs.asp.net/fredriknormen/archive/2009/03/11/how-the-presentation-model-could-look-like-when-using-silverlight-2-0-part-6.aspx</link><pubDate>Wed, 11 Mar 2009 08:28:25 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6953443</guid><dc:creator>Fredrik N</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/fredriknormen/rsscomments.aspx?PostID=6953443</wfw:commentRss><comments>http://weblogs.asp.net/fredriknormen/archive/2009/03/11/how-the-presentation-model-could-look-like-when-using-silverlight-2-0-part-6.aspx#comments</comments><description>&lt;p&gt;This post is not really a follow-up, it’s more like an announcements and for my Swedish readers.&lt;/p&gt;  &lt;p&gt;I’m going to talk about how to implement different UI Patterns when using Silverlight as a client on a Swedish conference called Developer Summit, which is a conference for developers and architects etc. I’m the Web track owner at the conference. If you are interested to see more about how to implement UI Patterns within Silverlight, you should come and listen to me ;)&lt;/p&gt;  &lt;p&gt;Here is a link to the Conference and also the time when it will take place: &lt;a title="http://www.cornerstone.se/sv/ExpertZone/developersummit/" href="http://www.cornerstone.se/sv/ExpertZone/developersummit/"&gt;http://www.cornerstone.se/sv/ExpertZone/developersummit/&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Hope to see some of you there.&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6953443" width="1" height="1"&gt;</description></item><item><title>MasterPage and Silverlight</title><link>http://weblogs.asp.net/fredriknormen/archive/2009/03/08/masterpage-and-silverlight.aspx</link><pubDate>Sun, 08 Mar 2009 08:27:15 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6946762</guid><dc:creator>Fredrik N</dc:creator><slash:comments>12</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/fredriknormen/rsscomments.aspx?PostID=6946762</wfw:commentRss><comments>http://weblogs.asp.net/fredriknormen/archive/2009/03/08/masterpage-and-silverlight.aspx#comments</comments><description>&lt;p&gt;I have seen several post about how to implement MasterPage in Silverlight 2.0, most of the posts are about using “fixed” UserControls and dynamically change the content of a control in code-behind. Here is another solution where a Template will be used instead.&lt;/p&gt;  &lt;p&gt;In Silverlight we can use the ContentControl to add a child element to it:   &lt;br /&gt;&lt;/p&gt;  &lt;div&gt;   &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&amp;lt;ContentControl&amp;gt;
            
   &amp;lt;Button Content=&lt;span style="color: #006080"&gt;&amp;quot;test&amp;quot;&lt;/span&gt;&amp;gt;&amp;lt;/Button&amp;gt;
            
&amp;lt;/ContentControl&amp;gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;
  &lt;br /&gt;The ContentControl has a Template property we can use to specify the Template of the ContentControl. To create a template we can for example use the &amp;lt;Style&amp;gt; element within the App.xaml (Only to make it global).

  &lt;br /&gt;&lt;/p&gt;

&lt;div&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&amp;lt;Application.Resources&amp;gt;
       
       &amp;lt;Style x:Name=&lt;span style="color: #006080"&gt;&amp;quot;myMasterPage&amp;quot;&lt;/span&gt; TargetType=&lt;span style="color: #006080"&gt;&amp;quot;ContentControl&amp;quot;&lt;/span&gt;&amp;gt;
           &amp;lt;Style.Setters&amp;gt;
               &amp;lt;Setter Property=&lt;span style="color: #006080"&gt;&amp;quot;Template&amp;quot;&lt;/span&gt;&amp;gt;
                   &amp;lt;Setter.Value&amp;gt;
                       &amp;lt;ControlTemplate TargetType=&lt;span style="color: #006080"&gt;&amp;quot;ContentControl&amp;quot;&lt;/span&gt;&amp;gt;
                           &amp;lt;Grid Height=&lt;span style="color: #006080"&gt;&amp;quot;300&amp;quot;&lt;/span&gt; Width=&lt;span style="color: #006080"&gt;&amp;quot;400&amp;quot;&lt;/span&gt;&amp;gt;
                               
                               &amp;lt;Grid.RowDefinitions&amp;gt;
                                   &amp;lt;RowDefinition Height=&lt;span style="color: #006080"&gt;&amp;quot;55&amp;quot;&lt;/span&gt;/&amp;gt;
                                   &amp;lt;RowDefinition Height=&lt;span style="color: #006080"&gt;&amp;quot;*&amp;quot;&lt;/span&gt;/&amp;gt;
                                   &amp;lt;RowDefinition Height=&lt;span style="color: #006080"&gt;&amp;quot;25&amp;quot;&lt;/span&gt;/&amp;gt;
                               &amp;lt;/Grid.RowDefinitions&amp;gt;
                              
                               &amp;lt;Grid Grid.Row=&lt;span style="color: #006080"&gt;&amp;quot;1&amp;quot;&lt;/span&gt;&amp;gt;
                                   &amp;lt;Grid.ColumnDefinitions&amp;gt;
                                       &amp;lt;ColumnDefinition Width=&lt;span style="color: #006080"&gt;&amp;quot;0.5*&amp;quot;&lt;/span&gt;/&amp;gt;
                                       &amp;lt;ColumnDefinition Width=&lt;span style="color: #006080"&gt;&amp;quot;*&amp;quot;&lt;/span&gt;/&amp;gt;
                                   &amp;lt;/Grid.ColumnDefinitions&amp;gt;

                                   &amp;lt;StackPanel Grid.Column=&lt;span style="color: #006080"&gt;&amp;quot;0&amp;quot;&lt;/span&gt;&amp;gt;
                                       &amp;lt;Button Content=&lt;span style="color: #006080"&gt;&amp;quot;Button 1&amp;quot;&lt;/span&gt; Click=&lt;span style="color: #006080"&gt;&amp;quot;Button_Click&amp;quot;&lt;/span&gt;&amp;gt;&amp;lt;/Button&amp;gt;
                                       &amp;lt;Button Content=&lt;span style="color: #006080"&gt;&amp;quot;Button 2&amp;quot;&lt;/span&gt; Click=&lt;span style="color: #006080"&gt;&amp;quot;Button_Click_1&amp;quot;&lt;/span&gt;&amp;gt;&amp;lt;/Button&amp;gt;
                                       &amp;lt;Button Content=&lt;span style="color: #006080"&gt;&amp;quot;Button 3&amp;quot;&lt;/span&gt; Click=&lt;span style="color: #006080"&gt;&amp;quot;Button_Click_2&amp;quot;&lt;/span&gt;&amp;gt;&amp;lt;/Button&amp;gt;
                                   &amp;lt;/StackPanel&amp;gt;

                                   &amp;lt;ContentPresenter Grid.Column=&lt;span style="color: #006080"&gt;&amp;quot;1&amp;quot;&lt;/span&gt; Content=&lt;span style="color: #006080"&gt;&amp;quot;{TemplateBinding Content}&amp;quot;&lt;/span&gt;&amp;gt;&amp;lt;/ContentPresenter&amp;gt;

                               &amp;lt;/Grid&amp;gt;
                               
                           &amp;lt;/Grid&amp;gt;
                           
                       &amp;lt;/ControlTemplate&amp;gt;
                       
                   &amp;lt;/Setter.Value&amp;gt;
                   
               &amp;lt;/Setter&amp;gt;
           &amp;lt;/Style.Setters&amp;gt;
       &amp;lt;/Style&amp;gt;
       
   &amp;lt;/Application.Resources&amp;gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;
  &lt;br /&gt;The Style will target the ContentControl and also set the Template property of the ContentControl. The Template property will have a child element of type ControlTemplate which can be used to define a template. We will use the &amp;lt;Style&amp;gt; and &amp;lt;ControlTemaplate&amp;gt; to define our MasterPage. The &amp;lt;ContentPresenter&amp;gt; can be used in a similar way as &amp;lt;ContentPlaceholder&amp;gt; is used within a ASP.Net MasterPage. The Content of the &amp;lt;ContentPresenter&amp;gt; will be the Content from the &amp;lt;ContentControl&amp;gt; which will use the “myMasterPage” template.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Note: If we add an event to the template, it will be added to the App’s code-behind.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To use the “myMasterPage” template in our Page.xaml we simply add a &amp;lt;ContentControl&amp;gt; and set it's Style property to the “myMasterPage´” style:
  &lt;br /&gt;&lt;/p&gt;

&lt;div&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&amp;lt;UserControl x:Class=&lt;span style="color: #006080"&gt;&amp;quot;SilverlightApplication1.Page&amp;quot;&lt;/span&gt;
    xmlns=&lt;span style="color: #006080"&gt;&amp;quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&amp;quot;&lt;/span&gt; 
    xmlns:x=&lt;span style="color: #006080"&gt;&amp;quot;http://schemas.microsoft.com/winfx/2006/xaml&amp;quot;&lt;/span&gt; 
    Width=&lt;span style="color: #006080"&gt;&amp;quot;400&amp;quot;&lt;/span&gt; Height=&lt;span style="color: #006080"&gt;&amp;quot;300&amp;quot;&lt;/span&gt;&amp;gt;
    &amp;lt;ContentControl Style=&lt;span style="color: #006080"&gt;&amp;quot;{StaticResource myMasterPage}&amp;quot;&lt;/span&gt;&amp;gt;
          
        &amp;lt;Button Content=&lt;span style="color: #006080"&gt;&amp;quot;test&amp;quot;&lt;/span&gt;&amp;gt;&amp;lt;/Button&amp;gt;
            
    &amp;lt;/ContentControl&amp;gt;
&lt;br /&gt;&amp;lt;/UserControl&amp;gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;
  &lt;br /&gt;The content of the ContentControl, will now be located where the ContentPresenter is in the “myMasterpage” template.&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6946762" width="1" height="1"&gt;</description></item><item><title>How the Presentation Model could look like when using Silverlight 2.0 (Part 5)</title><link>http://weblogs.asp.net/fredriknormen/archive/2009/02/25/how-the-presentation-model-could-look-like-when-using-silverlight-2-0-part-5.aspx</link><pubDate>Wed, 25 Feb 2009 13:53:11 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6925948</guid><dc:creator>Fredrik N</dc:creator><slash:comments>7</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/fredriknormen/rsscomments.aspx?PostID=6925948</wfw:commentRss><comments>http://weblogs.asp.net/fredriknormen/archive/2009/02/25/how-the-presentation-model-could-look-like-when-using-silverlight-2-0-part-5.aspx#comments</comments><description>&lt;p&gt;Maybe the title of my blog post are not the best one now when I write about my little Presentation Model framework for Silverlight.&lt;/p&gt;  &lt;p&gt;To day I notice some problems when it comes to switching views and also play movies and animations etc. For example to start playing a movie we need to call the MediaElement’s Play method. With my Framework we can only execute a Action method located in our Presentation Model, and I don’t want to pass a FrameworkElement as an argument to the Presentation Model, so there was no way to make sure an Action method can start playing a movie. So to solve this I created a specific class with the name ActionResult, this ActionResult class:   &lt;br /&gt;&lt;/p&gt;  &lt;div&gt;   &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; ActionResult
{
    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; ActionResult()
    {
       &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.ActionResultHandler = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; DefaultActionResultHandler();
    }

    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; IActionResultHandler ActionResultHandler { get; &lt;span style="color: #0000ff"&gt;protected&lt;/span&gt; set; }
}&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;
  &lt;br /&gt;Action methods can then return a ActionResult:

  &lt;br /&gt;&lt;/p&gt;

&lt;div&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; CustomerPresentationModel : Silverlight.Extension.PresentationModel
{
       &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; ActionResult Show(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; customerId)
       {
           &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; ChangeView(&lt;span style="color: #006080"&gt;&amp;quot;About.About&amp;quot;&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;base&lt;/span&gt;.PreviousUsetState);
       }

       &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; ActionResult PlayMovie()
       {
           &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; MovieActionResult(&lt;span style="color: #0000ff"&gt;null&lt;/span&gt;, MovieAction.Play);
       }
}&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;
  &lt;br /&gt;If an ActionResult is returned from a Action method, I will use the ActionResult’s ActionResultHandler and invoke the HandleActionResult method, where I pass the FrameworkElement that trigged the Action method and also pass the ActionResult class as an argument:

  &lt;br /&gt;&lt;/p&gt;

&lt;div&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;interface&lt;/span&gt; IActionResultHandler
{
    &lt;span style="color: #0000ff"&gt;bool&lt;/span&gt; HandleActionResult(FrameworkElement sourceElement, ActionResult returnValue);
}&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;
  &lt;br /&gt;To make sure I can start playing a movie from the Action method, I will pass a MovieActionResult, which will use a MoveActionResultHandler to handle the ActionResult and start playing the movie:

  &lt;br /&gt;&lt;/p&gt;

&lt;div&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; MovieActionResult : ActionResult
{
     &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; MovieActionResult(Stream mediaSource, MovieAction movieAction)
     {
        &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.MovieAction = movieAction;
        &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.MediaSource = mediaSource;
        &lt;span style="color: #0000ff"&gt;base&lt;/span&gt;.ActionResultHandler = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; MovieActionResultHandler();
     }

     &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; MovieAction MovieAction { get; &lt;span style="color: #0000ff"&gt;internal&lt;/span&gt; set; }

     &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; Stream MediaSource { get; &lt;span style="color: #0000ff"&gt;internal&lt;/span&gt; set; }
}&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;div&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; MovieActionResultHandler : IActionResultHandler
{
    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;bool&lt;/span&gt; HandleActionResult(FrameworkElement sourceElement, ActionResult returnValue)
    {
        var mediaElement = sourceElement &lt;span style="color: #0000ff"&gt;as&lt;/span&gt; MediaElement;

        &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (mediaElement == &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;)
           &lt;span style="color: #0000ff"&gt;throw&lt;/span&gt; &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Exception(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;.Format(&lt;span style="color: #006080"&gt;&amp;quot;The sourceElement ({0},{1}) for the MovieActionResultHandler is not of type MediaElement&amp;quot;&lt;/span&gt;, sourceElement.Name, sourceElement.GetType().Name));

        var actionResult = returnValue &lt;span style="color: #0000ff"&gt;as&lt;/span&gt; MovieActionResult;

        &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (actionResult == &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;)
           &lt;span style="color: #0000ff"&gt;throw&lt;/span&gt; &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Exception(&lt;span style="color: #006080"&gt;&amp;quot;The returnValue agrument is not of type MovieActionResult&amp;quot;&lt;/span&gt;);

        &lt;span style="color: #0000ff"&gt;switch&lt;/span&gt; (actionResult.MovieAction)
        {
            &lt;span style="color: #0000ff"&gt;case&lt;/span&gt; MovieAction.Play:
                 mediaElement.Play();
                 &lt;span style="color: #0000ff"&gt;break&lt;/span&gt;;
            &lt;span style="color: #0000ff"&gt;case&lt;/span&gt; MovieAction.Pause:
                 mediaElement.Pause();
                 &lt;span style="color: #0000ff"&gt;break&lt;/span&gt;;
            &lt;span style="color: #0000ff"&gt;case&lt;/span&gt; MovieAction.Resume:
                 mediaElement.Play();
                 &lt;span style="color: #0000ff"&gt;break&lt;/span&gt;;
            &lt;span style="color: #0000ff"&gt;case&lt;/span&gt; MovieAction.Stop:
                 mediaElement.Stop();
                 &lt;span style="color: #0000ff"&gt;break&lt;/span&gt;;
            &lt;span style="color: #0000ff"&gt;default&lt;/span&gt;:
                &lt;span style="color: #0000ff"&gt;throw&lt;/span&gt; &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Exception(&lt;span style="color: #006080"&gt;&amp;quot;Can't handle MovieAction&amp;quot;&lt;/span&gt;);
        }
        &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; &lt;span style="color: #0000ff"&gt;true&lt;/span&gt;;
    }
}&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;
  &lt;br /&gt;The MovieResultHandler can now interact with the FrameworkElement that trigged the Action method.&lt;/p&gt;

&lt;p&gt;So to play a movie when the MouseLeftButtonUp is trigged we can simply write:
  &lt;br /&gt;&lt;/p&gt;

&lt;div&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&amp;lt;MediaElement e:Attach.MouseLeftButtonUp=&lt;span style="color: #006080"&gt;&amp;quot;PlayMovie&amp;quot;&lt;/span&gt; AutoPlay=&lt;span style="color: #006080"&gt;&amp;quot;False&amp;quot;&lt;/span&gt; Source=&lt;span style="color: #006080"&gt;&amp;quot;http://localhost:4317/movie.wmv&amp;quot;&lt;/span&gt; Height=&lt;span style="color: #006080"&gt;&amp;quot;200&amp;quot;&lt;/span&gt; Width=&lt;span style="color: #006080"&gt;&amp;quot;200&amp;quot;&lt;/span&gt;/&amp;gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;I have also added a ActionResult called DynamicChangeViewActionResult and a handler for it. By using this ActionResult we can dynamically specify a View and make sure our Silverlight applicaiton switches view after an Action method is executed:
  &lt;br /&gt;&lt;/p&gt;

&lt;div&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; ActionResult Show(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; customerId)
{
    &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; ChangeView(&lt;span style="color: #006080"&gt;&amp;quot;About&amp;quot;&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;customerId&lt;/span&gt;);
}&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;
  &lt;br /&gt;The ChangeView is a method added to the base class PresentationModel which can be used to get some helper method, but aren’t needed. The ChangeView will return a DynamicChangeViewActionResult, and will get the About.xaml page and automatically replace the content of the “LayoutRoot” element with the new View. So my Framework can sort of also use the MVC pattern. By passing object as a second argument to the ChangeView, we can pass additional information to the next View’s Presentation Model’s Action methods. We can also specify a name of a ContentControl or Panel located on our View, and the make sure only a part of the View is updated with a new UserControl instead of the whole view.

  &lt;br /&gt;&lt;/p&gt;

&lt;div&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; ActionResult Show(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; customerId)
{
   &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; ChangeView(&lt;span style="color: #006080"&gt;&amp;quot;About&amp;quot;&lt;/span&gt;, &lt;span style="color: #006080"&gt;&amp;quot;MyPanelToUpdate&amp;quot;&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;customerId&lt;/span&gt;);
}&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;
  &lt;br /&gt;So the basic ideas of using the ActionResult feature is only to make sure others can return their own ActionResult and handle the result of the Action method, for example to play an animation, or change an image or what ever.&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6925948" width="1" height="1"&gt;</description></item><item><title>How the Presentation Model could look like when using Silverlight 2.0 (Part 4)</title><link>http://weblogs.asp.net/fredriknormen/archive/2009/02/24/how-the-presentation-model-could-look-like-when-using-silverlight-2-0-part-4.aspx</link><pubDate>Tue, 24 Feb 2009 15:40:48 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6925068</guid><dc:creator>Fredrik N</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/fredriknormen/rsscomments.aspx?PostID=6925068</wfw:commentRss><comments>http://weblogs.asp.net/fredriknormen/archive/2009/02/24/how-the-presentation-model-could-look-like-when-using-silverlight-2-0-part-4.aspx#comments</comments><description>&lt;p&gt;I have created a small framework only for fun and to have a programming task ;) The framework I have created (not yet 100% completed) is similar to Prism, Caliburn and Silverlight.FX. So this is not a framework that should replace those other framework, it still only a hobby project to see if I managed to create a similar one. I will still write about it in this Part 4 of my Presentation Model series. The goal with the framework is to leave the code-behind alone and focus on a separate class and declare everything in the XAML. The following is an example of a class (a Presentation Model):   &lt;br /&gt;&lt;/p&gt;  &lt;div&gt;   &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; LoginPresentationModel : Silverlight.Extension.Model
{
       &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; _userName;

       &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; UserName
       {
           get { &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; _userName; }
           set
           {
               _userName = &lt;span style="color: #0000ff"&gt;value&lt;/span&gt;;
               &lt;span style="color: #0000ff"&gt;base&lt;/span&gt;.NotifyPropertyChanged(&lt;span style="color: #006080"&gt;&amp;quot;UserName&amp;quot;&lt;/span&gt;);
           }
       }
       
       &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; Login(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; userName, &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; password)
       {
           &lt;span style="color: #008000"&gt;//Do some validation&lt;/span&gt;
           &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.UserName = userName;
       }
}&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Note: The Model doesn't need to Inherit from the Model base class, I only do it because I have added the NotifyPropertyChanged method to the base class.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The code-behind for my Page.XAML will look like this:
  &lt;br /&gt;&lt;/p&gt;

&lt;div&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;partial&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; Page : UserControl
{
      &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; Page()
      {
          InitializeComponent();
      }
}&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Note: I hope Silverlight team will add the InitializeComponents to the page.g.cs file so we can remove the Code-behind.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To use the LoginPresentaitonModel in my View (XAML file) we can use an Attached property added to any FrameworkElement’s called View.Model:
  &lt;br /&gt;&lt;/p&gt;

&lt;div&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&amp;lt;UserControl x:Class=&lt;span style="color: #006080"&gt;&amp;quot;PresentationModelExample1.Page&amp;quot; &lt;/span&gt;xmlns..&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; xmlns:e=&lt;span style="color: #006080"&gt;&amp;quot;clr-namespace:Silverlight.Extension;assembly=Silverlight.Extension&amp;quot;&lt;/span&gt;
    xmlns:m=&lt;span style="color: #006080"&gt;&amp;quot;clr-namespace:PresentationModelExample1.Model&amp;quot;&lt;/span&gt;
    Width=&lt;span style="color: #006080"&gt;&amp;quot;400&amp;quot;&lt;/span&gt; Height=&lt;span style="color: #006080"&gt;&amp;quot;350&amp;quot;&lt;/span&gt;&amp;gt;
    &amp;lt;e:View.Model&amp;gt;
        &amp;lt;m:LoginPresentationModel/&amp;gt;
    &amp;lt;/e:View.Model&amp;gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Note: Because the View.Model can be used on any FramewrokElement, we can partially add different Presentation Model to the&amp;#160; VIew, but I recommend to only use one per View.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;
  &lt;br /&gt;The LoginPresentationModel class will be bound to the UserControl’s DataContext property, to we can now simply use normal data binding to bind FrameworkElements to the Presentation Model’s properties:

  &lt;br /&gt;&lt;/p&gt;

&lt;div&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&amp;lt;Grid x:Name=&lt;span style="color: #006080"&gt;&amp;quot;LayoutRoot&amp;quot;&lt;/span&gt; Background=&lt;span style="color: #006080"&gt;&amp;quot;White&amp;quot;&lt;/span&gt;&amp;gt;
       &amp;lt;StackPanel Margin=&lt;span style="color: #006080"&gt;&amp;quot;50&amp;quot;&lt;/span&gt;&amp;gt;

           &amp;lt;TextBox x:Name=&lt;span style="color: #006080"&gt;&amp;quot;userName&amp;quot;&lt;/span&gt; Text=&lt;span style="color: #006080"&gt;&amp;quot;{Binding UserName}&amp;quot;&lt;/span&gt;/&amp;gt;

           &amp;lt;Password x:Name=&lt;span style="color: #006080"&gt;&amp;quot;password&amp;quot;&lt;/span&gt;/&amp;gt;

           &amp;lt;Button e:Attach.Click=&lt;span style="color: #006080"&gt;&amp;quot;Login&amp;quot;&lt;/span&gt; Content=&lt;span style="color: #006080"&gt;&amp;quot;Login&amp;quot;&lt;/span&gt;/&amp;gt;
      &amp;lt;/StackPanel&amp;gt;
&amp;lt;/Grid&amp;gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;
  &lt;br /&gt;The code above will bind the UserName property of the LoginPresentationModel to the TextBox userName. The Button control ha an attached property Attach.Click which will make sure the Login method of the LoginPresentationModel is invoked when the Button&amp;#160; click event is trigged.

  &lt;br /&gt;&lt;/p&gt;

&lt;div&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; Login(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; userName, &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; password)
{
}&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;
  &lt;br /&gt;As you can see the Login method has two arguments, userName and password. Which is not given when the Login method is attached to the Click event. By default the framework will check if there are controls with the same name as the argument, if so, it will get the value from the controls and pass them as an argument. So in this case the userName and Password control’s value will be passed to the Login method. I can also write the following when I attached the method to the event:

  &lt;br /&gt;&lt;/p&gt;

&lt;div&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&amp;lt;Button e:Attach.Click=&lt;span style="color: #006080"&gt;&amp;quot;Login(userName.Text, password.Text)&amp;quot;&lt;/span&gt; Content=&lt;span style="color: #006080"&gt;&amp;quot;Login&amp;quot;&lt;/span&gt;/&amp;gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;
  &lt;br /&gt;The argument mapping in this framework works similar to how it does in the ASP.Net MVC. For example if the Login method instead will take a LoginCredential class:&lt;/p&gt;

&lt;p&gt;&lt;span style="color: #0000ff"&gt;
    &lt;br /&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; Login(&lt;span style="color: #0000ff"&gt;LoginCredential loginCredential&lt;/span&gt;) { } &lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;div&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; LoginCredential
{
    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; UserName { get; set; }
    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; Password { get; set; }
}&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;
  &lt;br /&gt;The LoginCredential will be created and the framework will first look for controls with the name “loginCredential_UserName” and/or “loginCredential_Password” and get the value and set it to the LoginCredential properties. If the “loginCredential_” prefix can’t be found it will check for controls with the same name as&amp;#160; the properties of the LoginCredential class. A MappingAttribute can also be used for the arguments of a method to also specify a specific prefix. [Mapping(“login”)], and instead of looking for “loginCredential_” prefex, the framework will look for a the prefix “login_”.&lt;/p&gt;

&lt;p&gt;We can also make sure our action methods returns a value and set the value to a specific FrameworkElement’s property:
  &lt;br /&gt;&lt;/p&gt;

&lt;div&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; Login(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; userName, &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; password)
{
    &lt;span style="color: #008000"&gt;//Do some validation&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (faild)
        &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; &lt;span style="color: #006080"&gt;&amp;quot;The user name or password is not correct..&amp;quot;&lt;/span&gt;;

    &lt;span style="color: #008000"&gt;//..&lt;/span&gt;
}&lt;/pre&gt;
&lt;/div&gt;

&lt;br /&gt;

&lt;p&gt;&lt;/p&gt;

&lt;div&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&amp;lt;TextBloc x:Name=&lt;span style="color: #006080"&gt;&amp;quot;errorMsg&amp;quot;&lt;/span&gt;/&amp;gt;

&amp;lt;! -- .... ---&amp;gt;

&amp;lt;Button e:Attach.Click=&lt;span style="color: #006080"&gt;&amp;quot;Login =&amp;gt; errorMsg.Text&amp;quot;&lt;/span&gt; Content=&lt;span style="color: #006080"&gt;&amp;quot;Login&amp;quot;&lt;/span&gt;/&amp;gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;&lt;/p&gt;

&lt;br /&gt;By using the “=&amp;gt;” we specify that we will take the value from the Login and move it to the errorMsg.Text property. But if we use a correct Presentation Model we would not use this “expression”, instead have a property in the Presentation Model which we bind to the TextBlock and set the property internally in within the Login method and then use the NofityPropertyChanged to update the TextBlock value:

&lt;br /&gt;

&lt;br /&gt;

&lt;br /&gt;

&lt;div&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&amp;lt;TextBloc x:Name=&lt;span style="color: #006080"&gt;&amp;quot;errorMsg&amp;quot; Text=”{Binding ErrorMsg}”&lt;/span&gt;/&amp;gt;

&amp;lt;! -- .... ---&amp;gt;

&amp;lt;Button e:Attach.Click=&lt;span style="color: #006080"&gt;&amp;quot;Login&amp;quot;&lt;/span&gt; Content=&lt;span style="color: #006080"&gt;&amp;quot;Login&amp;quot;&lt;/span&gt;/&amp;gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;div&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; Login(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; userName, &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; password)
{
    &lt;span style="color: #008000"&gt;//Do some validation&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (faild)
        &lt;font color="#0000ff"&gt;this.ErrorMsg =&lt;/font&gt; &lt;span style="color: #006080"&gt;&amp;quot;The user name or password is not correct..&amp;quot;&lt;/span&gt;;

    &lt;span style="color: #008000"&gt;//..&lt;/span&gt;
}&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;
  &lt;br /&gt;The Framework also support Asynchronous calls. We can mark a method with the AsynCall attribute and make sure it will be executed in a background worker thread:

  &lt;br /&gt;&lt;/p&gt;

&lt;div&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;[AsynCall]
&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; Login(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; userName, &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; password)
{
    &lt;span style="color: #008000"&gt;//Do some validation&lt;/span&gt;
}&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;
  &lt;br /&gt;We can also specify a callback method which will be executed in the UI thread:

  &lt;br /&gt;&lt;/p&gt;

&lt;div&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;[AsynCall(CallBack=&lt;span style="color: #006080"&gt;&amp;quot;Login_Completed&amp;quot;&lt;/span&gt;)]
&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; Login(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; userName, &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; password)
{
    &lt;span style="color: #008000"&gt;//Do some validation&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; &lt;span style="color: #006080"&gt;&amp;quot;someting&amp;quot;&lt;/span&gt;;
}

&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; Login_Completed(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; result)
{
    &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; result + &lt;span style="color: #006080"&gt;&amp;quot;and something more&amp;quot;&lt;/span&gt;;
}&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;
  &lt;br /&gt;The AsyncCallAttribute is an ActionFilter, so we can create our own ActionFilters, which has at the moment three methods we can use, OnPreAction, OnPostAction and UnhandledException. the ActonFilters are similar to how ActionFilters works within the ASP.NET MVC. Here is an example of a TestActionFitlerAttribute:&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;div&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; TestActionFilterAttribute : ActionFilterAttribute
{
      &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;override&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; OnPreAction(PreActionFilterArgs actionFilterContext)
      {
          &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (actionFilterContext.ActionMethodArguments != &lt;span style="color: #0000ff"&gt;null&lt;/span&gt; &amp;amp;&amp;amp; actionFilterContext.ActionMethodArguments.Length &amp;gt; 0)
          {
              var c = actionFilterContext.ActionMethodArguments[0] &lt;span style="color: #0000ff"&gt;as&lt;/span&gt; Customer;

              c.FirstName = &lt;span style="color: #006080"&gt;&amp;quot;Fredrik&amp;quot;&lt;/span&gt;;
          }

          var p = actionFilterContext.PresentationModel &lt;span style="color: #0000ff"&gt;as&lt;/span&gt; CustomerPresentationModel;
          p.Customer.FirstName = &lt;span style="color: #006080"&gt;&amp;quot;Lovisa&amp;quot;&lt;/span&gt;;
      }


      &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;override&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; OnPostAction(PostActionFilterArgs actionFilterContext)
      {
          actionFilterContext.ActionMethodReturnValue += &lt;span style="color: #006080"&gt;&amp;quot;test&amp;quot;&lt;/span&gt;;
      }


      &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;override&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; OnUnhandledException(UnhandledExceptionActionFilterArgs unhandledExceptionActionFilterArgs)
      {
          var c = unhandledExceptionActionFilterArgs.PresentationModel &lt;span style="color: #0000ff"&gt;as&lt;/span&gt; CustomerPresentationModel;
          c.ErrorMsg = unhandledExceptionActionFilterArgs.Exception.Message;

          unhandledExceptionActionFilterArgs.Handled = &lt;span style="color: #0000ff"&gt;true&lt;/span&gt;;
      }
}&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;&lt;/p&gt;

&lt;br /&gt;The Action Filter above will manipulate the Action methods arguments before the action method is executed. The filter will also manipulate the return value of a Action filter (if the Action method will return a value). We can also manipulate the Presentation Model’s stage within the Action Filter, the Action Filters will be executed within the UI thread.

&lt;br /&gt;

&lt;br /&gt;The source code is more or less completed, need to do some more refactoring and also run some more tests, but all the basics will work. If you want a framework like this you can take a look at Prism v 2.0 from Microsoft Patterns &amp;amp; Practices, Caliburn or Nikhil’s Silverlight.FX, my framework is nothing I will support and only created it for fun. If you want the source code, please drop me an e-mail (fnormen [ at ] hotmail.com because I have no place to upload the source code at the moment. Remember the source code is not yet completed, I will add more support for more events and also make sure others can easy add events to attach to etc.&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6925068" width="1" height="1"&gt;</description></item><item><title>How the Presentation Model could look like when using Silverlight 2.0 (Part 3)</title><link>http://weblogs.asp.net/fredriknormen/archive/2009/02/22/how-the-presentation-model-could-look-like-when-using-silverlight-2-0-part-3.aspx</link><pubDate>Sun, 22 Feb 2009 13:15:41 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6923043</guid><dc:creator>Fredrik N</dc:creator><slash:comments>7</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/fredriknormen/rsscomments.aspx?PostID=6923043</wfw:commentRss><comments>http://weblogs.asp.net/fredriknormen/archive/2009/02/22/how-the-presentation-model-could-look-like-when-using-silverlight-2-0-part-3.aspx#comments</comments><description>&lt;p&gt;In my previous &lt;a href="http://weblogs.asp.net/fredriknormen/archive/2009/01/30/how-the-presentation-model-could-look-like-when-using-silverlight-2-0.aspx"&gt;Part 1&lt;/a&gt; and &lt;a href="http://weblogs.asp.net/fredriknormen/archive/2009/02/16/how-the-presentation-model-could-look-like-when-using-silverlight-2-0-part-2.aspx"&gt;Part 2&lt;/a&gt; I wrote how a Presentation Model could be implemented and how to handle Async .calls. In this post I will show you how we can avoid adding code to the Code-behind. In &lt;a href="http://weblogs.asp.net/fredriknormen/archive/2009/02/16/how-the-presentation-model-could-look-like-when-using-silverlight-2-0-part-2.aspx"&gt;Part 2&lt;/a&gt;, I had the following code in the code-behind:    &lt;br /&gt;&lt;/p&gt;  &lt;div&gt;   &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;partial&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; Page : UserControl
{
   &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; NamePresentationModel _namePresentationModel;

   &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; Page()
   {
      InitializeComponent();

      _namePresentationModel = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; NamePresentationModel(&lt;span style="color: #0000ff"&gt;new&lt;/span&gt; NameRepository());

      &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.Loaded += Page_Loaded;
   }

   &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; Page_Loaded(&lt;span style="color: #0000ff"&gt;object&lt;/span&gt; sender, RoutedEventArgs e)
   {
       LoadFromPresentationModel();
   }

   &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; Button_Click(&lt;span style="color: #0000ff"&gt;object&lt;/span&gt; sender, RoutedEventArgs e)
   {
     _namePresentationModel.SaveAsync((source, args) =&amp;gt;
                                    {
                                       messageTextBlock.Text = &lt;span style="color: #006080"&gt;&amp;quot;NameEntity Saved&amp;quot;&lt;/span&gt;;
                                    });
   }


    &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; LoadFromPresentationModel()
    {
       _namePresentationModel.LoadAsync((sender, args) =&amp;gt;
                                     {
                                          myStackPanel.DataContext = args.Result;
                                     });
    }
}&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;
  &lt;br /&gt;Wouldn’t it be nice if we can leave the code-behind empty and instead specify which Presentation Model we would like to use in the XAML file instead? Here is my new code-bind:

  &lt;br /&gt;&lt;/p&gt;

&lt;div&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;partial&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; Page : View
{
    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; Page()
    {
        InitializeComponent();
    }
}&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;
  &lt;br /&gt;I have moved all the actions and creation of the Presentation Model to the XAML file instead:

  &lt;br /&gt;&lt;/p&gt;

&lt;div&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&amp;lt;e:View x:Class=&lt;span style="color: #006080"&gt;&amp;quot;PresentationModelExample1.Page&amp;quot;&lt;/span&gt;
    xmlns=&lt;span style="color: #006080"&gt;&amp;quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&amp;quot;&lt;/span&gt; 
    xmlns:x=&lt;span style="color: #006080"&gt;&amp;quot;http://schemas.microsoft.com/winfx/2006/xaml&amp;quot;&lt;/span&gt;
    xmlns:e=&lt;span style="color: #006080"&gt;&amp;quot;clr-namespace:Silverlight.Extension;assembly=Silverlight.Extension&amp;quot;&lt;/span&gt;
    xmlns:m=&lt;span style="color: #006080"&gt;&amp;quot;clr-namespace:PresentationModelExample1.Model;assembly=PresentationModelExample1&amp;quot;&lt;/span&gt;
    Width=&lt;span style="color: #006080"&gt;&amp;quot;400&amp;quot;&lt;/span&gt; Height=&lt;span style="color: #006080"&gt;&amp;quot;300&amp;quot;&lt;/span&gt;
    &lt;strong&gt;&lt;em&gt;&lt;font size="3"&gt;e:Action.Loaded=&lt;span style="color: #006080"&gt;&lt;font color="#000000"&gt;&amp;quot;Load&amp;quot;&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;/em&gt;&lt;/strong&gt;&amp;gt;
    &lt;strong&gt;&lt;em&gt;&lt;font size="4"&gt;&amp;lt;e:View.Model&amp;gt;
        &amp;lt;m:NamePresentationModel/&amp;gt;
    &amp;lt;/e:View.Model&amp;gt;&lt;/font&gt;&lt;/em&gt;&lt;/strong&gt;

    &amp;lt;Grid x:Name=&lt;span style="color: #006080"&gt;&amp;quot;LayoutRoot&amp;quot;&lt;/span&gt; Background=&lt;span style="color: #006080"&gt;&amp;quot;White&amp;quot;&lt;/span&gt;&amp;gt;
        &amp;lt;StackPanel Margin=&lt;span style="color: #006080"&gt;&amp;quot;50&amp;quot;&lt;/span&gt;&amp;gt;

            &amp;lt;TextBox x:Name=&lt;span style="color: #006080"&gt;&amp;quot;name&amp;quot;&lt;/span&gt; Margin=&lt;span style="color: #006080"&gt;&amp;quot;4&amp;quot;&lt;/span&gt; Text=&lt;span style="color: #006080"&gt;&amp;quot;{Binding Name}&amp;quot;&lt;/span&gt;&amp;gt;&amp;lt;/TextBox&amp;gt;

            &amp;lt;Button &lt;strong&gt;&lt;em&gt;&lt;font size="4"&gt;e:Action.Click=&lt;span style="color: #006080"&gt;&amp;quot;Save&amp;quot;&lt;/span&gt;&lt;/font&gt;&lt;/em&gt;&lt;/strong&gt; Margin=&lt;span style="color: #006080"&gt;&amp;quot;10&amp;quot;&lt;/span&gt; Content=&lt;span style="color: #006080"&gt;&amp;quot;Save&amp;quot;&lt;/span&gt;&amp;gt;&amp;lt;/Button&amp;gt;

        &amp;lt;/StackPanel&amp;gt;
        
    &amp;lt;/Grid&amp;gt;
&amp;lt;/e:View&amp;gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;
  &lt;br /&gt;By using the Action.&amp;lt;EventName&amp;gt; Attached Property, I can specify a method located in the Presentation Model and invoke it when the &amp;lt;EventName&amp;gt; is trigged. The View.Model Attached Property is used to specify which Presentation Model the View should use. Here is the code for the View class used instead of the UserControl:

  &lt;br /&gt;&lt;/p&gt;

&lt;div&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; View : UserControl
{
    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;object&lt;/span&gt; Model
    {
        get { &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; DataContext &lt;span style="color: #0000ff"&gt;as&lt;/span&gt; Model; }
        set { DataContext = &lt;span style="color: #0000ff"&gt;value&lt;/span&gt;; }
    }
}&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;
  &lt;br /&gt;As you can see when I give the Model a value, the value will be bound to the DataContext of the UserControl. I need to change the code-behind to inherits from my View class, and I also need to add a namespace to the XAML file to point out where the View class is located. Then I replace the &amp;lt;UserControl&amp;gt; element with my new View element instead. When this is done I can use normal data binding to get values from my Presentation Model. The next thing to do is to create a Attached Property to make sure they invoke the specified Presentation Model methods when an event is trigged. It’s quite easy to add a Attached Property, the following example is the Action.Click attached property:

  &lt;br /&gt;&lt;/p&gt;

&lt;div&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; Action
{

       &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;readonly&lt;/span&gt; DependencyProperty ClickProperty =
          DependencyProperty.RegisterAttached(
             &lt;span style="color: #006080"&gt;&amp;quot;Click&amp;quot;&lt;/span&gt;,
             &lt;span style="color: #0000ff"&gt;typeof&lt;/span&gt;(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;),
             &lt;span style="color: #0000ff"&gt;typeof&lt;/span&gt;(Action),
             &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; PropertyMetadata(
                 &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;,
                 &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; PropertyChangedCallback(OnClickChanged)));


       &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; GetClick(DependencyObject element)
       {
           &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; (&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;)element.GetValue(ClickProperty);
       }


       &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; SetClick(DependencyObject element, &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; &lt;span style="color: #0000ff"&gt;value&lt;/span&gt;)
       {
           element.SetValue(ClickProperty, &lt;span style="color: #0000ff"&gt;value&lt;/span&gt;);
       }


       &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; OnClickChanged(DependencyObject sourceElement,
                                          DependencyPropertyChangedEventArgs e)
       {
           var button = sourceElement &lt;span style="color: #0000ff"&gt;as&lt;/span&gt; Button;

           &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (button == &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;)
               &lt;span style="color: #0000ff"&gt;throw&lt;/span&gt; &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; ArgumentException(&lt;span style="color: #006080"&gt;&amp;quot;DependencyObject is not of type Button&amp;quot;&lt;/span&gt;);

           button.Click += ((sender, args) =&amp;gt; { ActionHelper.GenerateActionCall(e.NewValue.ToString(), button); });
       }
}&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;
  &lt;br /&gt;We only need to create a static class and then add a DependencyProperty and use the DependencyProeprty’s RegisterAttached method to register a Attached Property. The argument are the name of the Property to use, the type, owner and then a PropertyChangedCallback which will be executed when the properties value are changed. Next step is to add a Get&amp;lt;PropertyName&amp;gt; and a Set&amp;lt;PropertyName&amp;gt; method and make sure it will set and get the value from the specified DependencyProperty. The name after the Get and Set prefix is the name of the property that you want to use. So if you name the Get method to GetMyPropery, the Attached property in the XAML will be Action.GetMyProperty.&lt;/p&gt;

&lt;p&gt;In the specified callback method of the DependencyProperty, I have hooked up to the button control’s Click event. The ActionHelper class something that I have created to help me create a method which will invoke the specified action method. So the method will only get the Model from the DataContext of the specified control and then call the InvokeMember of the model’s type, something like this:
  &lt;br /&gt;&lt;/p&gt;

&lt;div&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;model.GetType().InvokeMember(
                    actionName,
                    System.Reflection.BindingFlags.InvokeMethod,
                    &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;,
                    model,
                    arguments);&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;
  &lt;br /&gt;I have also added some code to map arguments of the action method to controls on the UI, so if I have a Save method with an argument called name I will get the value from a control with the same name as the argument. If the argument of the Action method is an entity, I will create a new instance of&amp;#160; the Entity and map it’s property to controls with the same name.

  &lt;br /&gt;&lt;/p&gt;

&lt;div&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; Save(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; name)
{
    &lt;span style="color: #008000"&gt;//...&lt;/span&gt;
}

&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; Save(NameEntity name)
{
    &lt;span style="color: #008000"&gt;//...&lt;/span&gt;
    _nameRepository.SaveName(name);
}&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;
  &lt;br /&gt;There are several of frameworks created to map a Presentation Model to a View without using a code-behind. I only created my own to learn more about how to extend Silverlight elements etc. You can for example get a similar framework from Nikhil (Member of the ASP.Net team) called &lt;a href="http://projects.nikhilk.net/SilverlightFX/"&gt;Silverlight.FX&lt;/a&gt;, another project with similar functionality is the &lt;a href="http://www.codeplex.com/caliburn"&gt;Caliburn&lt;/a&gt;.&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6923043" width="1" height="1"&gt;</description></item></channel></rss>