kaes
kaes

Reputation: 1307

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.

Upvotes: 1

Views: 411

Answers (3)

AnthonyWJones
AnthonyWJones

Reputation: 189495

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.

Upvotes: 1

Nivid Dholakia
Nivid Dholakia

Reputation: 5452

Resource File will be the best place to store such string

Upvotes: 0

Anatolii Gabuza
Anatolii Gabuza

Reputation: 6260

Use Resources File (.resx) to store strings.

Upvotes: 0

Related Questions