Reputation: 1307
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
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