Пример #1
0
        // perform drop
        void _dd_DragDrop(object source, DragDropEventArgs e)
        {
            // get object being dragged
            UIElement sourceElement = e.DragSource;

            // get source parent, target listboxes
            ListBox sourceParent = _list1.Items.Contains(sourceElement) ? _list1 : _list2;
            ListBox target = e.DropTarget as ListBox;

            // get index into target
            int index = GetDropIndex(e, target);

            // adjust index
            if (sourceParent == target)
            {
                int sourceIndex = sourceParent.Items.IndexOf(sourceElement);
                if (index > sourceParent.Items.IndexOf(sourceElement))
                {
                    index--;
                }
                if (index == sourceIndex)
                    return;
            }

            // remove from original position, insert into new position
            sourceParent.Items.Remove(sourceElement);
            target.Items.Insert(index, sourceElement);
        }
Пример #2
0
 /// <summary>
 /// Used to handle the DragDrop event.
 /// Determines the target and fires the corresponding action (move or copy).
 /// </summary>
 /// <param name="source">The source of the event</param>
 /// <param name="e">The event arguments</param>
 public void HandleDragDrop(object source, DragDropEventArgs e)
 {
     if (e.Effect != DragDropEffect.None)
     {
         // make the move...
         C1TreeViewItem item = e.DragSource as C1TreeViewItem;
         if (item != null)
         {
             // find target node
             C1TreeViewItem target = Tree.GetNode(e.GetPosition(null));
             if (target != null)
             {
                 Point p = e.GetPosition(target);
                 bool insertAfter = (p.Y > target.RenderSize.Height / 2);
                 if (Effect == DragDropEffect.Move)
                 {
                     DoMove(item, target, insertAfter);
                 }
                 else
                 {
                     DoCopy(item, target, insertAfter);
                 }
             }
         }
     }
 }
Пример #3
0
 // get drop location within a ListBox
 public static int GetDropIndex(DragDropEventArgs e, ListBox target)
 {
     int index = 0;
     foreach (UIElement child in target.Items)
     {
         Point p = e.GetPosition(child);
         if (p.Y - child.DesiredSize.Height / 2 < 0) break;
         index++;
     }
     return index;
 }
Пример #4
0
        void button_DragDrop(Control sender, DragDropEventArgs e)
        {
            ActionButton slot = sender as ActionButton;

            if (e.DraggedControl.Tag is Item)
            {
                Item item = e.DraggedControl.Tag as Item;
                ItemSlot itemSlot = slot.Tag as ItemSlot;

                if (GameLogic.Player.Equip(item, itemSlot))
                    slot.Item = item;
            }
        }
 private void OnDropInfo(object sender, DragDropEventArgs e)
 {
     if (e.Options.Status == DragStatus.DropComplete)
     {
         if (e.Options.Payload != null && e.Options.Destination.GetType() == typeof(TextBox))
         {
             var box = (TextBox)e.Options.Destination;
             if (box.SelectionStart < box.Text.Length)
             {
                 box.Text = box.Text.Substring(0, box.SelectionStart) + (string)e.Options.Payload + box.Text.Substring(box.SelectionStart);
             }
             else
             {
                 box.Text += (string)e.Options.Payload;
             }
         }
     }
 }
Пример #6
0
        /// <summary>
        /// Finds the drop placement (before, in or after).
        /// </summary>
        /// <param name="e">The <see cref="Telerik.Windows.Controls.DragDrop.DragDropEventArgs"/> instance containing the event data.</param>
        /// <returns>The DropPlacement Enum</returns>
        public static DropPlacement FindDropPlacement(DragDropEventArgs e)
        {
            //The text that would show up on a Drag to tell you whether you are going
            //to drop something before, in or after the item you are hovering over
            var dragActionString = ((String)((TreeViewDragCue)e.Options.DragCue).DragActionContent);

            if (dragActionString != null)
            {
                if (dragActionString.Contains("before"))
                    return DropPlacement.Before;
                if (dragActionString.Contains("in"))
                    return DropPlacement.In;
                if (dragActionString.Contains("after"))
                    return DropPlacement.After;
            }

            return DropPlacement.None;
        }
Пример #7
0
        // handle user dragging a cell to a new position
        void _ddMgr_DragDrop(object source, DragDropEventArgs e)
        {
            // get view object being dragged
            var bdr = e.DragSource as Border;
            var viewObject = bdr.Child as MyViewObject;
            if (viewObject != null)
            {
                // get target cell
                var ht = _flex.HitTest(e.GetPosition(_flex));
                if (ht.CellType == CellType.Cell && ht.Row > -1 && ht.Column > -1)
                {
                    // move object to target cell
                    var oldRange = new CellRange(bdr);
                    _flex[oldRange.Row, oldRange.Column] = null;
                    _flex[ht.Row, ht.Column] = viewObject.DataObject;

                    // and move the selection
                    _flex.Select(ht.Row, ht.Column);
                }
            }
        }
Пример #8
0
        /// <inheritdoc />
        protected override void HandleDragDropAssets(List <AssetItem> objects, DragDropEventArgs args)
        {
            for (int i = 0; i < objects.Count; i++)
            {
                var         item = objects[i];
                SurfaceNode node = null;
                switch (item.ItemDomain)
                {
                case ContentDomain.Animation:
                {
                    node = Context.SpawnNode(9, 2, args.SurfaceLocation, new object[]
                        {
                            item.ID,
                            1.0f,
                            true,
                            0.0f,
                        });
                    break;
                }

                case ContentDomain.SkeletonMask:
                {
                    node = Context.SpawnNode(9, 11, args.SurfaceLocation, new object[]
                        {
                            0.0f,
                            item.ID,
                        });
                    break;
                }
                }
                if (node != null)
                {
                    args.SurfaceLocation.X += node.Width + 10;
                }
            }
            base.HandleDragDropAssets(objects, args);
        }
Пример #9
0
        /// <inheritdoc />
        protected override void HandleDragDropAssets(List <AssetItem> objects, DragDropEventArgs args)
        {
            for (int i = 0; i < objects.Count; i++)
            {
                var         assetItem = objects[i];
                SurfaceNode node      = null;

                if (assetItem.IsOfType <FlaxEngine.Animation>())
                {
                    node = Context.SpawnNode(9, 2, args.SurfaceLocation, new object[]
                    {
                        assetItem.ID,
                        1.0f,
                        true,
                        0.0f,
                    });
                }
                else if (assetItem.IsOfType <SkeletonMask>())
                {
                    node = Context.SpawnNode(9, 11, args.SurfaceLocation, new object[]
                    {
                        0.0f,
                        assetItem.ID,
                    });
                }
                else if (assetItem.IsOfType <AnimationGraphFunction>())
                {
                    node = Context.SpawnNode(9, 24, args.SurfaceLocation, new object[] { assetItem.ID, });
                }

                if (node != null)
                {
                    args.SurfaceLocation.X += node.Width + 10;
                }
            }
            base.HandleDragDropAssets(objects, args);
        }
