示例#1
0
        public static void lv_PreviewMouseMove(object sender, System.Windows.Input.MouseEventArgs e)
        {
            if (startPoint.X == -1 && startPoint.X == -1)
            {
                return;
            }
            // Get the current mouse position
            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)
                {
                    WorkItem workItem = listViewItem.Tag as WorkItem;
                    if (workItem != null)
                    {
                        // Initialize the drag & drop operation
                        var data = new DragDropData()
                        {
                            OriginListView = listView, WorkItem = workItem
                        };
                        DataObject dragData = new DataObject(typeof(DragDropData), data);
                        DragDrop.DoDragDrop(listViewItem, dragData, DragDropEffects.Move);
                        startPoint = new Point(-1, -1);
                    }
                }
            }
        }
示例#2
0
        static void header_Drop(object sender, DragEventArgs e)
        {
            try
            {
                if (e.Data.GetDataPresent(typeof(DragDropData)))
                {
                    TextBlock tb = sender as TextBlock;
                    if (tb != null)
                    {
                        StackPanel sp = tb.Parent as StackPanel;
                        if (sp != null)
                        {
                            var lv = sp.Children[1] as ListView;
                            if (lv != null)
                            {
                                var obj = e.Data.GetData(typeof(DragDropData));

                                DragDropData ddd      = (DragDropData)obj;
                                ListView     originLV = ddd.OriginListView;
                                WorkItem     wi       = ddd.WorkItem;

                                Iteration iter = lv.Tag as Iteration;
                                wi.PartialOpen();
                                wi.IterationId   = iter.Id;
                                wi.IterationPath = iter.Path;
                                wi.Save(SaveFlags.MergeAll);
                                AddWorkItemToSprint(lv, wi);

                                foreach (object item in originLV.Items)
                                {
                                    if (item.GetType() == typeof(ListViewItem))
                                    {
                                        var tempWi = ((ListViewItem)item).Tag as WorkItem;
                                        if (tempWi != null && wi == tempWi)
                                        {
                                            var list = originLV.ItemsSource as List <ListViewItem>;
                                            list.Remove((ListViewItem)item);
                                            originLV.Items.Refresh();
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
            }
        }