我试图存储我在隔离存储中创建的对象列表,并能够通过自动为它们生成标题在列表中显示它们.到目前为止,代码仍然有效,但是一旦我对应用程序进行了逻辑删除并启动它,除了对象列表之外,我的所有数据都会被保存.我认为我的问题可能在于我首先如何初始化列表,或者可能是我如何显示名称.任何帮助表示赞赏.
这段代码在我的App.xaml.cs中:
public partial class App : Application
{
public List<my_type> testList = new List<my_type>();
void loadvalues()
{
IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings;
List<my_Type> L;
if (settings.TryGetValue<List<DrinkSesh>>("Storage", out L))
{ testList = L; }
}
void savevalues()
{
IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings;
settings["Storage"] = testList;
settings.Save();
}
}
Run Code Online (Sandbox Code Playgroud)
此代码在我的mainPage上将项添加到列表中:
(Application.Current as App).testList.Add(new my_type());
Run Code Online (Sandbox Code Playgroud)
这段代码是在不同的页面上将标题实现到屏幕上:
public different_class()
{
{
InitializeComponent();
for (i = 0; i < (Application.Current as App).testList.Count; i++)
{
CreateATextBlock((Application.Current as App).testList[i].Title_ToString(), i);
}
}
private void CreateATextBlock(String title,int num) …Run Code Online (Sandbox Code Playgroud)