Пример #10
0
        /// <summary>
        ///     Checks that the user of a <see cref="DragDropEventArgs"/> is within a
        ///     certain distance of the target and dropped entities without any entity
        ///     that matches the collision mask obstructing them.
        ///     If the <paramref name="range"/> is zero or negative,
        ///     this method will only check if nothing obstructs the entity and component.
        /// </summary>
        /// <param name="args">The event args to use.</param>
        /// <param name="range">
        ///     Maximum distance between the two entity and set of map coordinates.
        /// </param>
        /// <param name="collisionMask">The mask to check for collisions.</param>
        /// <param name="predicate">
        ///     A predicate to check whether to ignore an entity or not.
        ///     If it returns true, it will be ignored.
        /// </param>
        /// <param name="ignoreInsideBlocker">
        ///     If true and both the user and target are inside
        ///     the obstruction, ignores the obstruction and considers the interaction
        ///     unobstructed.
        ///     Therefore, setting this to true makes this check more permissive,
        ///     such as allowing an interaction to occur inside something impassable
        ///     (like a wall). The default, false, makes the check more restrictive.
        /// </param>
        /// <param name="popup">
        ///     Whether or not to popup a feedback message on the user entity for
        ///     it to see.
        /// </param>
        /// <returns>
        ///     True if the two points are within a given range without being obstructed.
        /// </returns>
        public bool InRangeUnobstructed(
            DragDropEventArgs args,
            float range = InteractionRange,
            CollisionGroup collisionMask = CollisionGroup.Impassable,
            Ignored predicate            = null,
            bool ignoreInsideBlocker     = false,
            bool popup = false)
        {
            var user    = args.User;
            var dropped = args.Dropped;
            var target  = args.Target;

            if (!InRangeUnobstructed(user, target, range, collisionMask, predicate, ignoreInsideBlocker))
            {
                if (popup)
                {
                    var message = Loc.GetString("You can't reach there!");
                    target.PopupMessage(user, message);
                }

                return(false);
            }

            if (!InRangeUnobstructed(user, dropped, range, collisionMask, predicate, ignoreInsideBlocker))
            {
                if (popup)
                {
                    var message = Loc.GetString("You can't reach there!");
                    dropped.PopupMessage(user, message);
                }

                return(false);
            }

            return(true);
        }
Пример #11
0
        /// <summary>
        /// Method called when the current drop target of this DragContainer changes.
        /// </summary>
        /// <param name="e">
        /// DragDropEventArgs object initialised as follows:
        /// - dragDropItem is initialised to the DragContainer triggering the event (typically 'this').
        /// - window is initialised to point to the Window which will be the new drop target.
        /// </param>
        /// <remarks>
        /// This event fires just prior to the target field being changed.  The default implementation
        /// changes the drop target, you can examine the old and new targets before calling the default
        /// implementation to make the actual change (and fire appropriate events for the Window objects
        /// involved).
        /// </remarks>
        protected virtual void OnDragDropTargetChanged(DragDropEventArgs e)
        {
            FireEvent(EventDragDropTargetChanged, e, EventNamespace);

            // Notify old target that drop item has left
            if (_dropTarget != null)
            {
                _dropTarget.NotifyDragDropItemLeaves(this);
            }

            // update to new target
            _dropTarget = e.Window;

            while ((_dropTarget != null) && !_dropTarget.IsDragDropTarget())
            {
                _dropTarget = _dropTarget.GetParent();
            }

            // Notify new target window that someone has dragged a DragContainer over it
            if (_dropTarget != null)
            {
                _dropTarget.NotifyDragDropItemEnters(this);
            }
        }
Пример #12
0
        /// <inheritdoc />
        protected override void HandleDragDropAssets(List <AssetItem> objects, DragDropEventArgs args)
        {
            for (int i = 0; i < objects.Count; i++)
            {
                var         assetItem = objects[i];
                SurfaceNode node      = null;

                if (assetItem.IsOfType <Texture>())
                {
                    node = Context.SpawnNode(5, 11, args.SurfaceLocation, new object[] { assetItem.ID });
                }
                else if (assetItem.IsOfType <CubeTexture>())
                {
                    node = Context.SpawnNode(5, 12, args.SurfaceLocation, new object[] { assetItem.ID });
                }
                else if (assetItem.IsOfType <ParticleEmitterFunction>())
                {
                    node = Context.SpawnNode(14, 300, args.SurfaceLocation, new object[] { assetItem.ID });
                }
                else if (assetItem.IsOfType <GameplayGlobals>())
                {
                    node = Context.SpawnNode(7, 16, args.SurfaceLocation, new object[]
                    {
                        assetItem.ID,
                        string.Empty,
                    });
                }

                if (node != null)
                {
                    args.SurfaceLocation.X += node.Width + 10;
                }
            }

            base.HandleDragDropAssets(objects, args);
        }
Пример #13
0
 public abstract bool DragDropOn(DragDropEventArgs eventArgs);
 public override bool DragDropOn(DragDropEventArgs eventArgs)
 {
     return(true);
 }
        void ddManager_DragDrop(object source, DragDropEventArgs e)
        {
            // get desired location
            Border rect = (Border)e.DropTarget;
            int targetRow = Grid.GetRow(rect);
            int targetColumn = Grid.GetColumn(rect);

            // undo mouseover
            rect.Background = (Brush)rect.Tag;

            // get old location
            FrameworkElement sourceBorder = (e.DragSource as FrameworkElement).Parent as Border;
            int sourceRow = Grid.GetRow(sourceBorder);
            int sourceColumn = Grid.GetColumn(sourceBorder);

            // piece
            Piece piece = _tablePieces[sourceRow, sourceColumn];
            bool isNotUsedCell = (_tablePieces[targetRow, targetColumn] == null);
            bool isSimpleMovement = true;
            bool isEating = true;
            List<Piece> eatenPieces = new List<Piece>();
            int direction = Offset(piece.Team.Direction);

            // analyze movement
            if (isNotUsedCell)
            {
                // simple movement
                isSimpleMovement &= (sourceRow + direction == targetRow)
                                 && (Math.Abs(targetColumn - sourceColumn) == 1);

                // eating pieces
                if (!isSimpleMovement)
                {
                    int offset = Math.Abs(targetColumn - sourceColumn);
                    isEating &= (targetRow - sourceRow == direction * offset)
                             && (offset % 2 == 0);

                    // rival pieces
                    int i = 1;
                    while (isEating && i < offset)
                    {
                        int r = Move(sourceRow, targetRow, i);
                        int c = Move(sourceColumn, targetColumn, i);
                        if (_tablePieces[r, c] != null)
                        {
                            isEating &= (_tablePieces[r, c].Team != piece.Team);
                            eatenPieces.Add(_tablePieces[r, c]);
                        }
                        else
                        {
                            isEating = false;
                        }
                        i += 2;
                    }

                    // using empty cells
                    i = 2;
                    while (isEating && i <= offset)
                    {
                        int r = Move(sourceRow, targetRow, i);
                        int c = Move(sourceColumn, targetColumn, i);
                        isEating &= (_tablePieces[r, c] == null);
                        i += 2;
                    }

                    if (!isEating)
                        eatenPieces.Clear();
                }
            }

            if (isNotUsedCell && (isSimpleMovement || isEating))
            {
                LocatePiece(piece, targetRow, targetColumn);
                foreach (var p in eatenPieces)
                {
                    RemovePiece(p);
                }
            }
        }
