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"));
}
}
}
listbox parent的datacontext绑定到Client实例
GameDetailsPanel.DataContext = client;
列表框的界限如下:
<ListBox.Items>
<Binding Path="Peers"></Binding>
</ListBox.Items>
根据我的理解,这是假设将列表绑定到相对于它的父级的路径 datacontext ..当我运行应用程序时,我收到以下错误:
{"A 'Binding' cannot be used within a 'ItemCollection' collection. A 'Binding' can only be set on a DependencyProperty of a DependencyObject."}
任何想法我做错了。
答案 0 :(得分:2)
您需要将ItemsSource
设置为List
的{{1}}。
Players
答案 1 :(得分:2)
<ListBox.ItemsSource>
<Binding Path="Peers"></Binding>
</ListBox.ItemsSource>