Vinayak Suley
Vinayak Suley

Reputation: 537

Is there a convenient way to set default values for ApplicationData.Current.LocalSettings using a settings file?

I'm using the built in settings infrastructure in my Windows Phone 8.1 application to store my settings key-value pairs. For instance:

ApplicationDataContainer settings = ApplicationData.Current.LocalSettings;
object value = settings.Values["DailyReminderOnOff"];

I'm trying to find a way to supply default values that come canned with the app at installation. Is there some recommended and convenient way of doing that?

I could implement my own system by placing a dirty bit and reading from a file if it's unset or provide defaults through if-null checks within the getter; but I'd rather avoid the hassle of writing and maintaining that code if the system provides something I've missed.

Thanks!

Upvotes: 1

Views: 202

Answers (1)

dotnetom
dotnetom

Reputation: 24901

There is no default way to get the value. Why don't you use simple fallback like this:

const string DefaultValue1 = "value123";
object value = settings.Values["DailyReminderOnOff"] ?? DefaultValue1;

Upvotes: 3

Related Questions