【问题标题】:ComboBox ItemTemplate does not support values of type 'Image'ComboBox ItemTemplate 不支持“图像”类型的值
【发布时间】:2012-07-16 23:56:30
【问题描述】:

我正在尝试将 WPF 组合框绑定到可观察的图像集合。 这是我的收藏:

    public class AvatarPhoto
    {
        public int AvatarId { get; set; }
        public BitmapImage AvatarImage { get; set; }
    }
    public ObservableCollection<AvatarPhoto> AvailableProfilePictures { get; private set; }

这是我的 xaml:

Visual Studio 给了我这个编译时错误: 属性“ItemTemplate”不支持“Image”类型的值。

为什么会出现这个错误?

谢谢

更新:感谢您的回答!它解决了这个问题。

现在我已经更新了我的代码,但我在 ComboBox 中看到了这个:

为什么不能正确显示图片?在调试窗口中,我可以看到我的集合已正确填充:

【问题讨论】:

    标签: wpf image binding combobox itemtemplate


    【解决方案1】:

    将您的Image 放入DataTemplate

    <ComboBox.ItemTemplate>
        <DataTemplate>
            <Image />
        </DataTemplate>
    </ComboBox.ItemTemplate>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-04-17
      • 1970-01-01
      • 2011-11-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多