Пример #16
0
        private void OnDragInfo(object sender, DragDropEventArgs e)
		{
			if (e.Options.Status == DragStatus.DragComplete)
			{
				var listBox = e.Options.Source.FindItemsConrolParent() as ListBox;

				var itemsSource = listBox.ItemsSource as IList<Track>;
				var operation = e.Options.Payload as DragDropOperation;

				itemsSource.Remove(operation.Payload as Track);
			}
		}
 bool IDraggable.Drop(DragDropEventArgs args)
 {
     return(TryBuckle(args.User, args.Target));
 }
Пример #18
0
        /// <summary>
        /// Sets the DragCue based on all possible errors.
        /// </summary>
        /// <param name="draggedItems">The dragged items.</param>
        /// <param name="e">The <see cref="Telerik.Windows.Controls.DragDrop.DragDropEventArgs"/> instance containing the event data.</param>
        /// <returns>Empty string if there is no error. Otherwise, it returns the errorString</returns>
        private string DragCueSetter(IEnumerable draggedItems, DragDropEventArgs e)
        {
            if (!draggedItems.OfType<RouteTask>().Any()) return "";

            //Checks to see if the destination is null
            var destinationCheck = e.Options.Destination;
            if (destinationCheck == null) return "";

            //If its not null we set the destination to e.Options.Destination.DataContext
            var destination = destinationCheck.DataContext;

            //Collection of dragged items
            var payloadCollection = ((IEnumerable<object>)e.Options.Payload).Cast<RouteTask>().ToArray(); //.Select(o => ((TH)o).ChildRouteTask)

            //The first item, used in various checks to be sure that all dragged items have the same service, location, etc.
            var payloadCheck = payloadCollection.First();


            #region Setting Drag Cue off Different Conditions

            #region Check For Multiple Tasks Being Dragged

            var routeTasks = draggedItems.OfType<RouteTask>().ToArray();

            if (routeTasks.Count() > 1)
            {
                var services = routeTasks.Select(rt => rt.Name).Where(n => n != null).Distinct();

                if (services.Count() > 1)
                    return ErrorConstants.DifferentService;

                //FirstOrDefault might be null but the second might have a service 
                payloadCheck = DragDropTools.CheckItemsForService(payloadCollection);
            }

            #endregion

            if (destination == null)
                return "";

            if (!(destination is Route) && !(destination is RouteDestination) && !(destination is RouteTask))
                return ErrorConstants.CannotDropHere;

            #region Drag Destination is RouteTask

            if (destination is RouteTask)
            {
                if (payloadCheck.Service != null)
                {
                    #region Check For Route Type

                    var routeType = ((RouteTask)destination).RouteDestination.Route.RouteType;

                    var returnString = DragDropTools.CheckRouteType(routeType, payloadCheck);

                    if (returnString != CommonErrorConstants.Valid)
                        return returnString;

                    #endregion
                }

                //Trying to drop a Task into a Destination with a different Location
                if (((payloadCheck.Location != ((RouteTask)destination).Location)))
                    if (payloadCheck.Service != null || ((RouteTask)destination).Service != null)
                        return CommonErrorConstants.InvalidLocation;
            }

            #endregion

            #region Drag Destination is RouteDestination

            else if (destination is RouteDestination)
            {
                #region Check For Route Type

                var routeType = ((RouteDestination)destination).Route.RouteType;

                var returnString = DragDropTools.CheckRouteType(routeType, payloadCheck);

                if (returnString != CommonErrorConstants.Valid)
                    return returnString;

                #endregion

                var dragActionString = ((String)((TreeViewDragCue)e.Options.DragCue).DragActionContent);

                //Checks to see if the dragged locations match the destinations location. Also makes sure that you are trying to drop in the destination before throwing an error.
                if (((payloadCheck.LocationId != ((RouteDestination)destination).LocationId)) && dragActionString != null && dragActionString.Contains("in"))
                    return CommonErrorConstants.InvalidLocation;
            }

            #endregion

            #region Drag Destination is Route

            else if (destination is Route)
            {
                #region Check For Route Type

                var routeType = ((Route)destination).RouteType;

                var returnString = DragDropTools.CheckRouteType(routeType, payloadCheck);

                if (returnString != CommonErrorConstants.Valid)
                    return returnString;

                #endregion
            }

            #endregion

            return "";

            #endregion
        }
Пример #19
0
 void dumyOnDrop(object sender, DragDropEventArgs e)
 {
     ClearDraggedObj(false);
     IFace.ClearDragImage();
 }
Пример #20
0
 void dumyOnEndDrag(object sender, DragDropEventArgs e)
 {
     IFace.ClearDragImage();
 }
Пример #21
0
        void button_DragDrop(Control sender, DragDropEventArgs e)
        {
            ActionButton slot = sender as ActionButton;

            slot.Item = e.DraggedControl.Tag as GuiItem;
        }
Пример #22
0
 void txt_OnDragDrop(Control sender, DragDropEventArgs e)
 {
     ((TextBox)sender).Text = ((Button)e.DraggedControl).Text;
 }
 void _ddManager_DragLeave(object source, DragDropEventArgs e)
 {
     var target = (Border)e.DropTarget;
     target.Background = (Brush)target.Tag;
 }
 void _ddManager_DragEnter(object source, DragDropEventArgs e)
 {
     var target = (Border)e.DropTarget;
     target.Tag = target.Background;
     target.Background = new SolidColorBrush(Colors.Orange);
 }
