类维护一个arraylist,如何把arraylist绑定到listbox上?希望arraylist里内容变化时,listbox上能相应变化。
list = new ArrayList();
listBox1.DataSource = list;
listBox1.DataBind();
我像上面这么用,显示:System.Windows.Controls.ListBox' does not contain a definition for 'DataSource'能通过xaml将lixtbox item绑定到一个类的集合吗?谢谢!
list = new ArrayList();
listBox1.DataSource = list;
listBox1.DataBind();
我像上面这么用,显示:System.Windows.Controls.ListBox' does not contain a definition for 'DataSource'能通过xaml将lixtbox item绑定到一个类的集合吗?谢谢!
所以我不确定是否listbox会和arraylist保持同步
同时,Model类的属性,要使用DependencyProperty,如:
public static readonly DependencyProperty StudentIpProperty =
DependencyProperty.Register("StudentPcIp", typeof(string),
typeof(StudentInfo), new UIPropertyMetadata(null));
/// <summary>
/// 客户端地址
/// </summary>
public string StudentPcIp
{
get { return (string)GetValue(StudentIpProperty); }
set { SetValue(StudentIpProperty, value); _studentPcIpNoDependencyProperty = value; }
}
这样,WPF才会自动关联更新