Home > Uncategorized > LocWebService: Only download resources per UserControl

LocWebService: Only download resources per UserControl

  1. Introduction
  2. UserControl local resources configuration
  3. WCF Service
  4. Code


1. Introduction

In this sample I will show how bind text elements that load localization resources from the server side resx file via a WCF service in silverlight 2.0.


  1. Only download resources per usercontrol
  2. Remove the need for custom resx code generators locally
  3. Local binding in design mode to english or your source language


  1. UserControl are slower to load (wait for WCF response before displaying)


2. UserControl local resources configuration

I first created two helper class’s to assist in design time binding called LocItem and LocCollection

LocItem implements the INotifyPropertyChanged class and contains two properties ItemName and ItemValue. This will enable us to dynamically update a localizable string at runtime. We then need to a LocItem for every localizable string we add it to our UserControl Resources  per control or page.

LocCollection is another helper class based from Silverlight Control Toolkit ObjectCollection This is a enumerable collection of our loc strings on a page, that get over the limitation that ResourceDictionary does not implement iEnumerable.

Both these are instantiated in markup and then bound to your localizable element.

        <Loc:LocItem ItemName="tb1" ItemValue="tb1" x:Key="LocItem1" />

<Loc:LocCollection x:Key="LStrings" >


<TextBlock x:Name="tb1" Text="{Binding ItemValue}" DataContext="{StaticResource LocItem1}" />


3. WCF Service

When the control initializes we make a WCF request to get all translations in our LocCollection. On the server side we lookup our server side resx file for each requested string and wrap it in a XDocument of LocString . Once the WCF loaded event fires we then update the  ItemValue our individual LocItems to display the localizable strings.


4. Code

This is a pretty crude sample but you could wrap this functionality in asp.net style base page to make it scale cleaner.

Download: LocWebService.zip

Categories: Uncategorized
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: