我有一个名为Person
的类,它只有名称,年龄和性别属性。我也有一个List<Person>
5人(现在硬编码,但不相关)。我想通过XAML将其绑定到一个列表框,因此具有各性能三个的TextBlocks:将列表绑定到WPF中的列表框中
<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应你的硬编码列表。 – lokusking