WPF Drag And Drop DataBinding
Hey guys, I'm starting to wrap WPF around my head and I came to a dead end.
I have a ListBox that accepts files/folders by drag and drop. I have a Files Class witch contains files properties like "Name", "Thumbnail" [and so on] and a FilesCollection Class well it's self intuitive. The Collection takes a "FilesPath" and then it retrieves all the files from that path. Currently it has a static p开发者_如何学Pythonath associated with it but I want that path to change when I drag a folder to the ListBox.
So what I want is:
- when I drag a folder to the ListBox, associate the path of it to the FilesCollection Class
All you need to do is set AllowDrop to True and handle the Drop event.
The ListBox definition:
<ListBox AllowDrop="True" Drop="ListBox_Drop"> </ListBox>
The event handler:
private void ListBox_Drop(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent("FileName"))
{
string folderPath = e.Data.GetData("FileName");
//do whatever you need to do with the folder path
}
}
精彩评论