Пример #25
0
 /// <summary>
 /// Handles the drag drop assets action.
 /// </summary>
 /// <param name="objects">The objects.</param>
 /// <param name="args">The drag drop arguments data.</param>
 protected virtual void HandleDragDropAssets(List <AssetItem> objects, DragDropEventArgs args)
 {
 }
Пример #26
0
 //Nothing needs to be done here in this case, everything is handled in OnDragInfo
 private void OnDropInfo(object sender, DragDropEventArgs e)
 {
 }
Пример #27
0
        void _ddManager_DragLeave(object source, DragDropEventArgs e)
        {
            var target = (Border)e.DropTarget;

            target.Background = (Brush)target.Tag;
        }
 void item_DragOver(object sender, DragDropEventArgs e)
 {
 }
Пример #29
0
        void ddManager_DragDrop(object source, DragDropEventArgs e)
        {
            // get desired location
            Border rect         = (Border)e.DropTarget;
            int    targetRow    = Grid.GetRow(rect);
            int    targetColumn = Grid.GetColumn(rect);

            // undo mouseover
            rect.Background = (Brush)rect.Tag;

            // get old location
            FrameworkElement sourceBorder = (e.DragSource as FrameworkElement).Parent as Border;
            int sourceRow    = Grid.GetRow(sourceBorder);
            int sourceColumn = Grid.GetColumn(sourceBorder);

            // piece
            Piece        piece            = _tablePieces[sourceRow, sourceColumn];
            bool         isNotUsedCell    = (_tablePieces[targetRow, targetColumn] == null);
            bool         isSimpleMovement = true;
            bool         isEating         = true;
            List <Piece> eatenPieces      = new List <Piece>();
            int          direction        = Offset(piece.Team.Direction);

            // analyze movement
            if (isNotUsedCell)
            {
                // simple movement
                isSimpleMovement &= (sourceRow + direction == targetRow) &&
                                    (Math.Abs(targetColumn - sourceColumn) == 1);

                // eating pieces
                if (!isSimpleMovement)
                {
                    int offset = Math.Abs(targetColumn - sourceColumn);
                    isEating &= (targetRow - sourceRow == direction * offset) &&
                                (offset % 2 == 0);

                    // rival pieces
                    int i = 1;
                    while (isEating && i < offset)
                    {
                        int r = Move(sourceRow, targetRow, i);
                        int c = Move(sourceColumn, targetColumn, i);
                        if (_tablePieces[r, c] != null)
                        {
                            isEating &= (_tablePieces[r, c].Team != piece.Team);
                            eatenPieces.Add(_tablePieces[r, c]);
                        }
                        else
                        {
                            isEating = false;
                        }
                        i += 2;
                    }

                    // using empty cells
                    i = 2;
                    while (isEating && i <= offset)
                    {
                        int r = Move(sourceRow, targetRow, i);
                        int c = Move(sourceColumn, targetColumn, i);
                        isEating &= (_tablePieces[r, c] == null);
                        i        += 2;
                    }

                    if (!isEating)
                    {
                        eatenPieces.Clear();
                    }
                }
            }

            if (isNotUsedCell && (isSimpleMovement || isEating))
            {
                LocatePiece(piece, targetRow, targetColumn);
                foreach (var p in eatenPieces)
                {
                    RemovePiece(p);
                }
            }
        }
Пример #30
0
 void DragDropHelper_ItemDropped(object sender, DragDropEventArgs e)
 {
 }
Пример #31
0
        /// <summary>
        ///Sets the drag cue while object is being dragged if the drop is not allowed to be dropped
        ///If the drag can be dropped then the defult drag cue is used
        ///If stopDragDrop is false it means drop is not allowed and then is cancelled
        /// </summary>
        private static string DragCueErrorStringHelper(DragDropEventArgs e)
        {
            var destination = e.Options.Destination;

            //Collection of dragged items
            var payloadCollection = (IEnumerable<object>)e.Options.Payload;

            //The first item, used in various checks to be sure that all dragged items have the same service, location, etc.
            var payloadCheck = payloadCollection.FirstOrDefault();

            //Place that the dragged items were dropped (before, in, after)
            var dropPlacement = DragDropTools.FindDropPlacement(e);

            #region Setting Drag Cue off Different Conditions

            #region Do all the checks for Mulit-Drag/Drop

            if (payloadCollection.Count() > 1)
            {
                var routeTasks = payloadCollection.OfType<RouteTask>();
                var routeDestinations = payloadCollection.OfType<RouteDestination>();

                var routeTasksExist = routeTasks.Any();
                var routeDestinationsExist = routeDestinations.Any();

                //User Selection Contains Both Tasks and Destinations
                if (routeTasksExist && routeDestinationsExist)
                    return ErrorConstants.InvalidSelection;
                //Checks whether there draggedItems are tasks and then checks to be sure they all have the same location if they are not being dropped in a route
                if (routeTasksExist)
                {
                    var locations = routeTasks.Select(rt => rt.Location).Distinct();

                    if (locations.Count() > 1 &&
                        (destination.DataContext is RouteTask ||
                         (destination.DataContext is RouteDestination && dropPlacement == DropPlacement.In)))
                        return ErrorConstants.DifferentLocations;
                }

                //FirstOrDefault might be null but the second might have a service 
                if (payloadCheck is RouteTask)
                    payloadCheck = DragDropTools.CheckItemsForService(payloadCollection.Cast<RouteTask>());
            }

            #endregion

            if (destination == null)
                return "";

            #region Drag Destination is a RouteTask

            if (destination.DataContext is RouteTask)
            {
                #region Check For Route Type
                var routeType = ((RouteTask)destination.DataContext).RouteDestination.Route.RouteType;

                var returnString = DragDropTools.CheckRouteType(routeType, payloadCheck);

                if (returnString != CommonErrorConstants.Valid)
                    return returnString;

                #endregion

                if (payloadCheck is RouteDestination)
                    return ErrorConstants.CantMergeDestinations;

                //Trying to drop a Task into a Destination with a different Location
                var routeTask = payloadCheck as RouteTask;

                if (routeTask == null)
                    return "";

                //Checks the RouteTasks location to be sure you are able to drop it in the specified RouteDestination
                if (((routeTask.Location != ((RouteTask)destination.DataContext).Location)) && (routeTask.Location != null))
                    return CommonErrorConstants.InvalidLocation;

            }

            #endregion

            #region Drag Destination is a RouteDestination

            else if (destination.DataContext is RouteDestination)
            {
                #region Check For Route Type
                var routeType = ((RouteDestination)destination.DataContext).Route.RouteType;

                var returnString = DragDropTools.CheckRouteType(routeType, payloadCheck);

                if (returnString != CommonErrorConstants.Valid)
                    return returnString;

                #endregion

                //Disallows the merging of destinations
                if (payloadCheck is RouteDestination && dropPlacement == DropPlacement.In)
                    return ErrorConstants.CantMergeDestinations;

                var routeTask = payloadCheck as RouteTask;

                if (routeTask == null)
                    return "";

                //Checks the RouteTasks location to be sure you are able to drop it on the specified RouteDestination
                if ((((routeTask.Location != ((RouteDestination)destination.DataContext).Location) && (routeTask.Location != null)) && dropPlacement != DropPlacement.After))
                    return CommonErrorConstants.InvalidLocation;

            }

            #endregion

            #region Drag Destination is a Route

            else if (destination.DataContext is Route)
            {
                #region Check For Route Type
                var routeType = ((Route)destination.DataContext).RouteType;

                var returnString = DragDropTools.CheckRouteType(routeType, payloadCheck);

                if (returnString != CommonErrorConstants.Valid)
                    return returnString;

                #endregion
            }

            #endregion

            return "";

            #endregion
        }
