If we are storing static data in our Win Phone app, xml files can be used for that.
Following sample explains how to do that:
<CountrList>
<country name="Abkhazia" capital ="Sukhumi" />
<country name="Afghanistan" capital ="Kabul" />
<country name="Albania" capital ="Tirana" />
</CountrList>
we can bind xml data to a list by using following code
<ListBox Name="lstData"
ItemsSource="{Binding}"
DisplayMemberPath="objMyList" />
select new clsWorldList
{
MyName = elem.Attribute("name").Value,
Following sample explains how to do that:
<CountrList>
<country name="Abkhazia" capital ="Sukhumi" />
<country name="Afghanistan" capital ="Kabul" />
<country name="Albania" capital ="Tirana" />
</CountrList>
we can bind xml data to a list by using following code
<ListBox Name="lstData"
ItemsSource="{Binding}"
DisplayMemberPath="objMyList" />
public class clsWorldList
{
public string MyName { get; set; }
public string MyCapital { get; set; }
}
{
public string MyName { get; set; }
public string MyCapital { get; set; }
}
....
....
var xElem = XElement.Load("XML/List.xml");
var objMyList =
from elem in xElem.Descendants("country")
orderby elem.Attribute("name").Value
from elem in xElem.Descendants("country")
orderby elem.Attribute("name").Value
select new clsWorldList
{
MyName = elem.Attribute("name").Value,
MyCapital = elem.Attribute("capital").Value,
};
};
lstData.DataContext = objMyList ;
No comments:
Post a Comment