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);
}
}
You can use a EventTriggerBehavior. You will dispatch "Drop Event" to a command. Probably you will need a converter for the event arguments. Here is an example using a listview.
<core:EventTriggerBehavior EventName="SelectionChanged">
<core:InvokeCommandAction InputConverter="{StaticResource SelectionChangedConverter}"
InputConverterParameter="{Binding ElementName=CapturasListView}"
Command="{Binding OpenCapturaCommand}" />
</core:EventTriggerBehavior>
Here some links which explain the same approach:
Checking out the documentation for caliburn, which I've never used, it appears you're missing Event and Action:
Cal:Message.Attach="[Event Drop] = [Action SaveFile($eventArgs)]"
According to the documentation cheat sheet here http://caliburnmicro.com/documentation/cheat-sheet
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With