Reputation: 697
I have a ListBox populated by a List of a certain class. However when each element is added to the ListBox its name in the ListBox is its class hierarchy, but I want to be able to rename the items since it is supposed to be a Layer list for rendering teach Listbox item on a screen.
What attribute of the item does ListBox look for when choosing a name for each element? And how can I allow the user to rename items?
Upvotes: 1
Views: 174
Reputation: 61349
Be default, a ListBox
will just call ToString
on every object in its ItemsSource. For a class, this is just the namespace-qualified name unless ToString
is overriden.
There are three ways to change what is displayed:
ToString()
DisplayMemberPath
property to bind to a propertyItemTemplate
You could use a TextBox
in your ItemTemplate
to allow for rename, or another control (elsewhere on the page) that updates the backing property (therefore updating the bound object).
Upvotes: 1