Here's the way it fits together in a nutshell.
First, you define a model which holds your data for binding.
public sealed class MyListBoxItem
{
public string Field1 {get;set;}
public string Field2 {get;set;}
public string Field3 {get;set;}
}
Now, you have to have a class that holds these models for binding. This type is often called the ViewModel; it presents information to the View for binding based on user input from the View. Its public properties are typically ObservableCollections and DependencyProperties so that changes in the ViewModel will be automatically picked up by the View (the UI):
public sealed class MyViewModel
{
public ObservableCollection<MylistBoxItem> Items {get;private set;}
public MyViewModel()
{
Items = new ObservableCollection<MyListBoxItem>();
Items.Add(new MyListBoxItem{Field1="One", Field2="Two",Filed3="Three"};
}
}
Within the codebehind for your UI, the "View", you instantiate your ViewModel and set it as the DataContext for your View.
public MyView()
{
this.DataContext = new MyViewModel();
}
this is important as the DataContext "flows" through the visual tree. It is available to every child element on which it is set.
To display the items, I must bind the ItemsSource of the ListView to the Items property of the DataContext (this is understood). Each row within the ListView has its DataContext set to each individual MyViewModel in the Items property. So you must bind each display member to the properties of the MyListBoxItem.
<ListView Name="RecordListView" ItemsSource="{Binding Items}">
<ListView.View>
<GridView>
<GridView.Columns>
<GridViewColumn Header="1" Width="Auto" DisplayMemberBinding="{Binding Path=Field1}" />
<GridViewColumn Header="2" Width="50" DisplayMemberBinding="{Binding Path=Field2}" />
<GridViewColumn Header="3" Width="100" DisplayMemberBinding="{Binding Path=Field3}" />
</GridView.Columns>
</GridView>
</ListView.View>
</ListView>
To understand this whole process better, search for high-rated questions here tagged [MVVM].
ALSO, to help debug your bindings, configure debugging for verbose databinding:
