我有一个 Windows Phone 7 应用程序的列表框,它显示从 XML 提要解析的信息。我希望能够更改列表框中字体的颜色,具体取决于从 XML 提要解析的值。我已经搜索并不能完全找到我正在寻找的东西。这是我的代码:
foreach (var item in doc.Descendants("station"))
{
if (item.Element("name").Value == dest)
{
listBox1.Items.Add(item.Element("name").Value);
listBox1.Items.Add("Last Updated:");
listBox1.Items.Add(item.Element("date").Value);
listBox1.Items.Add(item.Element("time").Value);
foreach (var item1 in item.Descendants("eta"))
{
listBox1.Items.Add(item1.Element("destination").Value);
listBox1.Items.Add(item1.Element("estimate").Value);
}//foreach
}//if
}//outer foreach
我想要的是,例如,
if item.Element("name").Value="Fremont" and item1.Element("destination").Value="Daly City",
then listBox1.Items.Add(item1.Element("destination").Value);
例如,将显示绿色文本(对于“名称”和“目的地”的不同值,依此类推)。我发现的大多数示例都是针对 WPF 或 WP7 以外的其他东西的。