WPF/C# Binding custom object list data to a ListBox?

后端 未结 4 557
情话喂你
情话喂你 2021-02-05 05:12

I\'ve ran into a bit of a wall with being able to bind data of my custom object list to a ListBox in WPF.

This is the custom object:

public          


        
4条回答
  •  悲哀的现实
    2021-02-05 05:43

    Each item in the list that ListBox shows automatically calls the ToString method to display it, and since you didn't override it, it displays the name of the type.

    So, there are two things you can do here.

    1. Override the ToString method like Sayse suggested.
    2. Use DataTemplate and bind each of your properties seperatly

    In your resource add the template with a key

            
                
                    
                    
                
            
    

    and give it as your listbox ItemTemplate

    
    

提交回复
热议问题