Пример #1
0
        private void StartDragGrid(object sender, MouseButtonEventArgs e) {
            Grid g = (Grid)sender;
            DragScope = Application.Current.MainWindow.Content as FrameworkElement;
            bool previousDrop = DragScope.AllowDrop;
            DragScope.AllowDrop = true;
            DragEventHandler draghandler = new DragEventHandler(Window1_DragOver);
            DragScope.PreviewDragOver += draghandler;
            DragEventHandler dragleavehandler = new DragEventHandler(DragScope_DragLeave);
            DragScope.DragLeave += dragleavehandler;
            QueryContinueDragEventHandler queryhandler = new QueryContinueDragEventHandler(DragScope_QueryContinueDrag);
            DragScope.QueryContinueDrag += queryhandler;

            _adorner = new DragAdorner(DragScope, (UIElement)g, true, 0.5);
            _layer = AdornerLayer.GetAdornerLayer(DragScope as Visual);
            _layer.Add(_adorner);

            IsDragging = true;
            _dragHasLeftScope = false;

            //NEEEEEEEEEEEEEEEEEEEEEEEEEED TO CHANGE
            TextBlock name = (TextBlock) g.Children[0];
            TextBlock duration = (TextBlock) g.Children[1];
            TextBlock path = (TextBlock)g.Children[2];
            String content = g.Tag.ToString() + "#" + path.Text + "#" + duration.Text;
            DataObject data = new DataObject(System.Windows.DataFormats.Text.ToString(), content);
            DragDropEffects de = DragDrop.DoDragDrop(g, data, DragDropEffects.Move);

            // Clean up our mess :) 
            DragScope.AllowDrop = previousDrop;
            AdornerLayer.GetAdornerLayer(DragScope).Remove(_adorner);
            _adorner = null;

            DragScope.DragLeave -= dragleavehandler;
            DragScope.QueryContinueDrag -= queryhandler;
            DragScope.PreviewDragOver -= draghandler;

            IsDragging = false;
        }
Пример #2
0
        private void StartDragSubItem(object sender, MouseEventArgs e)
        {
            TreeViewItem tvi2 = (TreeViewItem)sender;


            DragScope = Application.Current.MainWindow.Content as FrameworkElement;
            bool previousDrop = DragScope.AllowDrop;
            DragScope.AllowDrop = true;
            DragEventHandler draghandler = new DragEventHandler(Window1_DragOver);
            DragScope.PreviewDragOver += draghandler;
            DragEventHandler dragleavehandler = new DragEventHandler(DragScope_DragLeave);
            DragScope.DragLeave += dragleavehandler;
            QueryContinueDragEventHandler queryhandler = new QueryContinueDragEventHandler(DragScope_QueryContinueDrag);
            DragScope.QueryContinueDrag += queryhandler;

            _adorner = new DragAdorner(DragScope, (UIElement)this.tvi, true, 0.5);
            _layer = AdornerLayer.GetAdornerLayer(DragScope as Visual);
            _layer.Add(_adorner);


            IsDragging = true;
            _dragHasLeftScope = false;

            DataObject data = new DataObject(System.Windows.DataFormats.Text.ToString(), tvi2.Tag);
            DragDropEffects de = DragDrop.DoDragDrop(tvi2, data, DragDropEffects.Move);

            // Clean up our mess :) 
            DragScope.AllowDrop = previousDrop;
            AdornerLayer.GetAdornerLayer(DragScope).Remove(_adorner);
            _adorner = null;

            DragScope.DragLeave -= dragleavehandler;
            DragScope.QueryContinueDrag -= queryhandler;
            DragScope.PreviewDragOver -= draghandler;

            IsDragging = false;
        }
