我想知道是否存在按鍵音值,但下面的代碼不起作用形成我的Windows商店應用roamingsettings測試,如果存在的價值
if (roamingSettings.Values["Sound"] == null)
我想知道是否存在按鍵音值,但下面的代碼不起作用形成我的Windows商店應用roamingsettings測試,如果存在的價值
if (roamingSettings.Values["Sound"] == null)
「值」是一個集合,其成員可以像這樣檢查。
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");
}
也許你可以試試這樣寫代碼:
if(string.IsNullOrWhiteSpace(roamingSettings.Values["Sound"]))
我想你想這
/// <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
運作良好謝謝:
這是從我的StorageHelper採取: ) – 2013-02-19 11:49:22