Reputation: 12533
i'm a WPF noob . iv'e got a listbox which is bound to a Property of class Client
public class Client : INotifyPropertyChanged
{
private List<Player> peers ;
public List<Player> Peers
{
get { return peers; }
set
{
peers = value;
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs("Peers"));
}
}
}
the listbox parent's datacontext is bound to a Client instance
GameDetailsPanel.DataContext = client;
the listbox is bounded as follows :
<ListBox.Items>
<Binding Path="Peers"></Binding>
</ListBox.Items>
to my understanding this is suppose to bound the list to the path relative to it's parent's datacontext .. when i run the application i get the following error:
{"A 'Binding' cannot be used within a 'ItemCollection' collection. A 'Binding' can only be set on a DependencyProperty of a DependencyObject."}
any ideas what i'm doing wrong .
Upvotes: 1
Views: 865
Reputation: 26352
You need to set the ItemsSource
to your List
of Players
.
<ListBox ItemsSource="{Binding Peers}">
</ListBox>
Upvotes: 2
Reputation: 12533
o'k i found out what i was doing wrong normally i would dismiss this question .. but maybe it could help out a noob like me some day ..so
<ListBox.ItemsSource>
<Binding Path="Peers"></Binding>
</ListBox.ItemsSource>
Upvotes: 2