| sly 的个人资料Silverlight and Internat...照片日志列表 | 帮助 |
|
2008/11/16 LocWebService: Only download resources per UserControl
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. Advantages:
Disadvantages:
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. <UserControl.Resources>
</UserControl.Resources> ...
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 |
|
|