using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
namespace Password
{
public partial class Page : UserControl
{
ComboBox _cars = new ComboBox();
public Page()
{
InitializeComponent();
List<Car> carList = new List<Car>();
carList.Add(new Car() { Name = "Ferrari", Price = 150000 });
carList.Add(new Car() { Name = "Honda", Price = 12500 });
carList.Add(new Car() { Name = "Toyota", Price = 11500 });
ComboBox cb = new ComboBox();
_cars.DisplayMemberPath = "Name";
_cars.ItemsSource = carList;
_cars.SelectedIndex = 2;
_cars.SelectionChanged += new SelectionChangedEventHandler(cb_SelectionChanged);
MyCanvas.Children.Add(_cars);
}
void cb_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
Car selectedCar = (Car) _cars.SelectedItem;
int price = selectedCar.Price;
string carName = selectedCar.Name;
}
}
public class Car
{
public string Name { get; set; }
public int Price { get; set; }
}
}