2009-11-02 43 views

回答

9

你有两个选择。

最简单的方法是将您的ListBox的DisplayMemberPath属性设置为“标题”。

如果您不仅要设置显示的内容,还要设置用于显示它的控件的类型,然后设置列表框的 ItemTemplate

为了您的目标,我会推荐第一个选项。

+0

非常感谢Andrew ......只是我正在寻找的答案! – Woody

2

您可以在ListBoxItemTemplate属性设置DataTemplate

<ListBox ItemSource="{Binding}"> 
    <ListBox.ItemTemplate> 
    <DataTemplate DataType="tfs:WorkItem"> 
     <StackPanel> 
     <TextBlock Text="{Binding Title}" /> 
     <!-- Others --> 
     </StackPanel> 
    </DataTemplate> 
    </ListBox.ItemTemplate> 
</ListBox> 
+1

这是一种非常复杂的方式,可以在一行中完成DisplayMemberPath的功能。 – Ray

+0

@ Ray同意,只有在设置更复杂的用户界面时才使用它。 – bendewey