Пример #3
0
        public void StartDragDataGrid(object sender, MouseEventArgs e)
        {
            DataGridRow dgr = (DataGridRow)sender;

            // Let's define our DragScope .. In this case it is every thing inside our main window .. 
            DragScope = Application.Current.MainWindow.Content as FrameworkElement;

            // We enable Drag & Drop in our scope ...  We are not implementing Drop, so it is OK, but this allows us to get DragOver 
            bool previousDrop = DragScope.AllowDrop;
            DragScope.AllowDrop = true;

            // The DragOver event ... 
            DragEventHandler draghandler = new DragEventHandler(Window1_DragOver);
            DragScope.PreviewDragOver += draghandler;

            // Drag Leave is optional, but write up explains why I like it .. 
            DragEventHandler dragleavehandler = new DragEventHandler(DragScope_DragLeave);
            DragScope.DragLeave += dragleavehandler;

            // QueryContinue Drag goes with drag leave... 
            QueryContinueDragEventHandler queryhandler = new QueryContinueDragEventHandler(DragScope_QueryContinueDrag);
            DragScope.QueryContinueDrag += queryhandler;

            //Here we create our adorner.. 
            _adorner = new DragAdorner(DragScope, (UIElement)this.dg, true, 0.5);
            _layer = AdornerLayer.GetAdornerLayer(DragScope as Visual);
            _layer.Add(_adorner);


            IsDragging = true;
            _dragHasLeftScope = false;
            //Finally lets drag drop 
            string content = "dgr" + "#" + dgr.Tag.ToString();
            DataObject data = new DataObject(System.Windows.DataFormats.Text.ToString(), content);
            DragDropEffects de = DragDrop.DoDragDrop(dgr, data, DragDropEffects.Move);

            // Clean up our mess :) 
            DragScope.AllowDrop = previousDrop;
            AdornerLayer.GetAdornerLayer(DragScope).Remove(_adorner);
            _adorner = null;

            DragScope.DragLeave -= dragleavehandler;
            DragScope.QueryContinueDrag -= queryhandler;
            DragScope.PreviewDragOver -= draghandler;

            IsDragging = false;
        }
Пример #4
0
        private void StartDragInProcAdorner(MouseEventArgs e)
        {
            // Let's define our DragScope .. In this case it is every thing inside our main window ..
            DragScope = Program.ClientWindow.Content as FrameworkElement;
            System.Diagnostics.Debug.Assert(DragScope != null);

            // We enable Drag & Drop in our scope ...  We are not implementing Drop, so it is OK, but this allows us to get DragOver
            bool previousDrop = DragScope.AllowDrop;
            DragScope.AllowDrop = true;

            // Let's wire our usual events..
            // GiveFeedback just tells it to use no standard cursors..

            GiveFeedbackEventHandler feedbackhandler = new GiveFeedbackEventHandler(DragSource_GiveFeedback);
            this.GiveFeedback += feedbackhandler;

            // The DragOver event ...
            DragEventHandler draghandler = new DragEventHandler(Window1_DragOver);
            DragScope.PreviewDragOver += draghandler;

            // Drag Leave is optional, but write up explains why I like it ..
            DragEventHandler dragleavehandler = new DragEventHandler(DragScope_DragLeave);
            DragScope.DragLeave += dragleavehandler;

            // QueryContinue Drag goes with drag leave...
            QueryContinueDragEventHandler queryhandler = new QueryContinueDragEventHandler(DragScope_QueryContinueDrag);
            DragScope.QueryContinueDrag += queryhandler;

            //Here we create our adorner..
            _adorner = new DragAdorner(DragScope, (UIElement)this, true, 0.5);
            _layer = AdornerLayer.GetAdornerLayer(DragScope as Visual);
            _layer.Add(_adorner);

            IsDragging = true;
            _dragHasLeftScope = false;
            //Finally lets drag drop
            DataObject data = new DataObject(System.Windows.DataFormats.Text.ToString(), "abcd");
            DragDropEffects de = DragDrop.DoDragDrop(this, data, DragDropEffects.Move);

            // Clean up our mess :)
            DragScope.AllowDrop = previousDrop;
            AdornerLayer.GetAdornerLayer(DragScope).Remove(_adorner);
            _adorner = null;

            GiveFeedback -= feedbackhandler;
            DragScope.DragLeave -= dragleavehandler;
            DragScope.QueryContinueDrag -= queryhandler;
            DragScope.PreviewDragOver -= draghandler;

            IsDragging = false;
        }