2
由于某种原因,每次我重新启动(在浏览器中)Silverlight应用程序时,隔离存储都没有密钥。silverlight隔离存储 - 在应用程序重新启动时不存在
我甚至用下面的代码尝试了香草模板。 事情我已经检查:
始终使用同一端口
在应用程序启动时总是会创建独立存储的条目(永远坚持)
在关机,按键总是存在于独立存储
代码: -
namespace SilverlightApplication1
{
public partial class MainPage : UserControl, INotifyPropertyChanged
{
private string _ChildCount;
public string ChildCount
{
get { return _ChildCount; }
set { NotifyPropertyChangedHelper.SetProperty(this, ref _ChildCount, value, "ChildCount", PropertyChanged); }
}
public MainPage()
{
InitializeComponent();
SaveData();
}
~MainPage()
{
CheckData();
}
private void SaveData()
{
if (!IsolatedStorageSettings.ApplicationSettings.Contains("childCheck"))
{
IsolatedStorageSettings.ApplicationSettings.Add("childCheck", Parent.Create(5, 5));
ChildCount = "Created Children(5)";
}
else
CheckData();
}
private void CheckData()
{
if (IsolatedStorageSettings.ApplicationSettings.Contains("childCheck"))
{
if (((Parent)IsolatedStorageSettings.ApplicationSettings["childCheck"]).Children.Length == 5)
ChildCount = "Children Present";
else
ChildCount = "Parent present without children";
}
else
ChildCount = "Children not found";
}
public class Parent
{
public int Id { get; private set; }
public Child[] Children { get; private set; }
private Parent() { }
public static Parent Create(int id, int childCount)
{
var result = new Parent
{
Id = id,
Children = new Child[childCount]
};
for (int i = 0; i < result.Children.Length; i++)
result.Children[i] = Child.Create(i);
return result;
}
}
public class Child
{
public int Id { get; private set; }
private Child() { }
public static Child Create(int id)
{
return new Child { Id = id };
}
}
public event PropertyChangedEventHandler PropertyChanged;
}
}
任何帮助将受到欢迎。