I have a few images with some text, I need to show the image with the relevant text in a listbox.
Browsing google I came across this sample class,
public class Customer
{
public string Fname;
public string Lname;
public Customer(string firstName, string lastName)
{
Fname = firstName;
Lname = lastName;
}
public override string ToString()
{
return Fname + " " + Lname;
}
}
lstCustomers.Items.Add(new Customer("Foo","Bar"));
The above code works fine as it only returns string, how do I return an image and a string together so that it gets added to the listbox?
Best Regards
@nand
Best Solution
Just use a
DataTemplate
to display your objects in theListBox
.Create a data object that contains string properties and an Image property:
Create a
DataTemplate
to display this:Now add the
Img
items (or your data objects) to theListBox
like so: