I used the method described in the following question to populate a combo box.
ComboBox ItemTemplate does not support values of type 'Image'
The ComboBox is populated with instances of a wrapper class that contains the Image and some data. However as the poster of that question stated the images do not display in the combobox, however selecting one of the blank entries does bind the data correctly.
The data is bound in the model view as this interacts with the external data source, however the images are UI specific so are bound in the code of the user control.
How can I get the images displaying?
code:
public ObservableCollection<Wrapper> Images { get; set; }
public Class Wrapper
{
public Wrapper(int data, Image img)
{
Data = data;
Img = img;
}
public int Data { get; set; }
public Image Img { get; set; }
}
int selectedData;
public int SelectedData
{
get { return selectedData; }
set
{
selectedData = value;
(this.Resources["model"] as MyModel).External = Images[selectedData].Data;
SendPropertyChanged("SelectedData");
}
}
xaml:
<ComboBox ItemsSource="{Binding Images}" SelectedIndex="{Binding SelectedData}">
<ComboBox.ItemTemplate>
<DataTemplate>
<Image Source="{Binding Img}" Height="83" Width="71"/>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>