我有一个变量用在我所有的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