Tag Archives: Silverlight

Articles about the Future of Silverlight

10 Jul

Since PDC in late 2010 there have been lots of rumors and guessing about the future of Silverlight. In spring 2011 at MIX11 Microsoft released the beta of Silverlight 5 and announcing the final release of Silverlight 5 in late 2011.

With this post I’m trying to gather some of the most objective articles written about the future of Silverlight.

Silverlight is Dead, Long Live XAML
written on July 5, 2011

Premature cries of Silverlight / WPF skill loss. Windows 8 supports all programming models.
written on June 14, 2011

Silverlight rumored to have high prominence in Windows 8
written on June 9, 2011

Microsoft reorg: Scott Guthrie to head new Azure Application Platform team
written on May 2, 2011

Video: Tim Heuer – Silverlight is not dead – DevConnections 2010
written on November 7, 2010

PDC and Silverlight (by Bob Muglia)
written on November 1, 2010

Microsoft: Our strategy with Silverlight has shifted
written on October 29, 2010

Silverlight and HTML5 and Your Future
written on October 29, 2010

Silverlight TV 50: The State of Silverlight with Scott Guthrie
written on October 21, 2010

If you think I’m missing an article please let me know at @xamlgeek.

by xamlgeek

Share code between client and server

10 Apr

One of the challenges of writing managed components for Silverlight is the fact that it is not possible to use a normal .NET assembly in Silverlight projects. One way to get around this issue is to use linked and partial classes in Silverlight projects.

How to use linked classes in Silverlight

Let’s say I have a solution with 3 projects: a Silverlight client (client), a web application (web) and a .NET class library (lib). The lib contains entities and business logic that I wish to share between the client and the web.

It would be great to reference the lib from the client but that is not an option in Silverlight. Of course I can copy the content of the lib to the client, but that is really not an option either; nobody wants to maintain to sets of the same business logic.

Instead I can link the files from the lib to the client. In this sample I have a Person entity in the lib project that I wish to share with the client. In the client I choose to add an existing item and find the class from the lib project I wish to add. I click on the arrow next to the add button and select "Add as link".



This will add the Person entity class to my client project and it’s nothing more then a link to the class from the lib project. The link will make sure that the class is compiled into both projects at compile time.

The downside of this solution is that even though I can share the classes, it’s not possible to put logic into the classes that is server side or client side only. One way to get around that is to use partial classes.

Partial classes on the client and the server

In the lib project I can create a server side partial class of our business logic and I can do the same on the client. In this sample I have create a server side only version of the Person entity classes "Person.server.cs" and a client side only version of the Person entity called "Person.client.cs". The Person entity itself is still linked between the client and the server. Remember that for this to work the namespace must be the same between all partial files! This enables the separation of logic running only server or client side.


This solution enables me to run and share classes like business logic code on the client and the server.

You can download my sample here.

by xamlgeek

Slides and samples from Silverlight Patterns and Frameworks talk

8 Feb

Yesterday Martin Jespen and I did a talk about Silverlight patterns and framework at the monthly Silverlight Usergroup meeting in Denmark.

I the first part of the talk, Martin showed the differences between MEF and Unity and wrapped up by showing some of the possibilities in PRISM. You can download the samples here. You can download the documentation for PRISM here.

In the second part of the talk, I showed how to expose an OData feed using a WCF DataService and access the data from a Silverlight application. To follow up I showed how to use a WCF RIA Service and how to expose the data as an OData feed. You can down the samples here. You can find a guide to OData and Silverlight here.

You can download the presentation here.

by xamlgeek 

A guide to OData and Silverlight

6 Feb

OData (Open Data Protocol) is a web protocol for querying and updating data build upon web technologies such as HTTP, AtomPub and JSON. OData can be used to expose and access data from a several types of data source like databases, file systems and websites.

OData can be exposed by a variety of technologies – first and foremost .NET but also Java and Ruby. On the client side OData can be accessed by .NET, Silverlight, WP7, JavaScript, PHP, Ruby and Objective-C just to mention some of them. This makes OData very attractive to solutions where data need to be accessed by several clients.

The scope

In this post I will show how to expose data from an existing data source and access the data in a Silverlight application. The data source contains meteorological data about beaches in Copenhagen, Denmark and is hosted in a SQL Azure database.

Expose data

To be able to expose some data I need to get the data from somewhere. I have created a WCF Service Application called “ODataDemo.Services”. In this project I have created a folder called “Models” and added an EF4 model called “BeachDB.edmx”. The model contains one table called “Beaches” and the Entity Container is called “Entities”. So far it’s all standard EF4.


In Visual Studio 2010 we have an item type called “WCF Data Service” that we can use to expose an OData feed with. I have added a new WCF Data Service called “BeachService.svc”. The service inherits from DataService being the main entry point for developing an ADO.NET Data Service. The DataService requires a type that defines the data service. In this case it’s the Entity Container named “Entities” that I specified in the EF4 model.


By default nobody can read the data I’m exposing through the service. I have to specify the access rules explicitly. If I browse to the service I will just get the title of the service.


In the method “InitializeService” I can specify the access rules. In this scenario I want to allow users to read all data.


If I browse to my service again I can see the collection called “beach” is available. If I browse to the collection (“/beach”) I will get a complete list of all beaches available in the data store (about 30 beaches).


I some cases you want to limit the access the data store. One way to do that is by defining some Query Interceptors. As the name tells we can intercept the queries and modify or limit the result set.

On a beach entity I have a property called “IsMarketPlace”. It indicates if the beach is public available or not. I have added a Query Interceptor called “OnQueryBeach” that will make sure that only the beaches marked with IsMarketPlace = true will be returned.


