I was wondering what the best way to perform an if/then/else statement with the contents of an XML file. To be more specific, I want to display one of two images based on the content of a certain filed. For example, if the contents of a description item is "Red", I want to display a red button. If it's "Green", then a green image. This is for a Silverlight WP7 app made in Visual Studio 2010. Here is the context of my code:
public MainPage()
{
InitializeComponent();
Dispatcher.BeginInvoke((Action)(() => DATABASEinfoList.ItemsSource = list));
WebClient DB = new WebClient();
DB.DownloadStringCompleted += new DownloadStringCompletedEventHandler(DATABASEinfo_DownloadStringCompleted);
DB.DownloadStringAsync(new Uri("http://www.URL.com/index.xml"));
}
void DATABASEinfo_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
if (e.Error != null)
return;
XElement xmlitem = XElement.Parse(e.Result);
var list = new Lis开发者_运维问答t<DATABASEinfoViewModel>();
foreach (XElement item in xmlitem.Element("channel").Elements("item"))
{
var title = item.Element("title").Value;
var description = item.Element("description").Value;
list.Add(new DATABASEinfoViewModel
{
Title = title,
Description = description,
});
}
DATABASEinfoList.ItemsSource = list;
}
public class DATABASEinfoViewModel
{
public string Title { get; set; }
public string Description { get; set; }
}
if (xmlitem.Element("color").Value.Equals("Red")) {
// ...
}
精彩评论