我在做一個小應用程序來顯示從XML文件中讀取的一些信息。這些信息很簡單隻包含信息,ID和速率已經和它保存在存儲庫如何在Windows Phone中維護變量
static XmlJokeRepository()
{
XDocument loadedData = XDocument.Load("FactsXML.xml");
var data = from query in loadedData.Descendants("Joke")
select new Jokes
{
ID = (int)query.Element("ID"),
Rate = (int)query.Element("Rate"),
Info = (string)query.Element("Info"),
};
countryList = data.ToList();
}
public IList<Jokes> GetCountryList()
{
return countryList;
}
public Jokes GetCountryById(int id)
{
return countryList.FirstOrDefault(c => c.ID == id);
}
在那裏我有維護財產,並已保存在一個名爲類惡搞類。
public class Jokes
{
public int Rate
{
get;
set;
}
public int ID
{
get;
set;
}
public string Info
{
get;
set;
}
}
}
interface JokeRepository
{
IList<Jokes> GetCountryList();
Jokes GetCountryById(int id);
}
其中I呼叫並加載這個XML等上使用該 的InitializeComponent所述的MainPage(); JokeRepository countryRepository = new XmlJokeRepository(); DataContext = countryRepository.GetCountryById(1);
但它的工作,我必須指定哪一個我想要顯示,而不是隻是返回列表並從那裏管理它可以像例如如果用戶點擊下一步,獲得下一個笑話或者其他的東西。我正在尋找一種更通用的方式來做到這一點,並得到我想要的下一個笑話,就像列表並做一個簡單的GetNext()。
此外,在XML中,我只是在文本塊中有綁定笑話。謝謝您的幫助。
我剛剛添加了一個私人的IList數據併發送了一份清單回來,它完成了工作,謝謝反正。 –
Gustavo