我想在Silverlight中填充一個TreeView,但我遇到了一些困難 - 它總是顯示爲空。Silverlight TreeView不會填充
我找到了一個很好的教程(here),我創建了一個新項目並使用C#編寫了它的代碼,並且它完美地工作。我現在試圖將其納入我的項目(使用VB),但它不工作。我的VB代碼如下:
XAML
<UserControl.Resources>
<common:HierarchicalDataTemplate x:Key="myHierarchicalTemplate" ItemsSource="{Binding Items}" >
<TextBlock Text="{Binding myString}" />
</common:HierarchicalDataTemplate>
</UserControl.Resources>
<controls:TreeView Height="200" HorizontalAlignment="Left" Margin="280,464,0,0" Name="TreeView1" VerticalAlignment="Top" Width="120" ItemTemplate="{StaticResource myHierarchicalTemplate}" />
VB代碼:
Public Class myItem
Public myString As String
Public Items As ObservableCollection(Of myItem)
Public Sub New(ByVal myString As String, ByVal ParamArray myItems() As myItem)
Me.myString = myString
Dim itemsObservableCollection = New ObservableCollection(Of myItem)
For Each item As myItem In myItems
itemsObservableCollection.Add(item)
Next
Me.Items = itemsObservableCollection
End Sub
End Class
並填充它:
Dim itemsSource As New ObservableCollection(Of myItem)
itemsSource.Add(New myItem("Hello", New myItem("World"),
New myItem("Foo")))
itemsSource.Add(New myItem("Moo", New myItem("Boo", New myItem("Goo"))))
TreeView1.ItemsSource = itemsSource
我缺少什麼?
編輯:我已經嘗試調試該項目,並且「itemsSource」集合似乎正在生成,並被分配給TreeView1.ItemsSource罰款,但沒有顯示。它是一個顯示綁定問題?
對象必須執行INotifyPropertyChanged – 2011-02-09 11:12:18