Esempio n. 1
0
        private void fileslistbox_PreviewMouseMove(object sender, MouseEventArgs e)
        {
            // Get the current mouse position
            System.Windows.Point mousePos = e.GetPosition(null);
            Vector diff = startPoint - mousePos;

            if (e.LeftButton == MouseButtonState.Pressed &&
                (
                    Math.Abs(diff.X) > SystemParameters.MinimumHorizontalDragDistance ||
                    Math.Abs(diff.Y) > SystemParameters.MinimumVerticalDragDistance)
                )
            {
                // Get the dragged ListViewItem
                ListView     listView     = sender as ListView;
                ListViewItem listViewItem =
                    FindAnchestor <ListViewItem>((DependencyObject)e.OriginalSource);

                if (listViewItem != null)
                {
                    // Find the data behind the ListViewItem
                    ImageEntry ie = (ImageEntry)listView.ItemContainerGenerator.
                                    ItemFromContainer(listViewItem);

                    // Initialize the drag & drop operation
                    DataObject dragData = new DataObject("myFormat", ie);
                    DragDrop.DoDragDrop(listViewItem, dragData, DragDropEffects.Copy);
                }
            }
        }
Esempio n. 2
0
        private void selectionListViewDrop(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent("myFormat"))
            {
                ImageEntry   name         = e.Data.GetData("myFormat") as ImageEntry;
                ListViewItem listViewItem = FindAncestorOrSelf <ListViewItem>((DependencyObject)e.OriginalSource);

                if (listViewItem != null)
                {
                    ImageEntry nameToReplace = (ImageEntry)selectionlistbox.ItemContainerGenerator.ItemFromContainer(listViewItem);
                    int        index         = selectionlistbox.Items.IndexOf(nameToReplace);

                    if (index >= 0)
                    {
                        selectionlistbox.Items.Remove(name);
                        selectionlistbox.Items.Insert(index, name);
                    }
                }
                else
                {
                    selectionlistbox.Items.Remove(name);
                    selectionlistbox.Items.Add(name);
                }
            }
        }
Esempio n. 3
0
 private void selectionlistbox_Drop(object sender, DragEventArgs e)
 {
     if (e.Data.GetDataPresent("myFormat"))
     {
         ImageEntry ie       = e.Data.GetData("myFormat") as ImageEntry;
         ListView   listView = sender as ListView;
         if (!listView.Items.Contains(ie))
         {
             ie.ToggleSelected(true);
             listView.Items.Add(ie);
         }
     }
 }
Esempio n. 4
0
        public List <string> GetSelectedFiles()
        {
            List <string> result = new List <string>();

            if (explorer.SelectedPath == "")
            {
                return(result);
            }

            //DirectoryInfo dirinfo = new DirectoryInfo(explorer.SelectedPath);
            foreach (var item in selectionlistbox.Items)
            //foreach (var item in listbox.Items)
            {
                ImageEntry ie = (ImageEntry)item;

                //if (ie.Selected)
                result.Add(ie.FileNameInclPath);
            }

            return(result);
        }
Esempio n. 5
0
        private void selectionBeginDrag(MouseEventArgs e)
        {
            //ListView listView = this.listbox;
            //ListViewItem listViewItem =
            //    FindAncestorOrSelf<ListViewItem>((DependencyObject)e.OriginalSource);

            ListView     listView     = this.selectionlistbox;
            ListViewItem listViewItem =
                FindAncestorOrSelf <ListViewItem>((DependencyObject)e.OriginalSource);

            if (listViewItem == null)
            {
                return;
            }

            // get the data for the ListViewItem
            ImageEntry name = (ImageEntry)selectionlistbox.ItemContainerGenerator.ItemFromContainer(listViewItem);

            //setup the drag adorner.
            selectionInitialiseAdorner(listViewItem);

            //add handles to update the adorner.
            fileslistbox.PreviewDragOver += selectionListViewDragOver;
            fileslistbox.DragLeave       += selectionListViewDragLeave;
            fileslistbox.DragEnter       += selectionListViewDragEnter;

            DataObject      data = new DataObject("myFormat", name);
            DragDropEffects de   = DragDrop.DoDragDrop(this.fileslistbox, data, DragDropEffects.Move);

            //cleanup
            fileslistbox.PreviewDragOver -= selectionListViewDragOver;
            fileslistbox.DragLeave       -= selectionListViewDragLeave;
            fileslistbox.DragEnter       -= selectionListViewDragEnter;

            if (_adorner != null)
            {
                AdornerLayer.GetAdornerLayer(listView).Remove(_adorner);
                _adorner = null;
            }
        }
Esempio n. 6
0
        private void selectionlistbox_Drop(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent("myFormat"))
            {
                //MessageBox.Show(e.Data.GetData("myFormat").GetType().ToString());
                ImageEntry   name         = e.Data.GetData("myFormat") as ImageEntry;
                ListViewItem listViewItem = FindAncestorOrSelf <ListViewItem>((DependencyObject)e.OriginalSource);

                if (listViewItem != null)
                {
                    ImageEntry nameToReplace = (ImageEntry)selectionlistbox.ItemContainerGenerator.ItemFromContainer(listViewItem);

                    int removedIdx = (selectionlistbox.ItemsSource as ObservableCollection <ImageEntry>).IndexOf(name);
                    int targetIdx  = (selectionlistbox.ItemsSource as ObservableCollection <ImageEntry>).IndexOf(nameToReplace);

                    (selectionlistbox.ItemsSource as ObservableCollection <ImageEntry>).Move(removedIdx, targetIdx);
                }
                else
                {
                    (selectionlistbox.ItemsSource as ObservableCollection <ImageEntry>).Remove(name);
                    (selectionlistbox.ItemsSource as ObservableCollection <ImageEntry>).Add(name);
                }
            }
        }