开发者

listbox or listview of thumbnails with a directory as the input in c#

I've seen a lot of code for doing listbox or listview开发者_Go百科 thumbnails with hard coded, or submitted paths to an image. How would one just provide a path and c# display the contents of the directory as thumbnails?

Thanks for any help, I'm a total newb, my apologies if this is a lame question.


Ok this is derived from the sample Listviews with Multiple Views. I added a button which chooses a file in a directory and then gets all the files from the directory and adds them to the list view. I generically set every item to the cat image.

using Microsoft.Win32;
using System.Collections.Generic;

lv.ItemsSource = null;
List<XmlElement> elements = new List<XmlElement>();
Microsoft.Win32.FileDialog fd = new Microsoft.Win32.OpenFileDialog();
bool ?a = fd.ShowDialog();
if (a == true)
{
     XmlDocument doc = new XmlDocument();
     string dir = fd.FileName.Remove(fd.FileName.Length - fd.SafeFileName.Length, fd.SafeFileName.Length);
     string[] files = Directory.GetFiles(dir);
     foreach (string file in files)
     {
           XmlElement item = doc.CreateElement(file.Remove(0,dir.Length));
           item.SetAttribute("Name", file.Remove(0, dir.Length));
           item.SetAttribute("Type", Path.GetExtension(file));
           item.SetAttribute("Image", "images\\cat.png");
           elements.Add(item);
      }
}
lv.ItemsSource = elements;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