111,075
社区成员




public partial class MainWindow : Window
{
public class Customer:INotifyPropertyChanged //定义的类,用于添加到List
{
public string name;
public string imageUrl;
public string sex;
public string age;
public string Name
{
get { return name; }
set { name = value; OnPropertyChanged(new PropertyChangedEventArgs("Name")); }
}
public string ImageUrl
{
get { return imageUrl ;}
set { imageUrl = value; OnPropertyChanged(new PropertyChangedEventArgs("ImageUrl")); }
}
public string Sex
{
get { return sex;}
set { sex = value; OnPropertyChanged(new PropertyChangedEventArgs("Sex")); }
}
public string Age
{
get { return age;}
set { age = value; OnPropertyChanged(new PropertyChangedEventArgs("Age")); }
}
#region INotifyPropertyChanged 成员
public event PropertyChangedEventHandler PropertyChanged;
public void OnPropertyChanged(PropertyChangedEventArgs e)
{
if (PropertyChanged != null)
{
PropertyChanged(this, e);
}
}
#endregion
}
List<Customer> listCustomer = new List<Customer>(); //数据源
public MainWindow() //构造函数
{
this.InitializeComponent();
listCustomer.Add(new Customer() { ImageUrl = "Pic/P_1.png", Name = "hehe1", Sex = "男", Age = "12" });
listview.DataContext = listCustomer; //此处添加绑定
}
private void button1_Click(object sender, RoutedEventArgs e)
{
listCustomer.Add(new Customer() { ImageUrl = "Pic/P_5.png", Name = "hehe2", Sex = "女", Age = "16" });
}