Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF Listview binding to ItemSource?

Tags:

I have the following listview, but it doesn't show the actual records, but only the namespace of the object. I wondered if I need to create the columns in XAML for it to show the records and then bind it to some properties of an object or what is wrong with this?

<ListView             Name="ListCustomers"             ItemsSource="{Binding Path=ListOfCustomers}"             SelectedItem="{Binding Path=SelectedCustomer}"             SelectionMode="Single"             IsSynchronizedWithCurrentItem="True"             HorizontalAlignment="Stretch"             VerticalAlignment="Stretch"             MinHeight="100"              ></ListView> 

ListOfCustomers is an ObservableCollection<Customer> type. The actual customers do get loaded into the ObservableCollection, but they are not displayed. What is missing?

like image 867
Tony The Lion Avatar asked Feb 08 '10 12:02

Tony The Lion


1 Answers

You need to select the columns to display as well:

<ListView ItemsSource="{Binding ListOfCustomers}"           SelectedItem="{Binding Path=SelectedCustomer}"           ....>   <ListView.View>     <GridView>       <GridViewColumn Width="140" Header="First Name"          DisplayMemberBinding="{Binding FirstName}"  />       <GridViewColumn Width="140" Header="Last Name"            DisplayMemberBinding="{Binding LastName}" />       <GridViewColumn Width="140" Header="Email Address"          DisplayMemberBinding="{Binding Email}" />       ....     </GridView>   </ListView.View> </ListView> 
like image 100
ChrisF Avatar answered Sep 18 '22 06:09

ChrisF