Drag and drop MVVM files with Caliburn

I am trying to upload files using the drag and drop function. I was able to successfully complete the user interface, but I had problems accessing the object that was deleted in the backend. I was able to successfully capture the object if I made the code, but I am trying to use 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 tried EventArgs, I could not find the property of the file object. DragEventArgs is null when the code is validated.

A working solution for code outside

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); } } 
+6
source share
2 answers

You can use EventTriggerBehavior. You will send the Drop Event command to the team. You will probably need a converter for the event arguments. Here is an example using listview.

  <core:EventTriggerBehavior EventName="SelectionChanged"> <core:InvokeCommandAction InputConverter="{StaticResource SelectionChangedConverter}" InputConverterParameter="{Binding ElementName=CapturasListView}" Command="{Binding OpenCapturaCommand}" /> </core:EventTriggerBehavior> 

Here are some links that explain the same approach:

+6
source

Checking the calibration documentation that I never used seems like you are missing events and actions:

 Cal:Message.Attach="[Event Drop] = [Action SaveFile($eventArgs)]" 

According to the wrapper documentation here http://caliburnmicro.com/documentation/cheat-sheet

+4
source

All Articles