本文介绍了Xamarin,如何将我的Xamarin.plugins.settings转换为xamarin.preferences.essentials以保存输入的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用Montemagno的插件来保存设置,但是有人提到最好使用用户preferences.essential.没有太多的教程.

Ive been using Montemagno's plugin for saving Settings but someone mentioned it's better to user preferences.essential. There's not much tutorial on it.

我在获取和设置值以及从设置位置的另一个文件中访问它时遇到问题.

I'm having problem the getting and setting the value and accessing it from another file from where I set it.

//Settings.cs
public static string NameSettings
{
    get
    {
        return AppSettings.GetValueOrDefault(SettingsnameKey, SettingsDefault);
    }
    set
    {
        AppSettings.AddOrUpdateValue(SettingsnameKey, value);
    }
}

public static string DrainquantitySettings
{
    get
    {
        return AppSettings.GetValueOrDefault(SettingsdrainxKey, SettingsDefault);
    }
    set
    {
        AppSettings.AddOrUpdateValue(SettingsdrainxKey, value);
    }
}

//this is how i get it in another file
drainxPicker.SelectedItem = Settings.DrainquantitySettings;

nameEntry.Text = Settings.NameSettings;

//to set it
Settings.NameSettings = username;
Settings.DrainquantitySettings = item;


//to convert to preferences?
public static NameSettings
{
    get => Preferences.Get(nameof(NameSettings), username);
    set => Preferences.Set(nameof(NameSettings), value);
}

//to use it??
nameEntry.Text = Preferences.Settings.NameSettings;

//to set it??
Preferences.Settings.NameSettings = username;

推荐答案

我就是这么做的

public static bool UploadOnlyOverWifi
{
    get => Preferences.Get(nameof(UploadOnlyOverWifi), false);
    set => Preferences.Set(nameof(UploadOnlyOverWifi), value);
}

这篇关于Xamarin,如何将我的Xamarin.plugins.settings转换为xamarin.preferences.essentials以保存输入的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-01 08:51