我有一个树形视图:
<TreeView x:Name="treview_Menu"/>
我有我的自定义类:
public class CustomClass
public property description as string
public property icon as string
end class
在运行时我有:
dim oList as list(of CustomClass) = CustomClass_LayerLink.ListAll()
dim node as TreeViewItem
for each oEntity as CustomClass in oList
node = new TreeViewItem with
{
.header = oEntity.description
}
me.treview_Menu.items.add(node)
next
如何设置添加的每个节点的图标? Thankz。
我使用:visual studio ultimate 2012,和wpf。
答案 0 :(得分:0)
您可以绑定图像的source属性。绑定应该工作,所以你不需要为每个循环在wpf中手动完成。
希望它有所帮助。
<Style TargetType="{x:Type TreeViewItem}">
<Setter Property="HeaderTemplate">
<Setter.Value>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Image Name="icon"
Width="15"
Height="15"
Source="{Binding icon}"/>
<TextBlock Text="{Binding description}" />
</StackPanel>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>