ComboBox ItemTemplate does not support values of type 'Image'

谁说我不能喝 提交于 2019-12-12 04:59:33

问题


I'm trying to bind a WPF combobox to an observable collection of images. Here is my collection:

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

Here is my xaml:

Visual Studio gives me this compile time error: Property 'ItemTemplate' does not support values of type 'Image'.

Why is this error seen?

Thanks

Update: thanks for the answer! It solved the problem.

Now I have updated my code but I'm seeing this in the ComboBox:

Why is it not displaying pictures correctly? In the debug window I can see my collection is correctly populated:


回答1:


Put your Image in a DataTemplate:

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


来源:https://stackoverflow.com/questions/11514285/combobox-itemtemplate-does-not-support-values-of-type-image

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!