运行时wpf treeviewitem设置图标
我有一个树状视图,格式如下:运行时wpf treeviewitem设置图标,wpf,Wpf,我有一个树状视图,格式如下: <TreeView x:Name="treview_Menu"/> 在运行时,我有: 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
<TreeView x:Name="treview_Menu"/>
在运行时,我有:
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
如何为添加的每个节点设置图标?
谢谢
我使用:visual studio ultimate 2012和wpf。您可以绑定图像的源属性。绑定应该可以工作,因此您不需要for-each循环在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>
Icon是绑定到Customclass的Icon属性的图像,它应该是图像的路径HI,感谢帮助,它可以工作,但是现在我如何在双击TreeView项目时启动特定的windown?
<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>