List<CLASS> list = new List<CLASS>();

        list = (from query in doc.Descendants("row")
                   select new CLASS
                   {
                       Id = Convert.ToInt64(query.Element("Id").Value),
                       Name = query.Element("Name").Value,
                       title = query.Element("title").Value
                   }).ToList();

        listPicker2.DataContext = list;

How do I display list picker selected item in list picker in windows phone, I have binded list picker in page load event, but every time I select item of list picker items, within an second it automatically selects the first item, how to solve this?

有帮助吗?

解决方案

Ok one trick could be like this

take a global int variable on the top of the page

int refreshCount=0;

after the list gets filled, assign this refreshCount to some int value say 1

    List<CLASS> list = new List<CLASS>();

    list = (from query in doc.Descendants("row")
               select new CLASS
               {
                   Id = Convert.ToInt64(query.Element("Id").Value),
                   Name = query.Element("Name").Value,
                   title = query.Element("title").Value
               }).ToList();

    listPicker2.DataContext = list;
    refreshCount=1;

Now enclose this complete block with a simple condition and your code would become like this

if(refreshCount==0)
{
        List<CLASS> list = new List<CLASS>();
        list = (from query in doc.Descendants("row")
                   select new CLASS
                   {
                       Id = Convert.ToInt64(query.Element("Id").Value),
                       Name = query.Element("Name").Value,
                       title = query.Element("title").Value
                   }).ToList();

        listPicker2.DataContext = list;
        refreshCount=1;
}

By this you should get rid of your problems.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top