Here is a simple static class, Settings, that offers methods to Read and Write application settings and preferences from Silverlight applications.  These settings are similar to the ones that Windows apps would store in the registry or in an INI file, but in this case, are written to Silverlight’s isolated storage.

This class wraps Silverlight’s IsolatedStorageSettings class, so remember; since a user has the freedom to purge isolated storage at will, this class is mostly useful for storing application preferences like layout sizes and locations, and other creature comforts for regular users.  This class can read or write any data type to settings storage; the IsolatedStorageSettings class will automatically serialize and deserialize the settings for you.

The code below has been tested and used with Silverlight 3 and Silverlight 4.

using System.IO.IsolatedStorage;

namespace ClassLibrary
{
	public static class Settings
	{
		public static TT Read<TT>(string name)
		{
			return Read<TT>(name, default(TT));
		}

		public static TT Read<TT>(string name, TT defaultValue)
		{
			IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings;
			TT value;
			if (settings == null || !settings.TryGetValue<TT>(name, out value))
				return defaultValue;
			return value;
		}

		public static void Write<TT>(string name, TT value)
		{
			IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings;
			if (settings == null)
				return;
			if (settings.Contains(name))
				settings[name] = value;
			else
				settings.Add(name, value);
			settings.Save();
		}
	}
}