0
votes

I have a question. In my WP8.1 RT project, I have been asked to implement a ListView to select a list of countries. Can I have them probably in a text file and have that data bound against the ListView? Or what would be the easiest way to do this? I would like to prefer the former, but if there is an easier (latter) way to do it, i'd be happy to.

BTW, I've tried to have a .cs file with a list of countries (hard coded to the list) and bound it to he ListView. As a desperate measure, I have hard coded the list of countries to the ListView directly (which i dont prefer, because it is too easy and unethical). I need to use the ListView because I will need to implement SemanticZoom.

1

1 Answers

2
votes

The ideal data source is an XML file, a well-formed XML is easier to parse than a plain text file.

Parse an XML using Linq to XML is as simple as these two lines of code. I find an example for your reference.

XDocument loadedData = XDocument.Load("Countries.xml");

var countries = from query in loadedData.Descendants("Country").
           select new Country()...

Then bind the list to the ListView

listView1.ItemsSource = countries;

And you also need to define an ItemTemplate for the ListView. This is an example for this part.