日期:2014-05-17 浏览次数:21149 次
class Person
{
public string Name { get; set; }
public string Adress { get; set; }
public int Age { get; set; }
}
<Grid HorizontalAlignment="Left" Height="368" VerticalAlignment="Top" Width="596"> <ListBox Name="listBox" DisplayMemberPath="Name" HorizontalAlignment="Left" Height="165" Margin="175,40,0,0" VerticalAlignment="Top" Width="120"/> </Grid>
public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); list = new ObservableCollection<Person>() { new Person(){Name="张三",Adress="北京",Age=43}, new Person(){Name="李四",Adress="美国",Age=52}, new Person(){Name="王五",Adress="上海",Age=45}, listBox.ItemsSource=list; }; } ObservableCollection<Person> list; }