将图像绑定到树视图

时间:2014-03-05 08:07:52

标签: c# wpf binding treeview

我列表中的图片很少

public List<Image> UniqueDeviceImages
    {
        get;
        set;
    }

我正在尝试将这些图像集绑定到树视图

<StackPanel Orientation="Horizontal">
<ItemsControl x:Name="ImagelistControl" ItemsSource="{Binding Path=UniqueDeviceImages}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Image Source="{Binding Path=UniqueDeviceImages,Converter={StaticResource bitmapconvertor }}" Height="15" Width="15" Margin="0,2,4,3"/>
 </DataTemplate>
  </ItemsControl.ItemTemplate>
 </ItemsControl>
  <TextBlock Text="{Binding Path= UniqueDeviceName}">
  </TextBlock>
 </StackPanel>

有一个位图转换器,可将Image转换为Imageresource类型。图像没有绑定到树视图。树视图只显示设备名称。它没有显示任何图像。

1 个答案:

答案 0 :(得分:1)

ItemsControl中项目容器的DataContext自动设置为ItemsSource集合中的相应数据项。因此,在DataTemplate中,您不能再绑定到UniqueDeviceImages属性。只需删除绑定表达式的Path部分:

<Image Source="{Binding Converter={StaticResource bitmapconvertor}}" .../>