Click here to Skip to main content
15,880,967 members
Please Sign up or sign in to vote.
5.00/5 (2 votes)
See more:
Hi
Plz ny one guide me how to load multiple images in to a listbox in WPf.

i have a listbox and a button on the Wpf window and images in a sepearate folder. if we click on the button all the images should display in the listbox.

plz any one help me to accomplish this.

Thanks,
Posted

Why is it that no-one is capable of using google, or the search built in to code project ?

Custom ListBox Layout in WPF[^]
 
Share this answer
 
//Load BMP images from a pre-defined location
private void LoadImages()
{
//start clean
listView1.Clear();
listView1.Refresh();
imageList1.Images.Clear();

//setup the list
imageList1.ImageSize = new Size(50, 50);
imageList1.ColorDepth = ColorDepth.Depth32Bit;
imageList1.TransparentColor = Color.White;

//get the location
string[] images = Directory.GetFiles(_path, "*" + _imageFileExtension);

//load the list image list
foreach (string img in images)
{
System.Drawing.Image img1 = System.Drawing.Image.FromFile(img);
imageList1.Images.Add(GetThumbnaiImage(imageList1.ImageSize.Width, img1));
}

//populate the list view
int j = 0;
foreach (string img in images)
{
FileInfo fi = new FileInfo(img);
this.listView1.Items.Add(fi.Name);
this.listView1.Items[j].ImageIndex = j;
j++;
}

//display the list
this.listView1.View = View.LargeIcon;
this.listView1.LargeImageList = imageList1;
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900