我有一個變量用在我所有的10頁中,我應該在哪裏存儲它以便它可以被所有頁面訪問?通過將變量保存在APPDELEGATE
中,可以在iOS中完成相同的任務。 Windows Phone中的解決方案是什麼?在windows phone中存儲應用程序通用數據的位置?
0
A
回答
0
你應該看看some background reading,以幫助IsolatedStorageSettings
示例代碼 希望這將幫助你
public class AppSettings
{
// Our settings
IsolatedStorageSettings settings;
// The key names of our settings
const List<String> PropertyIdList = null;
const List<String> FavPropertyIdList = null;
const string SearchSource = null;
const string[] Suggestions = null;
const string PropertyId = null;
const string AgentContactInfo = null;
const string AgentShowPhoto = null;
/// <summary>
/// Constructor that gets the application settings.
/// </summary>
public AppSettings()
{
// Get the settings for this application.
settings = IsolatedStorageSettings.ApplicationSettings;
}
/// <summary>
/// Update a setting value for our application. If the setting does not
/// exist, then add the setting.
/// </summary>
/// <param name="Key"></param>
/// <param name="value"></param>
/// <returns></returns>
public bool AddOrUpdateValue(string Key, Object value)
{
bool valueChanged = false;
// If the key exists
if (settings.Contains(Key))
{
// If the value has changed
if (settings[Key] != value)
{
// Store the new value
settings[Key] = value;
valueChanged = true;
}
}
// Otherwise create the key.
else
{
settings.Add(Key, value);
valueChanged = true;
}
return valueChanged;
}
/// <summary>
/// Get the current value of the setting, or if it is not found, set the
/// setting to the default setting.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="Key"></param>
/// <param name="defaultValue"></param>
/// <returns></returns>
public T GetValueOrDefault<T>(string Key, T defaultValue)
{
T value;
// If the key exists, retrieve the value.
if (settings.Contains(Key))
{
value = (T)settings[Key];
}
// Otherwise, use the default value.
else
{
value = defaultValue;
}
return value;
}
}
0
根據您的意見,如果你有一個公共屬性,如:
public string MyStaticVariable { get; set; }
MyStaticVariable = "SomeValue";
在您的App.xaml.cs中定義,您可以通過以下方式訪問它:
App.MyStaticVariable;
我的意見:如果你正在談論1個變量,它可以在應用程序啓動時定義,隔離存儲只是矯枉過正。
相關問題
- 1. 在windows phone應用程序中存儲和獲取數據
- 2. Windows應用程序存儲位置
- 3. 將數據存儲在GUI應用程序中的位置?
- 4. localForage數據將存儲在iPad應用程序中的位置?
- 5. 應用程序數據在Windows 7和Vista中的存儲位置
- 6. SQLite數據庫存儲在Windows Phone 8.1中的位置
- 7. 應用程序在Windows Phone 8中的應用程序通信
- 8. 在Windows Store應用程序中存儲瓷磚位置
- 9. Windows 7 Phone應用程序存儲憑據的最佳方式
- 10. 在Android上存儲應用程序數據的位置?
- 11. 存儲Web應用程序試用數據的最佳位置
- 12. 在Windows上存儲應用程序日誌文件的位置
- 13. 在Windows Phone 8.1通用應用程序中設置起始頁
- 14. 本地數據存儲 - 通用Windows應用程序
- 15. 如何在windows phone中存儲應用程序狀態
- 16. 在Shiny應用程序中存儲Twitter憑據的位置?
- 17. 將用戶數據存儲在Windows 8 metro應用程序中
- 18. 存儲應用程序全局數據的位置?例如:
- 19. 存儲應用程序數據的位置
- 20. 存儲應用程序數據的位置?
- 21. windows phone 7的隔離存儲位置?
- 22. Windows Phone 8.1到通用應用程序
- 23. 通用應用程序Windows Phone方向
- 24. 存儲在移動應用程序中的數據(Windows 8)
- 25. Windows Phone中的地理位置HTML應用程序不工作
- 26. 本地保存圖像在Windows Phone 8.1通用應用程序
- 27. 將數據庫憑據存儲在Web應用程序中的位置?
- 28. 將從Web服務接收的數據存儲在windows phone 7應用程序的隔離存儲中
- 29. 在Windows Phone 7中存儲數據
- 30. 在Windows Phone中存儲敏感數據
您正在使用哪種語言?在C#中,您可以使用App.cs或隔離存儲器 –
好的!如果我在App.xaml.cs中保存一個變量,那麼我怎樣才能在頁面1中引用它? – Aju