//初始化ListBox private void InitialCarList() { List <cCar> carList = new List <cCar>() { new cCar() { Automaker = "Lamborghini", Name = "Diablo", Year = "1990", TopSpeed = "340" }, new cCar() { Automaker = "Lamborghini", Name = "Murcielago", Year = "2001", TopSpeed = "353" }, new cCar() { Automaker = "Lamborghini", Name = "Gallardo", Year = "2003", TopSpeed = "325" }, new cCar() { Automaker = "Lamborghini", Name = "Reventon", Year = "2008", TopSpeed = "356" }, }; foreach (cCar car in carList) { CarListItemView view = new CarListItemView(); view.Car = car; this.listBoxCars.Items.Add(view); } }
private void ListBoxCars_SelectionChanged(object sender, SelectionChangedEventArgs e) { CarListItemView view = e.AddedItems[0] as CarListItemView; if (view != null) { this.detailView.Car = view.Car; } }