Ejemplo n.º 1
0
        private void listView_Drop(object sender, DragEventArgs e)
        {
            bool isListViewEx = e.Data.GetDataPresent(typeof(ListViewEx <VMSong>));

            if (!isListViewEx)
            {
                return;
            }

            List <string>       itemsToMove = new List <string>();
            ListViewEx <VMSong> source      = e.Data.GetData(typeof(ListViewEx <VMSong>)) as ListViewEx <VMSong>;
            int index = listView.CurrentIndex;//GetCurrentIndex(e.GetPosition);

            /*
             * if(index >= Items.Count)
             * {
             *  throw new Exception("Index should be valid with the range");
             * }
             */

            // index = listView.GetCurrentIndex(e.GetPosition);

            listView.SelectedItems.Clear();
            listView._selItems.Clear();


            foreach (VMSong s in source._selItems)
            {
                itemsToMove.Add(s.Filepath);
            }

            listView.AddDataFromFiles(index, itemsToMove);
        }
Ejemplo n.º 2
0
        private void BeingMultiDrag(MouseEventArgs e)
        {
            ListViewEx <T> listView     = this;
            ListViewItem   listViewItem =
                FindAnchestor <ListViewItem>((DependencyObject)e.OriginalSource);

            if (listViewItem == null)
            {
                return;
            }

            //the listviewitem can be selected on drag before the cache has updated.
            //In this case, add the item to _selitems
            //when dragging between listviews, we use _selitems to get the selected items
            if (!_selItems.Contains((T)listViewItem.DataContext))
            {
                _selItems.Clear(); //make this item the only selected item
                _selItems.Add((T)listViewItem.DataContext);
            }

            RestoreCacheSelectedItems();
            SortCachedSelectedItems();

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

            //add handles to update the adorner.
            listView.PreviewDragOver += ListViewDragOver;
            listView.DragLeave       += ListViewDragLeave;
            listView.DragEnter       += ListViewDragEnter;

            DataObject      data = new DataObject(typeof(ListViewEx <T>), this);
            DragDropEffects de   = DragDrop.DoDragDrop(this, data, DragDropEffects.Move);

            _selItems.Clear();
            //cleanup
            listView.PreviewDragOver -= ListViewDragOver;
            listView.DragLeave       -= ListViewDragLeave;
            listView.DragEnter       -= ListViewDragEnter;

            if (_adorner != null)
            {
                AdornerLayer.GetAdornerLayer(listView).Remove(_adorner);
                _adorner = null;
            }
        }
Ejemplo n.º 3
0
        private void HandleDragDrop(DragEventArgs e)
        {
            bool isListViewEx = e.Data.GetDataPresent(typeof(ListViewEx <T>));

            if (isListViewEx)
            {
                List <T>       itemsToMove = new List <T>();
                ListViewEx <T> source      = e.Data.GetData(typeof(ListViewEx <T>)) as ListViewEx <T>;
                int            index       = CurrentIndex;//GetCurrentIndex(e.GetPosition);

                /*
                 * if(index >= Items.Count)
                 * {
                 *  throw new Exception("Index should be valid with the range");
                 * }
                 */

                if (source == this)
                {
                    foreach (T o in _selItems)
                    {
                        itemsToMove.Add(o);
                    }

                    MoveData(index, itemsToMove);
                    _selItems.Clear();
                    return;
                }
                index = GetCurrentIndex(e.GetPosition);
                if (index < 0)
                {
                    index = Items.Count;
                }

                SelectedItems.Clear();
                _selItems.Clear();

                foreach (T o in source._selItems)
                {
                    itemsToMove.Add(o);
                }

                AddData(index, itemsToMove);
            }
            else
            {
                DataObject    dataObj      = e.Data as DataObject;
                List <string> StringSource = dataObj.GetData(typeof(List <string>)) as List <string>;
                if (StringSource != null)
                {
                    int index = GetCurrentIndex(e.GetPosition);
                    if (index < 0)
                    {
                        index = Items.Count;
                    }
                    SelectedItems.Clear();
                    _selItems.Clear();
                    AddDataFromFiles(index, StringSource);
                }
            }
        }