问题
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