我遇到了一个问题,即在显示列表框绑定文本时,没有任何绑定图像。我下载并解析一个xml文件就好了,显示我想要的文本,但是想根据状态显示一个图像。 Linename
和Service
显示OK,但绑定图像根本不显示。 Atype只是用来调用GetImage方法(不是我知道的)。它应该根据状态设置ImageSource,但根本不显示图像。绑定后图像不显示在列表框中
XElement XmlTweet = XElement.Parse(e.Result);
var ns = XmlTweet.GetDefaultNamespace();
listBox1.ItemsSource = from tweet in XmlTweet.Descendants(ns + "LineStatus")
select new FlickrData
{
Linename = tweet.Element(ns + "Line").Attribute("Name").Value,
Service = tweet.Element(ns + "Status").Attribute("Description").Value,
Atype = GetImage(tweet.Element(ns + "Status").Attribute("Description").Value)
};
public String GetImage(String type)
{
FlickrData f = new FlickrData();
switch(type)
{
case "Good Service":
f.Type = new BitmapImage(new Uri("/Images/status_good.png", UriKind.Relative));
break;
case "Minor Delays":
f.Type = new BitmapImage(new Uri("/Images/status_minor.png", UriKind.Relative));
break;
case "Severe Delays":
f.Type = new BitmapImage(new Uri("/Images/status_severe.png", UriKind.Relative));
break;
case "Planned Closure":
f.Type = new BitmapImage(new Uri("/Images/status_minor.png", UriKind.Relative));
break;
}
return "anything";
}
在FlickrData这是一个简单的获取设置与Type
不显示的ImageSource。
public class FlickrData
{
public string Linename { get; set; }
public string Service { get; set; }
public string Detail { get; set; }
public ImageSource Type { get; set; }
public string Atype { get; set; }
}
你是如何设置绑定在用户界面? – 2013-03-21 15:01:28