日期:2014-05-17 浏览次数:20901 次
<Window x:Class="WPF熊俊.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Name="window1" Height="399.259" Width="604.074">
<Grid HorizontalAlignment="Left" Height="319" VerticalAlignment="Top" Width="517">
<ListBox ItemsSource="{Binding ElementName=window1, Path=ListPerson}" DisplayMemberPath="Name" HorizontalAlignment="Left" Height="160" Margin="40,41,0,0" VerticalAlignment="Top" Width="108"/>
</Grid>
</Window>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
ListPerson = new List<Person>()
{
new Person(){Name="张三",Adress="南街"},
new Person(){Name="李四",Adress="北京"},
new Person(){Name="王二",Adress="上海"},
};
}
private List<Person> listperson;
public List<Person> ListPerson
{
get { return listperson; }
set { listperson = value; }
}
}
public class Person
{
public string Name { get; set; }
public string Adress { get; set; }
}