1
我们有一个适用于Windows IoT Core的UWP,我们需要保存一些设置,但即使应用程序已停止或物联网设备重新启动,这些设置也必须保留。如何保存应用程序设置?
我拥有的代码如下,它在应用程序打开时工作得很好,如果我在XAML页面之间切换,但在应用程序停止时不起作用,就像变量从不存在一样。
static class Global
{
public static Windows.Storage.ApplicationDataContainer localSettings { get; set; }
public static Windows.Storage.StorageFolder localFolder { get; set; }
}
private void Btn_Inciar_Config_Click(object sender, RoutedEventArgs e)
{
if (TxtDeviceKey.Text != String.Empty || TxtDeviceName.Text != String.Empty || Txt_Humedad_Config.Text != String.Empty || Txt_Intervalo_Config.Text != String.Empty || Txt_Temperatura_Ambiente_Config.Text != String.Empty || Txt_Temperaura_Config.Text != String.Empty)
{
Windows.Storage.ApplicationDataCompositeValue composite =
new Windows.Storage.ApplicationDataCompositeValue();
composite["GlobalDeviceKey"] = TxtDeviceKey.Text;
composite["GlobalDeviceName"] = TxtDeviceName.Text;
composite["GlobalTemperature"] = Txt_Temperaura_Config.Text;
composite["GlobalHumidity"] = Txt_Humedad_Config.Text;
composite["GlobalTemperatureRoom"] = Txt_Temperatura_Ambiente_Config.Text;
composite["GlobalInterval"] = Txt_Intervalo_Config.Text;
localSettings.Values["ConfigDevice"] = composite;
Lbl_Error.Text = "";
Frame.Navigate(typeof(MainPage));
}
else
{
Lbl_Error.Text = "Ingrese todos los campos de configuracion";
}
}