开发者

Standard way to store string resources in a Silverlight app

I'm building a Silverlight 3 application, and I'm wondering what is the best way to store string text for use by the application.

Ideally these strings would be externalized in some sort of XML or independently editable format that开发者_高级运维 isn't binary compiled into my application.


I'd be inclined to use a ResourceDictionary in a Xaml file to achieve this.

<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:sys="clr-namespace:System;assembly=mscorlib"
>
    <sys:String x:Key="hello">Hello</sys:String>
    <sys:String x:Key="world">World</sys:String>
</ResourceDictionary>

Note this file does not have an x:Class. You would not include it as Content or as a Resource in the app build. You would instead just include it in the ClientBin folder where the XAP gets stored on the web site.

You would then use WebClient DownloadStringAsync to download this file and shove the resulting string through XamlReader which gets you an instance of ResourceDictionary that you can now use to resolve string references. In fact if you add this dictionary to the App.Resources' merged dictionaries its items can resolved as a static resource.


Use Resources File (.resx) to store strings.


Resource File will be the best place to store such string

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