开发者

How do I implement favorites in a windows phone 7 application?

So I have an application that reads in data from an XML file that looks like this:

<?xml version="1.0" encoding="utf-8" ?>
<Countries>
  <Country>
    <Name>Germany</Name>
    <Flag>../Images/Germany.png</Flag>
    <ID>1</ID>
    <Description>Germany Description</Description>
    <Capital>Berlin</Capital>
  </Country>
  <Country>
    <Name>Grece</Name>
    <Flag>../Images/Greece.png</Flag>
    <ID>2</ID>
    <Description>Grece Description</Description>
    <Capital>Athens</Capital>
  </Country>
  ...
</Countries>

This data is stored in List countryList. The country class has members for Name, Flag, etc. Now, when displaying all the countries in a listbox on the 'List' page, I have added the functionality to be able to click on a country name, and开发者_如何转开发 be taken to the 'Details' page, where we can view more information about that country that wasn't visible on the 'List' page.

I want to have a star icon, so that when the user clicks on it, the app marks that country as a favorite. How can I implement this efficiently? I thought of having a <Favorite>No</Favorite> for each <Country>, and having a TwoWay binding, and saving the Favorite data to the xml file before the app is closed as part of the cleanup. Is this the best way? Can someone please point me to an example?


Your method is fine. An alternative could be to have a new List that stores a list of ID's that are marked Favourite. Simply check which IDs are in the List and show a star icon next to them.

To save, you can create a simple text file with these values separated by a comma and save this (or simply serialize the List). When you need to load, you can load the file (or deserialize) and put it back into a List. This will save you any DOM manipulation of the XML file and also means that you don't need to store <Favorite>No</Favorite> for every element.

You could try both methods and see which one is more efficient, but space-wise, a separate list would be better. This also results in a lower loading time for the XML file.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