我有一个名为
Person
的类,只有姓名、年龄和性别属性。我也有一个包含5个人的List<Person>
(现在是硬编码的,但不相关)。我希望通过XAML将它绑定到ListBox上,使其具有每个属性的三个TextBlock:<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel>
<TextBlock Text="{Binding Path=name}" />
<TextBlock Text="{Binding Path=gender}" />
<TextBlock Text="{Binding Path=age}" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
问题在于我不知道该用什么作为数据上下文或项源,还有其他的选择。有什么想法吗?