English 中文(简体)
Windows 电话 7 Listbox 没有更新
原标题:Windows Phone 7 Listbox not updating

我从互联网上取出一个 XML 文件, 并把它加载到手机上。 一切正常, 减去未更新应用程序初始负荷的列表框 。

应用程序的简单路径如下:

程序加载时, 如果它连接到互联网, 它会运行更新联系人方法。 如果它没有, 它会检查它是否是第一个负载, 如果是, 它会通知用户在运行应用程序之前连接到移动或无线网络, 否则它会装入旧的数据 。

在更新方法中, 它会检查一个网络服务, 以查看自上次更新以来是否有更新。 如果第一次更新, 它会说有2000年更新, 迫使更新。 如果更新数大于零, 它会运行下载, 然后加载数据( 这里的问题是这里的问题), 否则它会装入旧的数据( 当前的数据 ) 。

问题在于下载后, 它不会加载数据。 这是上述项目的代码 。

GetData 函数 :

private void getData()
        {
            try
            {
                using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
                {
                    IsolatedStorageFileStream isoFileStream = myIsolatedStorage.OpenFile("contacts.xml", FileMode.Open);
                    using (StreamReader reader = new StreamReader(isoFileStream))
                    {
                        XElement xmlContact = XElement.Parse(reader.ReadToEnd());
                        lstContacts.ItemsSource = from contact in xmlContact.Descendants("contact")
                                                               select new ContactItem
                                                               {
                                                                   ImageSource = contact.Element("Image").Value,
                                                                   FName = contact.Element("FName").Value,
                                                                   LName = contact.Element("LName").Value,
                                                                   Extension = contact.Element("Extension").Value,
                                                                   Email = contact.Element("Email").Value,
                                                                   Cell = contact.Element("Cell").Value,
                                                                   Title = contact.Element("TitleName").Value,
                                                                   Dept = contact.Element("deptName").Value,
                                                                   Office = contact.Element("officename").Value,
                                                                   ID = contact.Element("ID").Value
                                                               };
                    }
                }
            }
            catch
            {
            }
        }

更新函数 :

void contact_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
        {
            if (e.Error != null)
            {
                return;
            }

            XElement xmlContact = XElement.Parse(e.Result);
            string updates = xmlContact.Element("updates").Element("number").Value;
            if (firstrun)
            {
                updates = "2000";
                settings["firstRun"] = (bool)false;
            }
            MessageBox.Show(updates);
            if (Convert.ToInt32(updates) > 0)
            {
                MessageBox.Show("Updating Contacts");
                ContactReader cr = new ContactReader("http://domain.tld/RLContactApp/getContactsWP7.php?sqlQueryType=C&lastUpdated=01%2F01%2F2000&format=xml", "contacts.xml");
                bool downloaded = cr.Download();
                if (downloaded)
                {
                    getData();
                }
            }
            else
            {
                MessageBox.Show("Not Updating Contacts");
                getData();
            }

        }

我正在寻找一种方法, 使数据被装入列表框, 而不告诉用户关闭应用程序并重新装入它 。

非常感谢任何帮助。

最佳回答

将您 Linq 查询转换为结果, 以.toList () 的方式在结尾处类似 。

  lstContacts.ItemsSource = (from contact in xmlContact.Descendants("contact")
                                                               select new ContactItem
                                                               {
                                                                   ImageSource = contact.Element("Image").Value,
                                                                   FName = contact.Element("FName").Value,
                                                                   LName = contact.Element("LName").Value,
                                                                   Extension = contact.Element("Extension").Value,
                                                                   Email = contact.Element("Email").Value,
                                                                   Cell = contact.Element("Cell").Value,
                                                                   Title = contact.Element("TitleName").Value,
                                                                   Dept = contact.Element("deptName").Value,
                                                                   Office = contact.Element("officename").Value,
                                                                   ID = contact.Element("ID").Value
                                                               }).ToList<ContactItem>();

现在, 这将执行查询, 返回列表, 并能够绑定数据 。

try with this (query }).ToList();

问题回答

暂无回答




相关问题
how to represent it in dtd?

I have two element action and guid. guid is a required field when action is add. but when action is del it will not appear in file. How to represent this in dtd ?

.Net application configuration add xml-data

I need to add xml-content to my application configuration file. Is there a way to add it directly to the appSettings section or do I need to implement a configSection? Is it possible to add the xml ...

XStream serializing collections

I have a class structure that I would like to serialize with Xstream. The root class contains a collection of other objects (of varying types). I would like to only serialize part of the objects that ...

MS Word splits words in its XML format

I have a Word 2003 document saved as a XML in WordProcessingML format. It contains few placeholders which will be dynamically replaced by an appropriate content. But, the problem is that Word ...

Merging an XML file with a list of changes

I have two XML files that are generated by another application I have no control over. The first is a settings file, and the second is a list of changes that should be applied to the first. Main ...

How do I check if a node has no siblings?

I have a org.w3c.dom.Node object. I would like to see if it has any other siblings. Here s what I have tried: Node sibling = node.getNextSibling(); if(sibling == null) return true; else ...

Ordering a hash to xml: Rails

I m building an xml document from a hash. The xml attributes need to be in order. How can this be accomplished? hash.to_xml

热门标签