Пример #32
0
 private void Browser_DragEnterEvent(object sender, DragDropEventArgs e)
 {
     Log("DragEnter event");
     PrintEventDetails(e);
 }
        private void DataGridViewDragDrop(object theSender, DragEventArgs theE)
        {
            Point aClientPoint = dataGridView.PointToClient(new Point(theE.X, theE.Y));
            var aHitTest = dataGridView.HitTest(aClientPoint.X, aClientPoint.Y);
            rowIndexOfItemUnderMouseToDrop = aHitTest.RowIndex;
            columnIndexOfItemUnderMouseToDrop = aHitTest.ColumnIndex;

            if (!(rowIndexFromMouseDown != rowIndexOfItemUnderMouseToDrop && columnIndexFromMouseDown != columnIndexOfItemUnderMouseToDrop))
            {
                if (OnDrop != null)
                {
                    DragDropEventArgs aEventArgs = new DragDropEventArgs(
                        theE, 
                        rowIndexFromMouseDown,
                        rowIndexOfItemUnderMouseToDrop,
                        columnIndexFromMouseDown,
                        columnIndexOfItemUnderMouseToDrop);
                    OnDrop(this, aEventArgs);
                }

                if (theE.Effect == DragDropEffects.Move)
                {
                    if (AllowThisOneRowDragDrop && rowIndexFromMouseDown != rowIndexOfItemUnderMouseToDrop)
                    {
                        DataGridViewRow aRowToMove = theE.Data.GetData(typeof(DataGridViewRow)) as DataGridViewRow;
                        dataGridView.Rows.RemoveAt(rowIndexFromMouseDown);
                        dataGridView.Rows.Insert(rowIndexOfItemUnderMouseToDrop, aRowToMove);

                        object aSwapRowHeader = dataGridView.Rows[rowIndexFromMouseDown].Cells[0].Value;
                        dataGridView.Rows[rowIndexFromMouseDown].Cells[0].Value =
                            dataGridView.Rows[rowIndexOfItemUnderMouseToDrop].Cells[0].Value;
                        dataGridView.Rows[rowIndexOfItemUnderMouseToDrop].Cells[0].Value = aSwapRowHeader;

                        dataGridView.Rows[rowIndexOfItemUnderMouseToDrop].Cells[columnIndexOfItemUnderMouseToDrop].Selected = true;
                    }
                    else if (AllowThisOneColumnDragDrop)
                    {
                        object aSwapObj;
                        foreach (DataGridViewRow aRow in dataGridView.Rows)
                        {
                            if (aRow.Index == 0)
                            {
                                continue;
                            }

                            if (columnIndexFromMouseDown < columnIndexOfItemUnderMouseToDrop)
                            {
                                for (int aI = columnIndexFromMouseDown; aI < columnIndexOfItemUnderMouseToDrop; aI++)
                                {
                                    aSwapObj = aRow.Cells[aI].Value;
                                    aRow.Cells[aI].Value =
                                        aRow.Cells[aI + 1].Value;
                                    aRow.Cells[aI + 1].Value = aSwapObj;
                                }
                            }
                            else
                            {
                                for (int aI = columnIndexFromMouseDown; aI > columnIndexOfItemUnderMouseToDrop; aI--)
                                {
                                    aSwapObj = aRow.Cells[aI].Value;
                                    aRow.Cells[aI].Value =
                                        aRow.Cells[aI - 1].Value;
                                    aRow.Cells[aI - 1].Value = aSwapObj;
                                }
                            }
                        }

                        dataGridView.Rows[rowIndexOfItemUnderMouseToDrop].Cells[columnIndexOfItemUnderMouseToDrop].Selected = true;
                    }
                }
            }

            AllowThisOneRowDragDrop = AllowRowDragDrop;
            AllowThisOneColumnDragDrop = AllowColumnDragDrop;
        }
Пример #34
0
        /// <summary>
        /// Sets up the drag cue.
        /// </summary>
        /// <param name="e">The <see cref="Telerik.Windows.Controls.DragDrop.DragDropEventArgs"/> instance containing the event data.</param>
        /// <param name="draggedItems">The dragged items.</param>
        /// <returns></returns>
        private TreeViewDragCue SetUpDragCue(DragDropEventArgs e, IEnumerable<object> draggedItems)
        {
            // Get the drag cue that the TreeView or we have created
            var cue = e.Options.DragCue as TreeViewDragCue ?? new TreeViewDragCue();


            var status = e.Options.Status;

            if (status == DragStatus.DropImpossible)
            {
                //Sets the Drag cue and we assume that a drop is not possible unless notified otherwise
                cue = DragDropTools.SetPreviewAndToolTipVisabilityAndDropPossible(cue, Visibility.Collapsed, Visibility.Visible, false);
                cue.DragActionContent = "Cannot drop here";
            }

            //Sets the Drag cue if a drop is possible
            if (status == DragStatus.DropPossible)
            {
                cue = DragDropTools.SetPreviewAndToolTipVisabilityAndDropPossible(cue, Visibility.Visible, Visibility.Collapsed, true);
                cue.IsDropPossible = true;

                //Setup the error string here
                var errorString = DragCueErrorStringHelper(e);

                //Check errorString, an empty string means that there is not an issue with the current drop location
                if (errorString != "")
                    cue = DragDropTools.CreateErrorDragCue(cue, errorString, this.Resources["DragCueTemplate"] as DataTemplate);

                if (errorString == "")
                    cue = DragDropTools.SetPreviewAndToolTipVisabilityAndDropPossible(cue, Visibility.Visible, Visibility.Collapsed, true);


                if (e.Options.Destination is TaskBoard)
                {
                    cue = DragDropTools.SetPreviewAndToolTipVisabilityAndDropPossible(cue, Visibility.Visible, Visibility.Visible, true);
                    //Adds an 's' to "item" in DragActionContent if more than one item is being dragged
                    cue.DragActionContent =
                        String.Format(draggedItems.Count() > 1
                                          ? "Add items to Task Board"
                                          : "Add item to Task Board");

                }
            }

            return cue;
        }
