Ejemplo n.º 1
0
        private void ListView_PreviewMouseMove(object sender, MouseEventArgs e)
        {
            if ((e.LeftButton == MouseButtonState.Pressed) && (fpMouseDownPos.HasValue))
            {
                Point pt = e.GetPosition(fListView);

                if ((fpMouseDownPos.Value - pt).Length > 10)
                {
                    ListViewItem dragStartItem = WpfListViewAssist.GetListViewItemAtPoint(fListView, fpMouseDownPos.Value);

                    if (dragStartItem != null)
                    {
                        DragDropEffects effects = DragDropEffects.Move;

                        if (fListView.SelectedItems.Count > 1)
                        {
                            effects = DragDropEffects.Copy;
                        }

                        DragDrop.DoDragDrop(fListView, dragStartItem, effects);
                    }

                    fInsertionMark.Hide();
                    fpMouseDownPos = null; // Make sure this code is executed once per Mouse Down
                    e.Handled      = true;
                }
            }
        }
Ejemplo n.º 2
0
        private void ListView_DragOver(object sender, System.Windows.DragEventArgs e)
        {
            int sourceIndex = -1;

            if (e.Data.GetDataPresent(typeof(ListViewItem)))
            {
                ListViewItem draggedItem = (ListViewItem)e.Data.GetData(typeof(ListViewItem));

                if (draggedItem != null)
                {
                    sourceIndex = fListView.Items.IndexOf(draggedItem.Content);
                }
            }
            else if (e.Data.GetDataPresent(DataFormats.FileDrop, false))
            {
                // Importing files
                if (!Enabled)
                {
                    e.Effects = DragDropEffects.None;
                }
            }
            else
            {
                e.Effects = DragDropEffects.None;
            }

            if (e.Effects == DragDropEffects.None)
            {
                fInsertionMark.Hide();
            }
            else
            {
                int targetIndex = -1;

                Point        pt   = e.GetPosition(fListView);
                ListViewItem item = WpfListViewAssist.GetListViewItemAtPoint(fListView, pt);

                if (item != null)
                {
                    targetIndex = fListView.Items.IndexOf(item.Content);
                }

                if (targetIndex < 0)
                {
                    fInsertionMark.Hide();
                }
                else
                {
                    int scrollIndex = targetIndex;

                    if (pt.Y < item.ActualHeight)
                    {
                        if (scrollIndex > 0)
                        {
                            scrollIndex--;
                        }
                    }
                    else if (pt.Y > (fListView.ActualHeight - item.ActualHeight))
                    {
                        if (scrollIndex < (fListView.Items.Count - 1))
                        {
                            scrollIndex++;
                        }
                    }
                    else
                    {
                        // No Scrolling
                    }

                    if (scrollIndex != targetIndex)
                    {
                        fInsertionMark.Hide();
                        fListView.ScrollIntoView(fListView.Items[scrollIndex]);
                        System.Threading.Thread.Sleep(70); //slow down the scrolling a bit
                    }
                    else if (sourceIndex < 0)
                    {
                        fInsertionMark.Show(item, true);
                    }
                    else if (targetIndex == sourceIndex)
                    {
                        fInsertionMark.Hide();
                    }
                    else
                    {
                        fInsertionMark.Show(item, targetIndex < sourceIndex);
                    }
                }
            }

            e.Handled = true;
        }