2016-11-01 6 views
1

私たちはWindows IoTコア用のUWPを持っていますので、いくつかの設定を保存する必要がありますが、アプリケーションが停止したりIoTデバイスが再起動してもこれらの設定は有効です。アプリケーションの設定を保存するには?

私が持っているコードは以下のとおりです。アプリケーションが開いているときには問題なく動作しますが、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"; 
    } 
} 

答えて

3

ローカルに設定を保存したい場合は、あなたがやったようにあなたは、(単一のエンティティとしてすべての値を保つために)単一のアイテムとして、またはApplicationDataCompositeValueとして保存することができます。コンポジット(または単一のアイテム)をApplicationData.Current.LocalSettingsコンテナに入れてください。コードの小さな部分の下に、空のアプリに貼り付けて2つのボタンに貼り付けるだけで試してみることができます。

private void SaveClicked(object sender, RoutedEventArgs e) 
{ 
    Windows.Storage.ApplicationDataCompositeValue composite = 
     new Windows.Storage.ApplicationDataCompositeValue(); 
    composite["GlobalDeviceKey"] = "Key"; 
    composite["GlobalDeviceName"] = "Name"; 
    ApplicationData.Current.LocalSettings.Values["ConfigDevice"] = composite; 
} 

private void LoadClicked(object sender, RoutedEventArgs e) 
{ 
    Windows.Storage.ApplicationDataCompositeValue composite = 
     (ApplicationDataCompositeValue) ApplicationData.Current.LocalSettings.Values["ConfigDevice"]; 
    var key = (string)composite["GlobalDeviceKey"]; 
} 
関連する問題