Reputation: 838
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
Upvotes: 1
Views: 1383
Reputation: 8592
A good example of ListBox implementation is here
http://www.c-sharpcorner.com/UploadFile/dpatra/534/
Upvotes: 0
Reputation: 292765
[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
Upvotes: 2