【发布时间】:2016-06-27 07:11:28
【问题描述】:
我有一个名为Person 的类,只有姓名、年龄和性别属性。而且我还有一个List<Person> 5 人(现在硬编码,但不相关)。我想通过 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>
问题是我不知道将什么用作数据上下文或项目源或其他什么。 有什么想法吗?
【问题讨论】:
-
ListBox 的 itemssource 应该是你的硬编码列表。
标签: wpf data-binding itemssource