Silverlight列表框问题
我正在使用 listBox.ItemsSource = e.Result.Persons
,它是人员的集合。当我希望它显示每个人对象的名字时,列表框显示实际的对象名称。我该怎么做?
I'm using listBox.ItemsSource = e.Result.Persons
, which is a collection of persons. The listbox shows the actual object names when I would like it to show the first name of each person object. How can I do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
使用列表框 ItemTemplate。
像这样的东西。
use Listboxes ItemTemplate.
something like this.
除了其他响应指定的绑定方法之外,您还可以简单地绑定它,如下所示:
In addition to the method of binding specified by the other response, you could simply bind it as follows:
或者使用专用的 “DisplayMemberPath”属性,它可以轻松地完成您想要的操作,没有任何副作用(也没有额外的标记):
对于更复杂的项目表示,请使用模板(见下文)。
Or use the dedicated "DisplayMemberPath" property, which do exactly what you want easily without any side effects (nor additional markup):
For more complicated item representations, use templates (see below).
您可以重写 Persons 对象的 ToString() 方法,以便它显示人员的名字。
You can override the ToString() method of the Persons object so that it display the first name of the person.