如何创建 WPF 列表框模板
我有一个应用程序,它使用许多列表框,并使用 listBox.ItemsSource 将数据附加到它们。问题是它创建了像[namespace].[class_name]这样的条目。
我如何创建一个模板,它将替换条目,例如。类“名称”字段?
我期待尽快收到您的来信 马修·W
I've got an application, which uses many listBoxes with data attached to them using listBox.ItemsSource. The problem is it creates entries like [namespace].[class_name].
How can I create a template, which will replace entries with, eg. class "Name" field?
I look forward to hear from you soon,
MattheW
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
[namespace].[classname] 是
ToString
方法的默认实现,如果您未指定要显示的内容,则会调用该方法。您可以使用
DisplayMemberPath
属性来指定要显示的类的哪个成员:如果您想要对项目的显示方式进行更多控制,您可以定义一个
DataTemplate
您的数据类型并将其分配给ListBox
的ItemTemplate
属性[namespace].[classname] is the default implementation of the
ToString
method, which is called if you don't specify what to display.You can use the
DisplayMemberPath
property to specify which member of the class you want to display :If you want more control on how the items are displayed, you can define a
DataTemplate
for your data type and assign it to theItemTemplate
property of theListBox
ListBox 实现的一个很好的例子在这里
http://www.c-sharpcorner.com /UploadFile/dpatra/534/
A good example of ListBox implementation is here
http://www.c-sharpcorner.com/UploadFile/dpatra/534/