If I try to browse the list of beaches again I will see that the list is now on down to only two beaches as expected.

Access data

Next step is to read the exposed data in a Silverlight browser application. Therefore I have created a new Silverlight Application project called “ODataDemo.Client”.

In Visual Studio 2010 we can access the data from our OData feed by adding a Service Reference that will generate the entities exposed by the feed.


The proxy generated by the Service Reference will also create a DataServiceContext that we can use to run our queries against. In this scenario the DataServiceContext class is called “Entities” taken from the Entity Container.


With the DataServiceContext instantiated, a collection of beaches instantiated and a simple query I’m ready to load some data. When the data is loaded I set the ItemSource of a ListBox that I have added to the start page.



In some scenarios it might not be enough to limit the users’ access to the data using a Query Interceptor and I need a way to identify the users calling my service.

There are several ways to implement authorization. What I will show is a really simplified way to implement authorization and is for demonstration purpose only!

First thing I need to do is to make sure that on every request I get to my service, I need to identify the user calling my service. In the constructor of my service I can subscribe to the ProcessingRequest event. It will fire whenever somebody is requesting the service.



In this case the user will get access if the Authenticate method returns true otherwise the user will get a 401 unauthorized exception. The implementation of Authenticate is really simple and is for demonstration purpose only!


If the header contains “Authorization” with a value of “z7sgeq9n” the user will get access. A real implementation would identify the user and retrieve the users’ roles. In the Query Interceptors I can differentiate the data being returned to the user based on the roles applied to the user.

I need to add the header to my Silverlight application as well. Otherwise I will just get an “Unauthorized exception”. I can add the header information as part of my DataServiceContext object.


With the header information in place I have implemented a simple authorization method to my OData feed.

Related links

Source code

by xamlgeek

Silverlight kurser og workshops

31 Jan

Jeg har tidligere skrevet om en række Silverlight workshops som jeg afholder I løbet af de kommende 4 måneder. Alle workshops foregår onsdag aften på ITU fra kl. 18:00-21:00.

Nu ligger der også 2 kurser på tegnebrættet – et “Introduktion til Silverlight 4”-kursus og et “Avanceret Silverlight 4”-kursus. Begge kurser ligger i starten af april.

For at gøre det hele en smule mere overskueligt har jeg opdateret silverlightkursus.dk så den fremover viser en oversigt over alle workshops, kurser og foredrag som Bluefragments står for.

Derudover afholder den danske Silverlight brugergruppe (SLDEV) en række spændende events som kan ses på http://sldev.eventbrite.com/.

Happy coding!

by xamlgeek 

PivotViewer demos

27 Jan

During the last months I have been working on a Silverlight PivotViewer demo for a customer. I have been very surprised by the power of the PivotViewer control available for Silverlight 4. That said I’m looking forward to the PivotViewer control being an integrated control in Silverlight 5.

The demo I did is a closed demo (for now), but below I have listed some public (and very cool) demos.

You can learn more about PivotViewer at http://www.silverlight.net/learn/pivotviewer/.

by xamlgeek 

Silverlight 4 certified

24 Jan

A few months ago I took a Silverlight 4 (beta) exam (70-506). Because it was a beta exam I didn’t receive the result right away – but today I got the result. And I passed – YEAH :) It’s was a beta exam so I don’t get the detailed score – could have been fun to see, though.

You can read more about the exam at Microsoft Learning:
Exam 70-506: TS: Silverlight 4, Development

by xamlgeek 

7 Silverlight workshops

24 Jan

During the next 4-5 months I will do a series of Silverlight workshops. Each workshop is a practical hands-on workshop with focus on one subject. The level of each workshop vary but is clearly marked on each workshop.

Introducing Silverlight
Rich UI
The Application Model

All workshops will be held in Danish in Copenhagen, Denmark. The workshops are hosted by Bluefragments.

by xamlgeek 

The Silverlight penetration is no longer an issue

23 Jan

From the very beginning of Silverlight penetration has been an issue. As a professional developer living of Silverlight and as a Silverlight MVP, I often face questions about the Silverlight penetration from customers.

Some facts: The Flash plug-in is installed on almost 97 percent of all computers whereas the Silverlight plug-in is installed on about 70 percent of all computers. http://riastats.com/

Silverlight is primarily used to create enterprise components, tools and sites. If you take a look at the tools used to create Flash versus Silverlight (Visual Studio + Expression Studio) there is no doubt Silverlight are miles ahead of Flash. If you look at the advantages of being able to reuse existing resources and knowledge (.NET and Visual Studio) from an enterprise perspective Silverlight will beat Flash any day of the week.

In my opinion, the penetration of Silverlight has now reached a level where it’s no longer a barrier for enterprises to use Silverlight – even on public faced websites. The many advances of Silverlight will overshadow the lower penetration compared to Flash.

by xamlgeek

WOW! that was fun

20 Jan

Tonight I participated in the first geeknight hosted by the Danish Silverlight usergroup (SLDEV). It was a really great experience and I actually think that it was great fun. Only six developers participated but it was a relaxed atmosphere and we shared a lot of experiences.

The only agenda was that it was all about Silverlight. What surprised me was that only one (1!) choose to work on a Silverlight (OOB) application. The rest (including myself) was working on a Silverlight WP7 application. I actually managed to complete my Badevand application that show meteological data for beaches in Copenhagen, Denmark. The data is stored in a SQL Azure database and retrieved using an OData feed.

It might sound really geeky (and it is!) but I’m looking forward to the next geeknight in February (http://www.eventbrite.com/event/1178036539).

by xamlgeek