我已經設置了我的DataContext
這樣的:WPF綁定路徑= /不工作?
<Window.DataContext>
<c:DownloadManager />
</Window.DataContext>
哪裏DownloadManager
是Enumerable<DownloadItem>
。然後,我把我的DataGrid
這樣的:
<DataGrid Name="dataGrid1" ItemsSource="{Binding Path=/}" ...
因此,它應該列出所有DownloadItems,對不對?所以,我應該能夠把我列,如:
<DataGridTextColumn Binding="{Binding Path=Uri, Mode=OneWay}"
哪裏Uri
是DownloadItem
的屬性。但它似乎並不喜歡這樣。在視覺屬性編輯器中,它不識別Uri
是一個有效的屬性,所以我猜測我做錯了什麼。
它之前工作,當我有數據網格綁定到Values
,但後來我把那個枚舉出DownloadManager
,並使其本身enumerable。我該如何解決? PS:通過「不工作」我的意思是它不列出任何項目。我已經添加了一些DM的構造函數,所以它不應該是空的。
'路徑= /'試圖找到的'DownloadManager'稱爲'/'一個屬性 - 這永遠不會是正確的。 (如果它是'XmlDataSource',你可以使用'XPath = /',但這是一個完全不同的故事......) – 2010-05-06 20:56:11
@Dan:啊..我剛從屬性編輯器中選擇了「Current Item」,這就是它給我。 – mpen 2010-05-06 20:58:17
@Dan - Path = /將綁定到DataContext中的當前項目(當 DataContext是一個集合時)。這裏有一個很好的資源,我經常在使用綁定路徑時使用:http://www.nbdtech.com/Blog/archive/2009/02/02/wpf-xaml-data-binding-cheat-sheet.aspx – 2010-05-06 21:03:28