示例#1
0
        //初始化listbox
        private void InitialCarList()
        {
            List <Car> carList = new List <Car>()
            {
                new Car()
                {
                    Automaker = "Lamborghini", Name = "CarA", Year = "2000", TopSpeed = "340"
                },
                new Car()
                {
                    Automaker = "Lamborghini", Name = "CarB", Year = "2001", TopSpeed = "350"
                },
                new Car()
                {
                    Automaker = "Lamborghini", Name = "CarC", Year = "2002", TopSpeed = "360"
                },
                new Car()
                {
                    Automaker = "Lamborghini", Name = "CarD", Year = "2003", TopSpeed = "370"
                },
            };

            foreach (Car car in carList)
            {
                CarListItemView view = new CarListItemView();
                view.Car = car;
                this.listBoxCars.Items.Add(view);
            }
        }
示例#2
0
        private void listBoxCars_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            CarListItemView view = e.AddedItems[0] as CarListItemView;

            if (view != null)
            {
                this.detailView.Car = view.Car;
            }
        }