1.<ListBox x:Name="listName" Width="248" Height="60">
<ListBoxItem Content="张三"/>
<ListBoxItem Content="李四"/>
<ListBoxItem Content="王五"/>
<ListBoxItem Content="赵柳"/>
</ListBox>
<TextBlock Width="248" Height="24" Text="你所选中的人员名称:" />
<TextBlock Width="248" Height="24" Text="{Binding ElementName=listName, Path=SelectedItem.Content}">
2. <DataGrid x:Name="dsGrid" AutoGenerateColumns="False" ItemsSource="{Binding Students}" CanUserAddRows="False">
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding Name}" Width="100" Header="名称" />
<DataGridTextColumn Binding="{Binding Age}" Width="80" Header="年龄" />
<DataGridTextColumn Binding="{Binding Country}" Width="150" Header="国家" />
</DataGrid.Columns>
</DataGrid>
public class Student
{
public string Name { get; set ;}
public string Age { get; set ; }
public string Country { get; set; }
}
public List<Student> GetStudentList()
{
Student liang = new Student();
liang.Age = "1";
liang.Name = "丘";
liang.Country = "中国";
}
this.DataContext = this;
List<Student> students = GetStudentList();
dsGrid.ItemsSource = students;