I have a ComboBox that should show me two values, a string and a picture. I have a list of some objects that I added to the ComboBox. Those objects have the string and Bitmap fields. I can show the string in my ComboBox, but I can't find a way to show the Bitmap.
Is there any way to make <Image/>
show my Bitmap?
Here is my ComboBox XAML code which I know isn't working, but I can't think of another way to do it.
<ComboBox x:Name="typeBox" Grid.Column="1" HorizontalAlignment="Left" Margin="10,318,0,0" VerticalAlignment="Top" Width="300" Height="29">
<ComboBox.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.RowDefinitions>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
</Grid.ColumnDefinitions>
<TextBlock Text="{Binding name}" Grid.Column="0" Grid.Row="0"/>
<Image Width="20" Height="20" HorizontalAlignment="Right" Grid.Row="0" Grid.Column="1" Source="{Binding img}"/>
</Grid>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
C# code of my form window that is relevant:
public NewRes()
{
pc = new PicChanger();
InitializeComponent();
typeBox.DataContext = GlowingEarth.types;
tagBox.DataContext = GlowingEarth.tags;
if (GlowingEarth.types.Count > 0)
{
foreach (Model.Type t in GlowingEarth.types)
{
typeBox.Items.Add(t);
}
}
if (GlowingEarth.tags.Count > 0)
{
foreach (Model.Etiquette t in GlowingEarth.tags)
{
tagBox.Items.Add(t);
}
}
}
C# code of my resources (Type and Etiquette) classes that are relevant:
public class Type
{
private string mark;
public string name { get; set; }
private string desc;
private Bitmap img;
public Type(string m, string n, string d, Bitmap mg)
{
mark = m;
name = n;
desc = d;
img = mg;
}
}
public class Etiquette
{
private string mark;
public string colCod { get; set; }
private string desc;
public Etiquette(string m, string c, string d)
{
mark = m;
colCod = c;
desc = d;
}
}