Пример #35
0
        private void button_DragDrop(Control sender, DragDropEventArgs e)
        {
            var slot = sender as ActionButton;

            slot.Item = e.DraggedControl.Tag as GuiItem;
        }
Пример #36
0
        /// <summary>
        ///This gets called:
        ///1) an item is dragged over a potential drop location 
        ///2) again after the mouse button has been released
        /// </summary>
        private void OnDropInfo(object sender, DragDropEventArgs e)
        {
            //Prevents you from dragging no where
            if (e.Options.Destination == null || e.Options.Payload == null)
                return;

            var destination = e.Options.Destination.DataContext;

            var draggedItems = (IEnumerable<object>)e.Options.Payload;

            var cue = SetUpDragCue(e, draggedItems);

            e.Options.DragCue = cue;

            //Checks to be sure that the drag has been completed and that the drop would be on a valid location
            if (e.Options.Status == DragStatus.DragComplete && ((TreeViewDragCue)e.Options.DragCue).IsDropPossible)
            {
                //Get the values for the variables below
                var dropPlacement = DragDropTools.FindDropPlacement(e);

                var placeInRoute = DragDropTools.GetDropPlacement(destination, dropPlacement);

                //Modify placeInRoute
                if (placeInRoute > 0 && dropPlacement != DropPlacement.After)
                    placeInRoute--;

                //Go in reverse to preserve the order that the objects were previously in
                foreach (var draggedItem in draggedItems.Reverse())
                {
                    if (e.Options.Destination is TaskBoard)
                    {
                        DragDropTools.RemoveFromRoute(draggedItem);
                        AddToTaskBoard(draggedItem);
                    }
                    else
                    {
                        AddToRoute(draggedItem, destination, placeInRoute, dropPlacement);
                    }
                }

                VM.Routes.DispatcherSave();
            }

            e.Handled = true;
        }
 private void DragSource_OnDragLeave(object sender, DragDropEventArgs e)
 {
     e.OperationType = OperationType.DropNotAllowed;
 }
        /// <summary>
        ///     Event of dropping a note
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void DataTree_OnNodeDragEnd(object sender, DragDropEventArgs e)
        {
            if (e.OperationType == OperationType.DropNotAllowed)
            {
                return;
            }
            var data          = new MoveFoldersAndEndpointsInputArgs();
            var dragNode      = e.Data as XamDataTreeNode;
            var mainViewModel = PageNavigatorHelper.GetMainModel();

            if (dragNode != null)
            {
                var dragData = dragNode.Data as DirectoryNode;
                if (dragData != null)
                {
                    var dropTarget = e.DropTarget as XamDataTreeNodeControl;
                    if (dropTarget != null)
                    {
                        var dropData = dropTarget.Node.Data as DirectoryNode;
                        if (dropData != null)
                        {
                            if (DataTree.Equals(sender))
                            {
                                ApplicationContext.NodeId = dragData.NodeId;
                                if (!(dropData.NodeId == dragData.NodeId && dropData.IsFolder == dragData.IsFolder))
                                {
                                    data.TargerFolderId = dropData.NodeId;
                                    var lstfi = new List <int>();
                                    var lstei = new List <int>();
                                    if (dragData.IsFolder)
                                    {
                                        lstfi.Add(dragData.NodeId);
                                    }
                                    else
                                    {
                                        lstei.Add(dragData.NodeId);
                                    }
                                    data.FolderIds   = lstfi;
                                    data.EndpointIds = lstei;

                                    if (mainViewModel != null)
                                    {
                                        mainViewModel.MoveDirectoriesAndEndpointsAction(data);
                                    }
                                }
                            }
                            else if (SoftwareDataTree.Equals(sender))
                            {
                                var updSource = ApplicationContext.UpdateSourceList.Find(r => r.Id == dragData.NodeId);
                                if (updSource != null)
                                {
                                    updSource.ParentId = dropData.NodeId;
                                    var editUpdSourceBg = new BackgroundWorkerHelper();
                                    editUpdSourceBg.AddDoWork(SaveBackgroundWorker_DoWork).DoWork(updSource);
                                }
                            }
                        }
                    }
                }
            }
        }
Пример #39
0
 /// <summary>
 /// 处理拖拽的拖动操作
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void UserInRoles_OnDragInfo(object sender, DragDropEventArgs e)
 {
     RadGridView gridView = sender as RadGridView;
     IEnumerable draggedItems = e.Options.Payload as IEnumerable;
     if (e.Options.Status == DragStatus.DragInProgress)
     {
         TreeViewDragCue cue = new TreeViewDragCue();
         // 设置拖放窗口显示内容的模板。
         cue.ItemTemplate = ServiceLocator.Current.GetInstance<UniCloud.UniAuth.Views.UserRoleAllotView>().Resources["UserInRolesTemplate"] as DataTemplate;
         cue.Background = new SolidColorBrush(Colors.Transparent);
         cue.ItemsSource = draggedItems;
         e.Options.DragCue = cue;
     }
 }
Пример #40
0
 bool IDragDropOn.CanDragDropOn(DragDropEventArgs eventArgs)
 {
     return(eventArgs.Dragged.HasComponent <IBody>());
 }
Пример #41
0
        /// <summary>
        /// 处理拖拽的释放操作
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void UserInRoles_OnDropInfo(object sender, DragDropEventArgs e)
        {
            var gridView = sender as RadGridView;
            var draggedItems = e.Options.Payload as List<object>;

            TreeViewDragCue cue = e.Options.DragCue as TreeViewDragCue;
            if (e.Options.Status == DragStatus.DropPossible)
            {
                if (cue != null)
                {
                    cue.DragActionContent = String.Format("添加 {0} 个角色到当前用户", draggedItems.Count());
                    cue.IsDropPossible = true;
                }
            }
            else if (e.Options.Status == DragStatus.DropImpossible)
            {
                if (cue != null)
                {
                    cue.DragActionContent = dropImpossibleReason;
                    cue.IsDropPossible = false;
                }
            }
            else if (e.Options.Status == DragStatus.DropComplete)
            {
                if (draggedItems != null && draggedItems.Any())
                {
                    draggedItems.ForEach(d => AddRoleToUserInRoles(d));
                }
            }
        }
 public bool CanDragDrop(DragDropEventArgs eventArgs)
 {
     return(eventArgs.Target != eventArgs.Dropped &&
            eventArgs.Target == eventArgs.User &&
            CanBeStripped(eventArgs.User));
 }
