The sample below shows how you can bind language resources (resx) with praticllay no code, only markup.
1. Open Visual Studio
2. Click File \ New Project...
3. Select Visual C# \ Silverlight \ Silverlight Application
4. In the name field type SL_Loc_Sample
5. Click ok and ok
6. In the Project Explorer
7. Right click on the SL_Loc_Sample (c# Icon) Project
8. Click Add \ New Folder
9. Name it Resources
10. Right click on Resources folder and click add New Item...
11. Select Resources File
12. Name it Strings.resx and click ok
13. Open the new created Strings.resx
14. In the Access Modifier: dropdown select Public
15. In the Name Field type tb1 and value “tb1 in english”
16. Repeat with Name Field type tb2 and value “tb2 in english”
17. In the file Strings.Designer.cs change “internal Strings() {“ to “public Strings() {” Note: Every time you change the strings.resx you update this reference i hope this gets fixed in the RTM verion
18. Click Save, press F5 and add debugging to web.config
19. IE opens up with a blank page
20. Close IE
21. Open Page.xaml in xaml editor window
22. In the user control add a new xml namespace xmlns:Loc="clr-namespace:SL_Loc_Sample.Resources"
23. Add a locstrings as a resource to your page eg: <UserControl.Resources><Loc:Strings x:Name="LocStrings" /></UserControl.Resources>
24. Inside the grid add a Textblock and bind it to your resource Tb1 eg: <TextBlock Text="{Binding tb1, Source={StaticResource LocStrings}}" />
25. The String should appear in the Design view above
26. Wrap the textblock inside a vertical stackpanel and add a second Textkblock
<StackPanel Orientation="Vertical">
<TextBlock Text="{Binding tb1, Source={StaticResource LocStrings}}" />
<TextBlock Text="{Binding tb2, Source={StaticResource LocStrings}}" />
</StackPanel>
27. In Project Explorer right click on Strings.resx and copy and paste it into the resources folder
28. Rename “Copy of Strings.resx” to “Strings.de.resx” (DE is the two letter language code for German)
29. Open Strings.de.resx Edit the value to “tb1 auf deutsch” and “tb2 auf deutsch”
30. Click Save, press F5
31. Notice the file %HOMEPATH%\Documents\Visual Studio 2008\Projects\SL_Loc_Sample\bin\debug\de\SL_Loc_Sample.resources.dll appears but is not embedded in your xap yet
32. To add that market to your xap you must open the .csproj in notepad (ugly workaround until SL2.0 tools RTW)
33. Update SupportedCultures to <SupportedCultures>de</SupportedCultures>
34. Save and close
35. VS 2008 will ask you to reload project, click reload
36. Next we need to update the SL browser object reference
37. Id recommend you delete the SL_Loc_SampleTestPage.aspx and set SL_Loc_SampleTestPage.html as your start page
38. In SL_Loc_SampleTestPage.html Add the culture and uiculture params to your object
<object data="data:application/x-silverlight," type="application/x-silverlight-2-b2" width="100%" height="100%">
<param name="source"v value="ClientBin/SL_Loc_Sample.xap"/>
<param name="onerror" value="onSilverlightError" />
<param name="background" value="white" />
<param name="culture" value="de" />
<param name="uiculture" value="de" />
</object>
39. Click Save, press F5
40. IE should open up with the German strings
Code:
http://cid-289eaf995528b9fd.skydrive.live.com/self.aspx/Public/SL%7C_Loc%7C_Sample.zip
Links:
http://silverlight.net/forums/p/17678/58967.aspx
http://blogs.msdn.com/webdevtools/archive/2008/06/10/localizing-a-silverlight-application.aspx