如何创建 WPF 列表框模板

发布于 2024-08-24 04:36:37 字数 158 浏览 4 评论 0原文

我有一个应用程序,它使用许多列表框,并使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

向日葵 2024-08-31 04:36:37

[namespace].[classname] 是 ToString 方法的默认实现,如果您未指定要显示的内容,则会调用该方法。

您可以使用 DisplayMemberPath 属性来指定要显示的类的哪个成员:

<ListBox ItemsSource="{Binding Persons}" DisplayMemberPath="Name" />

如果您想要对项目的显示方式进行更多控制,您可以定义一个 DataTemplate您的数据类型并将其分配给 ListBoxItemTemplate 属性

[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 :

<ListBox ItemsSource="{Binding Persons}" DisplayMemberPath="Name" />

If you want more control on how the items are displayed, you can define a DataTemplate for your data type and assign it to the ItemTemplate property of the ListBox

若无相欠,怎会相见 2024-08-31 04:36:37

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/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文