2012-02-20 101 views
1

我是WPF noob。 iv'e得到了列表框這勢必類客戶的財產binding itemscontrol列出哪些是父級datacontext中的屬性

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")); 
     } 
    } 
} 

列表框父母的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."} 

任何想法,我做錯了。

回答

2

您需要將ItemsSource設置爲ListPlayers

<ListBox ItemsSource="{Binding Peers}"> 
</ListBox> 
2

o'k我發現我在做什麼錯 通常我會關閉這個問題..但也許它可以幫幫忙,一個小白和我一樣 有一天..所以

   <ListBox.ItemsSource> 
        <Binding Path="Peers"></Binding> 
      </ListBox.ItemsSource> 
相關問題