I'm trying to have upload files through drag and drop functionality. I was successfully able to complete the UI work but I'm having trouble accessing the object that was dropped in the backend. I was able to succesfully grab the object if I did behind code but I'm trying to take the MVVM approach.
AttachmentView.xaml
Cal:Message.Attach="[Drop] = [SaveFile($eventArgs)]"
AttachmentViewModel.cs
public virtual async void SaveFile(DragEventArgs e)
{
var fileStream = new FileStream([File name goes here], FileMode.Open, FileAccess.Read);
}
I've tried EventArgs, I couldn't find the file object property. DragEventArgs is null when the code is tested.
Working solution for behind code
AttachmentView.xaml.cs
private void ImagePanel_Drop(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
{
// Note that you can have more than one file.
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
// Assuming you have one file that you care about, pass it off to whatever
// handling code you have defined.
Upload(files);
}
}