Exemple #1
0
        void StartDrag(ListBox parent, Point mousePosition)
        {
            var vm = this.DataContext as SalesViewModel;

            if (vm == null || !String.IsNullOrWhiteSpace(vm.SearchBarItemText))
            {
                return;
            }

            UIElement dataContainer;
            //get the object source for the selected item
            object data = GetObjectDataFromPoint(parent, mousePosition, out dataContainer);

            //if the data is not null then start the drag drop operation
            if (data != null)
            {
                RemoveAdorner();//clear the adorner layer from previous adorners

                //create a new adorner for the item and add it to the Adorner Layer
                adorner = new AdornerDragDrop(containerGrid, dataContainer);
                AdornerLayer.GetAdornerLayer(containerGrid).Add(adorner);
                //do the drag drop operation and pass the data
                DragDrop.DoDragDrop(parent, data, DragDropEffects.Move);
            }
        }
Exemple #2
0
        private void ListBox_DropHandler(object sender, DragEventArgs e)
        {
            RemoveAdorner();

            adorner = null;


            var data = e.Data.GetData(typeof(GoodsModel)) as GoodsModel;

            if (data == null)
            {
                return;
            }

            var destination = (e.OriginalSource as FrameworkElement);

            if (destination == null || destination.Tag == null)
            {
                return;
            }

            var vm = this.DataContext as SalesViewModel;

            if (vm == null)
            {
                return;
            }

            vm.ChangeBarItemPosition(data, destination.Tag.ToString());
        }
Exemple #3
0
 //remove the adorner from the layer
 private void RemoveAdorner()
 {
     if (adorner != null)
     {
         //remove the adorner
         AdornerLayer.GetAdornerLayer(containerGrid).Remove(adorner);
         adorner = null;
     }
 }
        protected override void OnPreviewMouseLeftButtonDown(MouseButtonEventArgs e)
        {
            base.OnPreviewMouseLeftButtonDown(e);

            if (e.OriginalSource.GetType() == typeof(RouteItem))
            {
                Point position = e.GetPosition(this);
                // To prevent Mouse "hang" error, release Adorner object if one constructed
                if (_adorner != null)
                {
                    AdornerLayer.GetAdornerLayer(_adorner.AdornedElement).Remove(_adorner);
                }
                // Initialize new Adorner object
                _adorner = new AdornerDragDrop(e.OriginalSource as UIElement)
                {
                    StartPoint = position
                };

                e.Handled = true;
            }
        }
        private void DragFinished(bool cancel)
        {
            //Release Mouse
            Mouse.Capture(null);
            // Remove adorner object from rendering layer
            AdornerLayer.GetAdornerLayer(_adorner.AdornedElement).Remove(_adorner);

            if (_adorner.IsDragStarted && cancel == false)
            {
                //Move object to new position
                if (_adorner.OriginalSource is RouteItem rt)
                {
                    rt.SetBindingPoint(new Point(
                                           _adorner.StartPoint.X + _adorner.LeftOffset - _adorner.ActualWidth / 2,
                                           _adorner.StartPoint.Y + _adorner.TopOffset - _adorner.ActualHeight / 2));
                }

                _adorner = null;

                InvalidateVisual();
            }
        }