【问题标题】:Why IsolatingStorageSettings is empty when i restart my APP ? (WP8)为什么当我重新启动我的 APP 时 IsolatingStorageSettings 为空? (WP8)
【发布时间】:2014-03-04 16:04:34
【问题描述】:

我使用 IsolatingStorageSetting 来存储对象集合。它在我的应用程序运行时运行良好,但当我重新启动它时...集合为空...为什么它不将我的对象集合保存在内存中。?

 private  void llsElements_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {

            LongListSelector llselement = null;
            listElementCollection.Clear();

            if (sender != null)
                llselement =(LongListSelector)sender;

            if(llselement.SelectedItem!=null)
            {
               BdeskElement bdelement=(BdeskElement)llselement.SelectedItem;

               if (bdelement.TypeElement == BdeskElement.BdeskTypeElement.File)
               {

                   if (!IsolatedStorageSettings.ApplicationSettings.Contains(bdelement.URLElement))//IsCached? =>NON
                   {

                       if (IsolatedStorageSettings.ApplicationSettings.Count >= 100)//Si la liste des fichiers en cache est pleine
                       {
                           string KeyOldestElement = IsolatedStorageSettings.ApplicationSettings.Last().Key;
                           IsolatedStorageSettings.ApplicationSettings.Remove(KeyOldestElement);//on supprime le dernier élément de la liste
                           if (IsolatedStorageOperations.IsFileSaved(KeyOldestElement+bdelement.Extension))
                           IsolatedStorageOperations.DeleteFile(KeyOldestElement+bdelement.Extension);

                       }

                       IsolatedStorageSettings.ApplicationSettings.Add(bdelement.URLElement, bdelement);//on ajoute notre élément

                        DownloadAndReadFile(bdelement);

                   }

                   else  //Si le fichier est deja présent dans la liste (donc déja en cache)
                   {
                       if (IsFileModified(bdelement, IsolatedStorageSettings.ApplicationSettings[bdelement.URLElement]))//compare la version téléchargée et la version en cache/ les versions sont identiques
                       {
                           string FileNameFormated = bdelement.URLElement.Replace("/", "_").Substring(7, bdelement.URLElement.Length - 7);
                           if (IsolatedStorageOperations.IsFileSaved(FileNameFormated))
                           {
                               MessageBox.Show("Le fichier est lu dans le cache");
                               byte[] Encryptedbytefile = IsolatedStorageOperations.GetFile((FileNameFormated));
                               byte [] UnCryptedByteFile=EncryptedString.DecryptDataToData(Encryptedbytefile);
                               IsolatedStorageOperations.SaveToFile(UnCryptedByteFile, "FileToRead" + bdelement.Extension);
                               IsolatedStorageOperations.ReadFile("FileToRead"+bdelement.Extension);

                           }

                       }

                       else//les versions sont différentes
                       {
                           IsolatedStorageSettings.ApplicationSettings.Remove(bdelement.URLElement);//supprime l'ancienne version
                           IsolatedStorageSettings.ApplicationSettings.Add(bdelement.URLElement, bdelement);//ajoute la nouvelle

                           DownloadAndReadFile(bdelement);
                       }


                   }
               }
               else if (bdelement.TypeElement == BdeskElement.BdeskTypeElement.Folder)
               {

                   //l'élément cliqué devient l'élément courant
                   App.CurrentFolder = bdelement;
                   //On raffiche la page
                   NavigationService.Navigate(new Uri(String.Format("/Views/BDocs/FolderView.xaml?id={0}", Guid.NewGuid().ToString()), UriKind.Relative));

               }
            }
 IsolatedStorageSettings.ApplicationSettings.Save(); //EDITED
            }

编辑

关于保存方法的问题

信息补充:无法序列化类型“System.Windows.Media.ImageSource”。考虑使用 DataContractAttribute 属性对其进行标记,并使用 DataMemberAttribute 属性标记您想要序列化的所有成员。或者,您可以确保该类型是公共的并且有一个无参数的构造函数 - 然后该类型的所有公共成员都将被序列化,并且不需要任何属性。

【问题讨论】:

  • 图像可能很难保存。如果您仍然遇到问题,请查看此免费库。 EZ_Iso.dll 它内置了保存图像的功能。你只需要打一个电话。 anthonyrussell.info/postpage.php?name=2

标签: memory windows-phone-8 settings isolatedstorage


【解决方案1】:

可能是因为你没有保存它 - 当你完成它时尝试使用IsolatedStorageSettings.ApplicationSettings.Save()

当然,当你重新启动模拟器时它不会工作 - 重新启动后它是一个新的实例。

EDIT - 在 OP 的编辑之后

您不能序列化 ImageSource - 类似的问题是 here。而是考虑序列化 ImagePath。

【讨论】:

  • 啊,是的,在我发布此消息 30 秒后,我明白了我的错误……但我遇到了一个我不明白的错误……我编辑了帖子……
  • 对不起,我的意思是当我重新启动应用程序时......哦,该死的我的对象有一个属性是 BitmapImage......我想问题来自那里......这真的很烦人......:(谢谢为你的帮助;)
  • @PaulMartinez 考虑序列化 ImagePath,如果你真的需要序列化 ​​Image,this answer might help
猜你喜欢
  • 2015-09-05
  • 1970-01-01
  • 2023-03-07
  • 1970-01-01
  • 2022-11-15
  • 1970-01-01
  • 2019-08-22
  • 2010-10-12
  • 2014-06-07
相关资源
最近更新 更多