Пример #43
0
 void onEndDrag(object sender, DragDropEventArgs e)
 {
     (sender as Widget).IFace.ClearDragImage();
 }
 public abstract bool Drop(DragDropEventArgs args);
 public bool DragDropOn(DragDropEventArgs eventArgs)
 {
     // Handled by StrippableComponent
     return(true);
 }
Пример #46
0
        private void OnDragInfo(object sender, DragDropEventArgs e)
        {
            if (CheckSourceForHeaderCell(e.Options.Source))
                return;

            var draggedItems = e.Options.Payload as IEnumerable; //draggedTHs = e.Options.Payload as IEnumerable;

            //var draggedItems = (from object draggedItem in draggedTHs 
            //select ((TH)draggedItem).ChildRouteTask).ToList(); 

            if (draggedItems == null) return;

            SetupDragCue(e, draggedItems);

            //Drag has completed and has been placed at a valid location
            if (e.Options.Status == DragStatus.DragComplete && ((TreeViewDragCue)e.Options.DragCue).IsDropPossible)
            {
                //Find out whether to drop it in, after, or before
                var dropPlacement = DragDropTools.FindDropPlacement(e);

                var destination = e.Options.Destination.DataContext;

                var placeInRoute = DragDropTools.GetDropPlacement(destination, dropPlacement);

                #region Modify placeInRoute

                if (dropPlacement == DropPlacement.Before)
                    placeInRoute--;

                //In case we somehow messed up. Set the place to the first position
                if (placeInRoute < 0)
                    placeInRoute = 0;

                #endregion

                //draggedItems = draggedItems as IEnumerable<object>;

                foreach (var draggedItem in draggedItems)
                    AddToRouteRemoveFromTaskBoard(draggedItem, destination, dropPlacement, placeInRoute);
            }

            e.Handled = true;

            VM.Routes.DispatcherSave();
        }
Пример #47
0
 private void thermo3DragDropEvents_DragDrop(object sender, DragDropEventArgs e)
 {
     thermo1DragDropEvents_DragDrop(sender, e);
 }
Пример #48
0
        /// <summary>
        /// Sets up the drag cue.
        /// </summary>
        /// <param name="e">The <see cref="Telerik.Windows.Controls.DragDrop.DragDropEventArgs"/> instance containing the event data.</param>
        /// <param name="draggedItems">The dragged items.</param>
        private void SetupDragCue(DragDropEventArgs e, IEnumerable draggedItems)
        {
            // Get the drag cue that the TreeView or we have created if one previously didnt exist
            var cue = e.Options.DragCue as TreeViewDragCue ?? new TreeViewDragCue();

            //Set up a drag cue and save it
            var errorString = DragCueSetter(draggedItems, e);

            if (errorString == "")
            {
                var itemNames = ((IEnumerable<object>)draggedItems).Select(i => ((RouteTask)i).Name);
                cue = DragDropTools.SetPreviewAndToolTipVisabilityAndDropPossible(cue, Visibility.Visible, Visibility.Collapsed, true);
                cue.ItemsSource = itemNames;
            }
            else if (errorString != "")
                cue = DragDropTools.CreateErrorDragCue(cue, errorString, this.Resources["DragCueTemplate"] as DataTemplate);

            e.Options.DragCue = cue;
        }
Пример #49
0
 void label_DragDrop(Control sender, DragDropEventArgs e)
 {
     GameObjectTreeNode target = sender.Parent as GameObjectTreeNode;
     GameObjectTreeNode source = e.Source as GameObjectTreeNode;
     if (target.Parent != null && (target != source))
     {
         var targetIndex = target.Parent.Nodes.IndexOf(target);
         source.Parent.Nodes.Remove(source);
         target.Parent.Nodes.Insert(targetIndex, source);
     }
 }
Пример #50
0
            private void Behavior_DragDrop(object sender, DragDropEventArgs e)
            {
                //https://www.devexpress.com/Support/Center/Question/Details/T583428/how-to-use-new-dragdropbehavior-in-xaf

                try
                {
                    var targetGrid = e.Target as GridView;


                    if (e.Action == DragDropActions.None)
                    {
                        return;
                    }
                    if (targetGrid == null)
                    {
                        return;
                    }

                    try
                    {
                        RePrioritiseIfNeeded();
                    }
                    catch (Exception exception)
                    {
                        Console.WriteLine(exception);
                        MessageBox.Show(exception.ToString());
                        throw;
                    }



                    var hitPoint = targetGrid.GridControl.PointToClient(Cursor.Position);
                    var hitInfo  = targetGrid.CalcHitInfo(hitPoint);

                    var droppedOnRowHandle = hitInfo.RowHandle;
                    var droppedOnRow       = targetGrid.GetRow(droppedOnRowHandle);


                    if (!(droppedOnRow is MPart droppedOnTask))

                    {
                        Debug.Print("huh?");
                        return;
                    }


                    var newPriority = 0;

                    switch (e.InsertType)
                    {
                    case InsertType.Before:
                        var rowBefore = targetGrid.GetRow(droppedOnRowHandle - 1);
                        switch (rowBefore)
                        {
                        case null:
                            newPriority = droppedOnTask.Priority - 1;
                            break;

                        case MPart prevTaskBeforeDroppedOn:
                            var diff = droppedOnTask.Priority - prevTaskBeforeDroppedOn.Priority;
                            newPriority = Convert.ToInt32(droppedOnTask.Priority - diff / 2);
                            break;
                        }


                        break;

                    case InsertType.After:
                        var rowAfter = targetGrid.GetRow(droppedOnRowHandle + 1);
                        switch (rowAfter)
                        {
                        case null:
                            newPriority = droppedOnTask.Priority + 1;
                            break;

                        case MPart nextTaskAfterDroppedOn:
                            var diff = nextTaskAfterDroppedOn.Priority - droppedOnTask.Priority;
                            newPriority = Convert.ToInt32(droppedOnTask.Priority + diff / 2);
                            break;
                        }

                        break;
                    }


                    TagToSetPriority(targetGrid, newPriority);
                }
                catch (Exception exception)
                {
                    Console.WriteLine(exception);
                    throw;
                }
            }
Пример #51
0
 void DragDropHelper_ItemDropped(object sender, DragDropEventArgs e)
 {
 }
Пример #52
0
 void onEndDrag(object sender, DragDropEventArgs e)
 {
     (sender as GraphicObject).IFace.ClearDragImage();
 }
