0

谁能帮我解决这个问题?我正在使用 Visual Studio2010 及其 windows phone 7 应用程序

我创建了 addpet.xaml 和 mypet.xaml。在 mypet.cs 文件中创建了 IsolatedStorageSetting 对象

{

      public static IsolatedStorageSettings settings=IsolatedStorageSettings.ApplicationSettings;

}

我有 5 个文本框,我将其值存储在列表项中。该列表存储在 IsolatedStorageSetting 对象中。

{

        SaveMypet savepet = new SaveMypet();

        savepet.Name = txt_name.ToString();
        savepet.Birthday = txt_birthday.ToString();
        savepet.FavFood = txt_favouritefood.ToString();
        savepet.DocNo = txt_doctorsno.ToString();
        savepet.VacDate = txt_vacdate.ToString();
        savepet.FavToy = txt_favouritetoy.ToString();
        //   savepet.Image1 = image1.Source;

        listMyPet.Add(savepet);
        settings.Add("iso_listMyPet", listMyPet);

}

现在我想在 addpet.cs 中访问这个对象并将其转换为列表,然后想分配给列表框。像这样,我做了但不工作在 addpet.cs 中创建了列表对象

{

     static List<pg_addPet> list_listMyPet = null;

}

       protected override void OnNavigatedTo(NavigationEventArgs e)

{

       list_listMyPet = (List<pg_addPet>)pg_addPet.settings["iso_mypet_list"];
       listbox_mypet.ItemsSource = list_listMyPet;  

}

我的 SaveMypet 课程是

        public class SaveMypet
{
    public string Name { get; set; }
    public string Birthday { get; set; }
    public string FavFood { get; set; }
    public string DocNo { get; set; }
    public string VacDate { get; set; }
    public string FavToy { get; set; }
   // public ImageSource  Image1 { get; set; }

}
4

2 回答 2

0

尝试以下操作:

if(!pg_mypet.settings.TryGetValue("iso_mypet_list", out list_listMyPet)) 
{
  list_listMyPet = new List<pg_addPet>();
}

这将尝试检索该值,如果失败,它将创建一个空列表。

于 2013-07-04T07:23:23.830 回答
0

您已将该settings属性声明为static. 因此,您需要使用类名来访问它:

list_listMyPet = (List<pg_addPet>)pg_mypet.settings["iso_mypet_list"];
于 2013-07-03T14:16:09.680 回答