可能重复:
XAML Code for TREEVIEW
以下是XAML中TreeView的代码:
<TreeView Height="338" HorizontalAlignment="Left" Margin="6,6,0,0"
Name="DisksTreeView1" VerticalAlignment="Top" Width="293">
<TreeView.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Image Source="{Binding ImagePath}" Width="32" Height="32"/>
<TextBlock Text="{Binding Namee}"/>
</StackPanel>
</DataTemplate>
</TreeView.ItemTemplate>
</TreeView>
以下是背后的代码:
Dim adpt As New DatabaseDearDataSetTableAdapters.DiskListTableAdapter
For Each k As KeyValuePair(Of String, GenreSet) In GenreSetDictionary
Dim t As New TreeNodeSet
t.Genre = True
t.Imagepath = k.Value.IconPath
t.Namee = k.Key
Dim pnode As New TreeViewItem
pnode.DataContext = t
For Each z As DatabaseDearDataSet.DiskListRow In adpt.GetDataByGenre(t.Namee)
Dim tt As New TreeNodeSet
tt.Genre = False
tt.Imagepath = IconDictionary(z.DiskIcon).IconPath
tt.Namee = z.DiskName
Dim cnode As New TreeViewItem
cnode.DataContext = tt
pnode.Items.Add(cnode)
Next
DisksTreeView1.Items.Add(pnode)
Next
我能够将pnode
添加到TreeView中,并且所有节点断点都被命中。问题是在TreeView中,我只能看到父视图箭头,其余的名称,图像等都没有显示出来。就像这样:
Sample picture http://img855.imageshack.us/img855/4231/unledzyc.jpg
我该如何解决这个问题?
答案 0 :(得分:0)
在您的代码隐藏中,您正在创建TreeViewItem
个实例并将它们添加到TreeView中。但您需要做的是 - 以分层方式定义模型类,将顶级项集合绑定到ItemsSource
的{{1}}属性,并使用TreeView
代替{ {1}}显示嵌套项目。
答案 1 :(得分:0)
上述问题的答案显示在以下页面: XAML and Required Code Set