0

我正在尝试将 Telerik 绑定RadJumpList到存储在 IsolatedStorage 中的 XML 文件。我的一些代码在下面,但它似乎不起作用。我究竟做错了什么?

public IEnumerable<Phones> GetSavedData()
{
IEnumerable<Phones> phoneList = new List<Phones>();

try
{
    using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
    {
        string offlineData = Path.Combine("WPTracker", "Offline");
        string offlineDataFile = Path.Combine(offlineData, "phones.xml");
        IsolatedStorageFileStream isoFileStream = myIsolatedStorage.OpenFile(offlineDataFile, FileMode.Open);

        if (myIsolatedStorage.FileExists(offlineDataFile))
        {
            using (XmlReader xmlReader = XmlReader.Create(isoFileStream))
            {
                XmlSerializer deserializer = new XmlSerializer(typeof(List<Phones>));
                List<Phones> phones = deserializer.Deserialize(xmlReader) as List<Phones>;

                phones.Sort(
                    new Comparison<Phones>((Phones p1, Phones p2) =>
                    {
                        return p1.FullName.CompareTo(p2.FullName);
                    }));

                this.radJumpList1.ItemsSource = phones;

                return phones;
            }
        }
        else
        {
            var update = new UpdateDatabase();
            update.UpdateData();

            GetSavedData();
        }
    }
}
catch (IsolatedStorageException)
{
    MessageBox.Show("There was an error retireving the data from Isolated Storage.", "The subscriber you are trying to reach can not be located.", MessageBoxButton.OK);
}

return phoneList;           
}

我认为这与从 IsolatedStorage 读取 XML 文件有关,因为我收到此错误:

[ExceptionMessage]:[There is an error in XML document (1, 2).] at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, Object events) at System.Xml.Serialization.XmlSerializer.Deserialize(TextReader textReader) at WPTracker.ViewModels.Phones.PhoneMainView.GetSavedData() at WPTracker.ViewModels.Phones.PhoneMainView.OnNavigatedTo(NavigationEventArgs e) at Microsoft.Phone.Controls.PhoneApplicationPage.InternalOnNavigatedTo(NavigationEventArgs e) at Microsoft.Phone.Controls.PhoneApplicationPage.Microsoft.Phone.Controls.IPhoneApplicationPage.InternalOnNavigatedToX(NavigationEventArgs e) at System.Windows.Navigation.NavigationService.RaiseNavigated(Object content, Uri uri, NavigationMode mode, Boolean isNavigationInitiator, IPhoneApplicationPage existingContentPage, IPhoneApplicationPage newContentPage) at System.Windows.Navigation.NavigationService.CompleteNavigation(DependencyObject content, NavigationMode mode) at System.Windows.Navigation.NavigationService.ContentLoader_BeginLoad_Callback(IAsyncResult result) at System.Windows.Navigation.PageResourceContentLoader.BeginLoad_OnUIThread(AsyncCallback userCallback, PageResourceContentLoaderAsyncResult result) at System.Windows.Navigation.PageResourceContentLoader.<>c__DisplayClass4.<BeginLoad>b__0(Object args)]

如果需要,我可以附上 XML 文件的副本。它基本上是来自 Azure 移动服务的表。

更新

这是我的一些代码的链接(zip 文件)

  • UpdateXML.cs是我用来从 Azure 下载数据然后将其保存到 XML 文件中的工具。
  • PhoneMainViewPhones定义类的位置和GetSavedData代码的位置
  • phones.xml是来自的 XML 文件UpdateXML.cs

SkyDrive ZIP 文件

4

0 回答 0