Пример #53
0
        /// <summary>
        /// Used to handle the DragOver event.
        /// Adds the mark to indicate the drop target
        /// Determines if a given node of the tree is a valid drop location
        /// </summary>
        /// <param name="source">The source of the event</param>
        /// <param name="e">The event arguments</param>
        public void HandleDragOver(object source, DragDropEventArgs e)
        {
            C1DragDropManager dragDropManager = source as C1DragDropManager;
            if (Mark.Parent == null)
                dragDropManager.Canvas.Children.Add(Mark);
            Mark.Visibility = Visibility.Collapsed;
            e.Effect = DragDropEffect.None;

            // Check if is a valid drop action
            C1TreeViewItem target = Tree.GetNode(e.GetPosition(null));
            if (IsValidDrop(e.DragSource as C1TreeViewItem, target))
            {
                // get target with respect to drag/drop canvas
                Point p = target.C1TransformToVisual(dragDropManager.Canvas).Transform(new Point());
                Point pos = e.GetPosition(target);
                if (pos.Y > target.RenderSize.Height / 2)
                {
                    p.Y += target.RenderSize.Height;
                }
                Mark.SetValue(Canvas.LeftProperty, p.X);
                Mark.SetValue(Canvas.TopProperty, p.Y);
                Mark.Visibility = Visibility.Visible;
                e.Effect = DragDropEffect.Move;
            }
        }
        bool IDragDropOn.CanDragDropOn(DragDropEventArgs eventArgs)
        {
            if (!ActionBlockerSystem.CanInteract(eventArgs.User))
            {
                _notifyManager.PopupMessage(eventArgs.User, eventArgs.User, Loc.GetString("You can't do that!"));

                return(false);
            }

            if (eventArgs.User == eventArgs.Dropped) // user is dragging themselves onto a climbable
            {
                if (!eventArgs.User.HasComponent <ClimbingComponent>())
                {
                    _notifyManager.PopupMessage(eventArgs.User, eventArgs.User, Loc.GetString("You are incapable of climbing!"));

                    return(false);
                }

                var bodyManager = eventArgs.User.GetComponent <BodyManagerComponent>();

                if (bodyManager.GetBodyPartsOfType(Shared.GameObjects.Components.Body.BodyPartType.Leg).Count == 0 ||
                    bodyManager.GetBodyPartsOfType(Shared.GameObjects.Components.Body.BodyPartType.Foot).Count == 0)
                {
                    _notifyManager.PopupMessage(eventArgs.User, eventArgs.User, Loc.GetString("You are unable to climb!"));

                    return(false);
                }

                var userPosition      = eventArgs.User.Transform.MapPosition;
                var climbablePosition = eventArgs.Target.Transform.MapPosition;
                var interaction       = EntitySystem.Get <SharedInteractionSystem>();
                bool Ignored(IEntity entity) => (entity == eventArgs.Target || entity == eventArgs.User);

                if (!interaction.InRangeUnobstructed(userPosition, climbablePosition, _range, predicate: Ignored))
                {
                    _notifyManager.PopupMessage(eventArgs.User, eventArgs.User, Loc.GetString("You can't reach there!"));

                    return(false);
                }
            }
            else // user is dragging some other entity onto a climbable
            {
                if (eventArgs.Target == null || !eventArgs.Dropped.HasComponent <ClimbingComponent>())
                {
                    _notifyManager.PopupMessage(eventArgs.User, eventArgs.User, Loc.GetString("You can't do that!"));

                    return(false);
                }

                var userPosition      = eventArgs.User.Transform.MapPosition;
                var otherUserPosition = eventArgs.Dropped.Transform.MapPosition;
                var climbablePosition = eventArgs.Target.Transform.MapPosition;
                var interaction       = EntitySystem.Get <SharedInteractionSystem>();
                bool Ignored(IEntity entity) => (entity == eventArgs.Target || entity == eventArgs.User || entity == eventArgs.Dropped);

                if (!interaction.InRangeUnobstructed(userPosition, climbablePosition, _range, predicate: Ignored) ||
                    !interaction.InRangeUnobstructed(userPosition, otherUserPosition, _range, predicate: Ignored))
                {
                    _notifyManager.PopupMessage(eventArgs.User, eventArgs.User, Loc.GetString("You can't reach there!"));

                    return(false);
                }
            }

            return(true);
        }
Пример #55
0
		private void OnDropInfo(object sender, DragDropEventArgs e)
		{
			if (e.Options.Status == DragStatus.DropPossible)
			{
				var listBox = e.Options.Destination.FindItemsConrolParent() as ListBox;
				VisualStateManager.GoToState(listBox, "DropPossible", false);
				var destination = e.Options.Destination;

				//Get the DropCueElemet:
				var dropCueElement = (VisualTreeHelper.GetChild(listBox, 0) as FrameworkElement).FindName("DropCueElement") as FrameworkElement;

				var operation = e.Options.Payload as DragDropOperation;

				//Get the parent of the destination:
				var visParent = VisualTreeHelper.GetParent(destination) as UIElement;

				//Get the spacial relation between the destination and its parent:
				var destinationStackTopLeft = destination.TransformToVisual(visParent).Transform(new Point());

				var yTranslateValue = operation.DropPosition == DropPosition.Before ? destinationStackTopLeft.Y : destinationStackTopLeft.Y + destination.ActualHeight;

				dropCueElement.RenderTransform = new TranslateTransform() { Y = yTranslateValue };
			}

			//Hide the DropCue:
			if (e.Options.Status == DragStatus.DropImpossible || e.Options.Status == DragStatus.DropCancel || e.Options.Status == DragStatus.DropComplete)
			{
				var listBox = e.Options.Destination.FindItemsConrolParent() as ListBox;
				VisualStateManager.GoToState(listBox, "DropImpossible", false);
			}

			//Place the item:
			if (e.Options.Status == DragStatus.DropComplete)
			{
				var listBox = e.Options.Destination.FindItemsConrolParent() as ListBox;

				var itemsSource = listBox.ItemsSource as IList<Track>;
				var destinationIndex = itemsSource.IndexOf(e.Options.Destination.DataContext as Track);

				var operation = e.Options.Payload as DragDropOperation;
				var insertIndex = operation.DropPosition == DropPosition.Before ? destinationIndex : destinationIndex + 1;

				itemsSource.Insert(insertIndex, operation.Payload as Track);

				listBox.Dispatcher.BeginInvoke(() =>
				{
					listBox.SelectedIndex = insertIndex;
				});

                UpdatePlaylist();
			}
		}
Пример #56
0
 public bool Drop(DragDropEventArgs args)
 {
     return(TryBuckle(args.User, args.Target));
 }
 public virtual bool CanDragDropOn(DragDropEventArgs eventArgs)
 {
     return(eventArgs.Dragged.HasComponent <SharedClimbingComponent>());
 }