-
Notifications
You must be signed in to change notification settings - Fork 1
User Preferences
Chris Perry edited this page Apr 15, 2024
·
2 revisions
User Preferences in .NET MAUI are used to store local values within an App's datafiles
The preference helper provides a way to standardize the usage of FocusApp preferences.
- Default values are all stored in one place and don't need to be specified each time a preference is retrieved
The PreferenceNames enum details the various names of each FocusApp preference.
Get is used to check if there is saved value, and if there isn't, the default value will be returned.
- TPrefType is the datatype of the preference you're retrieving Usage example:
double ambianceVolume = PreferencesHelper.Get<double>(PreferencesHelper.PreferenceNames.ambiance_volume);
When changing the preference, .Set is used
- TPrefType is the datatype of the preference you're setting Usage Examples:
- With TPrefType automatically determined
PreferencesHelper.Set(PreferencesHelper.PreferenceNames.ambiance_volume, newValue);
- With TPrefType manually specified
PreferencesHelper.Set<bool>(PreferencesHelper.PreferenceNames.ambiance_volume, newBool);
Here's an example of a Key/Value Pair for saving ambient audio:
.Get is used to check if there is saved value, and if there isn't, the second value is the "Default value"
When changing the preference, .Set is used:
For switches, the name of the switch is passed through a function where a key and value is set.