Silverlight And Strongly Typed Resource Classes

If you have tried to localize Silverlight applications using .resx files you will probably have noticed that strongly typed resource classes don't work straight out of the box. This post describes how you can overcome this.

New in Visual Studio 2008 is the PublicResXFileCodeGenerator, a code generator for creating public strongly typed resource classes. This code generator does indeed generate public classes with public properties and for all applications except Silverlight this is exactly what is wanted of a public strongly typed resource class. But for Silverlight applications it is not enough. The problem is that the constructor in the generated code is still internal. Normally this doesn't make any difference because nothing ever constructs a strongly typed resource class directly; only the static properties are used. But the constructor is used in a Silverlight application and that's where the internal constructor is unhelpful. The manual solution to this problem is to edit the generated code and this is a very undesirable solution because you have to continually re-edit the generated code every time it is re-generated. A more permanent solution is needed and it is available in the form of the PublicResourceCodeGenerator. I have written a number of code generators for strongly typed resource classes that solve various problems. You can download the code generators here and the source code is included in the source code for my .NET Internationalization book here. Here is the current list of code generators for strongly typed resource classes:-

Code Generator Class Description
ResourceCodeGenerator Generates the exact same code as the ResXFileCodeGenerator and offers no additional benefit.
PublicResourceCodeGenerator Generates almost the same code as the PublicResXFileCodeGenerator except that the constructor is public instead of internal.
ResourceProviderCodeGenerator Generates the same code as the ResXFileCodeGenerator except that it uses a provider model instead of the ResourceManager.
PublicResourceProviderCodeGenerator Generates the same code as the PublicResXFileCodeGenerator except that it uses a provider model instead of the ResourceManager and the constructor is public.
GlobalResourceProviderProxyGenerator Generates the same code as the GlobalResXFileProxyGenerator (used for ASP.NET global resources) except that it uses a provider model instead of the ResourceManager.

So to generate strongly typed resource classes that can be used in Silverlight applications select the .resx file in Solution Explorer and then in the Properties Window set the Custom Tool to PublicResourceCodeGenerator.

Currently rated 4.2 by 9 people

  • Currently 4.222222/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by: GuySmithFerrier
Posted on: Saturday, September 27, 2008 at 8:10 AM
Tags: , ,
Categories: Internationalization
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (2) | Post RSSRSS comment feed

DotNetDevNet: An Evening Of Silverlight with Jesse Liberty


Hold the phone! Yes, Jesse Liberty, author of over 20 books, Program Manager on the Silverlight Team at Microsoft, self-confessed "Silverlight Geek" (it actually says that on his business card) is coming to Bristol. And he's going to talk on Silverlight for 2 hours! Jesse is doing a lightening tour of the UK combining The .NET Developer Network in Bristol, ReMix in Brighton and 2 events in Dublin and Belfast. On Tuesday 16th September 2008 he is in Bristol to cover two Silverlight subjects:-

Styles, Templates and Visual State Manager
1.       Introductions, Make fun of the American
2.       Modifying a toolbox control with in-line attributes
3.       Creating Styles and applying them to controls in Xaml
4.       Creating Styles and applying them to controls in Blend
5.       Reskinning toolbox controls with Templates, by hand
6.       Reskinning toolbox controls with Templates, in Blend

Skinnable Custom Controls- The Parts and State Model and Inside the VSM
1.       An introduction to the Parts and State Manager and VSM in detail
2.       Creating a Custom Control
3.       Visual States and Visual State Groups
4.       Storyboards and Transitions
5.       Inside the VSM
6.       Creating a Custom Control Contract
7.       The Template Part Attribute
8.       The Template Visual State Attribute
9.       Putting it all together.
10.     Good night and where’s the beer?

Attendance is free - you just have to be a member (which is free) and send an email saying you want to attend. If you're into Silverlight can you afford to miss hearing about it straight from the horse's mouth ? (Sorry, Jesse, British colloqualiasms sometimes leave something to be desired).

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by: GuySmithFerrier
Posted on: Monday, August 18, 2008 at 11:04 PM
Tags: ,
Categories: Events
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (0) | Post RSSRSS comment feed

ReMix UK 08: Internationalizing WPF And Silverlight Applications

ReMix UK 08 is Microsoft's 2 day UI technologies conference for designers and developers. This year it will be held in Brighton on Thursday 18th and Friday 19th September 2008 and I'm very pleased to say that I will be speaking on the Friday. My session is:-

Internationalizing WPF And Silverlight Applications
Windows Presentation Foundation (WPF) applications have as many similarities as differences from Windows Forms applications. The same is true for WPF’s localization model. This session illustrates how to localize and globalize WPF and Silverlight applications and pays particular attention to those issues that are unique to XAML, WPF and Silverlight.

There's lots to cover here and some thinking and some decisions to be made to get the right result.

See you there.

Currently rated 3.0 by 3 people

  • Currently 3/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by: GuySmithFerrier
Posted on: Thursday, July 31, 2008 at 11:18 PM
Tags: , ,
Categories: Events | Internationalization
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (0) | Post RSSRSS comment feed