I have a WPF ListBox as follows:
<ListBox x:Name="myListBox" ItemsSource="{Binding}" Visibility="Visible" Width="Auto" SelectionMode="Single" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" MinWidth="150">
</ListBox>
private ObservableCollection<MyClass> _myCollection;
private ListBox _listBox;
protected virtual void GetControls()
{
object value;
if ((value = GetTemplateChild("myListBox")) != null)
{
_listBox = value as ListBox;
if (_listBox != null)
{
if (_listBox.ItemsSource == null)
_listBox.ItemsSource = _myCollection;
}
}
}
private void LoadItems()
{
List<MyClass> items = await GetAllItemsForDisplay();
_myCollection.AddRange(verbs.AsParallel().OrderBy(v => v?.DisplayName));
}
This result in all the items getting listed in the listbox but the display text is My.NameSpace.MyCLass. When in fact I want to display the DisplayName property of MyClass.
How can I do this? How can I set the value for Display equal to MyClass.DisplayName