0

我的设置页面中有一个城市列表。我希望用户选择一个城市,完成后,我希望将不同的设置保存在独立的存储中。我的列表:

List<Cities> source = new List<Cities>();
source.Add(new Cities() { Name = "Asker", Latitude = "59.83734", Longitude = "10.43595", Datatable = "AskerTable.xml" });
source.Add(new Cities() { Name = "Arendal", Latitude = "58.46151", Longitude = "8.77253", Datatable = "ArendalTable.xml" });

如何将城市名称、纬度和经度以及表格名称写入独立存储,以便在主页中使用?我对用户更改时发生的事情的编程已经走了多远:

    void listPicker_SelectionChanged(object sender, SelectionChangedEventArgs e) 
    { 
    var appStorage = IsolatedStorageFile.GetUserStoreForApplication();
    string fileName="settings.txt";

 using (var file = appStorage.OpenFile(fileName, System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.Write))
    {
         using (var writer = new StreamWriter(file))
               {
                  writer.Write(listPicker.SelectedItems.);
                }
    }
4

1 回答 1

0

You could serialize the list of objects List<Cities> via some serialization format (Xml,Json, etc). Then write it to the stream. Then De-serialize it on the way back out when you need it. I don't know what type the listPicker.SelectedItems is but if its just List<Cities> that would work...

于 2012-05-29T20:35:27.883 回答