daily pastebin goal
45%
SHARE
TWEET

Untitled

a guest Jan 18th, 2019 50 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <ListView Grid.Row="1" Grid.Column="0" Background="Transparent"
  2.           ItemsSource="{Binding MyViewModelObservableCollection}"
  3.  
  4.           AllowDrop = "True"
  5.  
  6.           Drop = "{Binding TheDropHandlerInTheViewModel, PassTheDropEventArgs}"
  7.  
  8.           DragOver = "{Binding TheDragOverHandlerInTheViewModel, PassTheDrageEventArgs}">
  9.  
  10. </ListView>
  11.    
  12. private void ImagePanel_Drop(object sender, DragEventArgs e)
  13. {
  14.  
  15.   if (e.Data.GetDataPresent(DataFormats.FileDrop))
  16.   {
  17.     // можно же перетянуть много файлов, так что....
  18.     string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
  19.  
  20.     // делаешь что-то
  21.   }
  22. }
  23.    
  24. <StackPanel Name="ImagePanel" Drop="ImagePanel_Drop" AllowDrop="true">
  25.     ...
  26. </StackPanel>
  27.    
  28. Drop="ImagePanel_Drop" AllowDrop="true"
  29.    
  30. <Grid>
  31.     <ListBox ItemsSource="{Binding Items}"
  32.              dd:DragDrop.IsDropTarget="True"
  33.              dd:DragDrop.DropHandler="{Binding}"
  34.              >
  35.  
  36.     </ListBox>
  37. </Grid>
  38.    
  39. public class MainViewModel : ViewModelBase, IDropTarget
  40. {
  41.  
  42.     public ObservableCollection<string> Items { get; set; }
  43.  
  44.     public MainViewModel()
  45.     {
  46.         Items = new ObservableCollection<string>();
  47.     }
  48.  
  49.     public void DragOver(IDropInfo dropInfo)
  50.     {
  51.         dropInfo.DropTargetAdorner = DropTargetAdorners.Insert;
  52.  
  53.         var dataObject = dropInfo.Data as IDataObject;
  54.  
  55.         dropInfo.Effects = dataObject != null && dataObject.GetDataPresent(DataFormats.FileDrop)
  56.             ? DragDropEffects.Copy
  57.             : DragDropEffects.Move;
  58.     }
  59.  
  60.     public void Drop(IDropInfo dropInfo)
  61.     {
  62.         var dataObject = dropInfo.Data as DataObject;
  63.         if (dataObject != null && dataObject.ContainsFileDropList())
  64.         {
  65.             var files = dataObject.GetFileDropList();
  66.             foreach (var file in files)
  67.             {
  68.                 Items.Add(file);
  69.  
  70.             }
  71.         }
  72.     }
  73. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top