2013-02-18 91 views

回答

2

「值」是一個集合,其成員可以像這樣檢查。

if(roamingSettings.Values.ContainsKey("Sound")) 
{ 
    var myRoamingSettingValue = roamingSettings.Values["Sound"]; 
    // do stuff with the value you pulled back 
} 
else 
{ 
    // your roaming settings collection doesn't contain the value you are interested in. 
    // Add it? 
    roamingSettings.Values.Add("Sound", "myDefaultValue"); 
} 
+0

運作良好謝謝:

var _Exists = SettingExists("Sound", StorageStrategies.Roaming); 

這是從我的StorageHelper採取: ) – 2013-02-19 11:49:22

0

也許你可以試試這樣寫代碼:

if(string.IsNullOrWhiteSpace(roamingSettings.Values["Sound"])) 
1

我想你想這

/// <summary>Returns if a setting is found in the specified storage strategy</summary> 
/// <param name="key">Path of the setting in storage</param> 
/// <param name="location">Location storage strategy</param> 
/// <returns>Boolean: true if found, false if not found</returns> 
public static bool SettingExists(string key, StorageStrategies location = StorageStrategies.Local) 
{ 
    switch (location) 
    { 
     case StorageStrategies.Local: 
      return Windows.Storage.ApplicationData.Current.LocalSettings.Values.ContainsKey(key); 
     case StorageStrategies.Roaming: 
      return Windows.Storage.ApplicationData.Current.RoamingSettings.Values.ContainsKey(key); 
     default: 
      throw new NotSupportedException(location.ToString()); 
    } 
} 
public enum StorageStrategies 
{ 
    /// <summary>Local, isolated folder</summary> 
    Local, 
    /// <summary>Cloud, isolated folder. 100k cumulative limit.</summary> 
    Roaming, 
    /// <summary>Local, temporary folder (not for settings)</summary> 
    Temporary 
} 

你會這樣稱呼它:http://codepaste.net/gtu5mq

相關問題