【问题标题】:Binding list of images to treeview将图像列表绑定到树视图
【发布时间】:2014-03-05 08:07:52
【问题描述】:

我的列表中的图片很少

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 类型。图像没有绑定到树视图。树视图只显示设备名称。它不显示任何图像。

【问题讨论】:

    标签: c# wpf binding treeview


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-04-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-22
      • 1970-01-01
      • 2019-08-17
      相关资源
      最近更新 更多