虽然wpf 开发有段时间了,但是对于绑定数据这块儿,理解的还是不太深入 。
参考了 http://blog.csdn.net/leftfist/article/details/25333425 的列子,也弄了个简单点的绑定对象列表的试了下。
xaml
代码:
public class Room
{
public string imgSource { set; get; }
public string createrName { set; get; }
public string roomName { set; get; }
public string roomState { set; get; }
public string howmany { set; get; }
public string rowBg { set; get; }
public ImageBrush background { set; get; }
}
List roomList = new List();
for (int i = 0; i < 15; i++)
{
var newitem = new Room()
{
//rowBg = "images/row_background.png",
imgSource = "images/locked.png",
roomName = "room_" + i,
createrName = "name_" + i,
roomState = "sate--" + i,
howmany = "人数_" + i*10,
};
ImageBrush b = new ImageBrush();
b.ImageSource = new BitmapImage(new Uri(new FileInfo("images/row_background.png").FullName, UriKind.Absolute));
b.Stretch = Stretch.Fill;
newitem.background = b;
roomList.Add(newitem);
}
listView1.ItemsSource = roomList;