protected override Script.IScriptCommand onEvent(RoutedEvent eventId) { switch (eventId.Name) { //case "MouseDrag": //case "TouchDrag": // return ScriptCommands.AssignGlobalParameterDic("{CanvasResize}", false, // ScriptCommands.IfAssigned("{CanvasResize.ResizeItemAdorner}", // HubScriptCommands.DettachResizeItemAdorner("{CanvasResize.AdornerLayer}","{CanvasResize.ResizeItemAdorner}"))); //case "MouseDrag": //case "TouchDrag": // return HubScriptCommands.DettachResizeItemAdorner("{ResizeItemAdorner}"); case "PreviewTouchUp": case "PreviewMouseUp": return(ScriptCommands.FilterArray("{Sender.Items}", "IsSelected", ComparsionOperator.Equals, true, "{SelectedItems}", ScriptCommands.AssignGlobalParameterDic("{CanvasResize}", false, HubScriptCommands.DettachResizeItemAdorner("{CanvasResize.AdornerLayer}", "{CanvasResize.ResizeItemAdorner}", ScriptCommands.IfArrayLength(ComparsionOperator.Equals, "{SelectedItems}", 1, ScriptCommands.Assign("{CanvasResize.ResizeItem}", "{SelectedItems[0]}", false, HubScriptCommands.AssignAdornerLayer(AdornerType.SelectedItem, "{CanvasResize.AdornerLayer}", false, HubScriptCommands.AttachResizeItemAdorner("{CanvasResize.AdornerLayer}", "{CanvasResize.ResizeItemAdorner}"))) ))))); } return(base.onEvent(eventId)); }
protected override Script.IScriptCommand onEvent(RoutedEvent eventId) { switch (eventId.Name) { case "MouseMove": case "TouchMove": return (ScriptCommands.AssignGlobalParameterDic("{CanvasResize}", false, ScriptCommands.IfTrue("{CanvasResize.IsResizing}", HubScriptCommands.AssignCursorPosition(PositionRelativeToType.Panel, "{CanvasResize.CurrentPosition}", false, HubScriptCommands.UpdateResizeItemAdorner("{CanvasResize.ResizeItemAdorner}", "{CanvasResize.ResizeMode}", "{CanvasResize.StartPosition}", "{CanvasResize.CurrentPosition}"))))); //case "MouseDrag": //case "TouchDrag": case "PreviewTouchDown": case "PreviewMouseDown": return (ScriptCommands.AssignGlobalParameterDic("{CanvasResize}", false, HubScriptCommands.SetRoutedEventHandled( ScriptCommands.Assign("{CanvasResize.IsResizing}", true, false, HubScriptCommands.AssignCursorPosition(PositionRelativeToType.Panel, "{CanvasResize.StartPosition}", false, //Assign Source's Name (e.g. N, NW) to CanvasResize.ResizeMode. ScriptCommands.Assign("{CanvasResize.ResizeMode}", "{EventArgs.Source.Name}", false, HubScriptCommands.CaptureMouse(CaptureMouseMode.UIElement))))))); case "PreviewTouchUp": case "PreviewMouseUp": return (ScriptCommands.Assign("{CanvasResize.ResizeItemAdorner.OffsetX}", 0, false, ScriptCommands.Assign("{CanvasResize.ResizeItemAdorner.OffsetY}", 0, false, ScriptCommands.AssignGlobalParameterDic("{CanvasResize}", false, ScriptCommands.Assign("{CanvasResize.IsResizing}", false, false, HubScriptCommands.SetRoutedEventHandled( HubScriptCommands.CaptureMouse(CaptureMouseMode.Release, ScriptCommands.Subtract("{CanvasResize.CurrentPosition.X}", "{CanvasResize.StartPosition.X}", "{DiffX}", ScriptCommands.Subtract("{CanvasResize.CurrentPosition.Y}", "{CanvasResize.StartPosition.Y}", "{DiffY}", ScriptCommands.Switch <string>("{CanvasResize.ResizeMode}", new Dictionary <string, IScriptCommand>() { { "N", resizeNorthCommand }, { "NE", ScriptCommands.RunSequence(resizeNorthCommand, resizeEastCommand) }, { "E", resizeEastCommand }, { "SE", ScriptCommands.RunSequence(resizeSouthCommand, resizeEastCommand) }, { "S", resizeSouthCommand }, { "SW", ScriptCommands.RunSequence(resizeSouthCommand, resizeWestCommand) }, { "W", resizeWestCommand }, { "NW", ScriptCommands.RunSequence(resizeNorthCommand, resizeWestCommand) }, }, ScriptCommands.PrintConsole("Not supported : {CanvasResize.ResizeMode}, {DiffX},{DiffY}"))))))))))); } return(base.onEvent(eventId)); }
protected override IScriptCommand onEvent(RoutedEvent eventId) { if (eventId.Name.Contains("Mouse") && !EnableMouse) { return(base.onEvent(eventId)); } if (eventId.Name.Contains("Touch") && !EnableTouch) { return(base.onEvent(eventId)); } IScriptCommand detachAdornerAndResetDragDrop = ScriptCommands.SetPropertyValue(DragDropLiteCommand.DragDropDropTargetKey, "IsDraggingOver", false, DragDropScriptCommands.DetachAdorner("{DragDrop.AdornerLayer}", "{DragDrop.Adorner}", DragDropScriptCommands.EndLiteDrag("{DragDrop.SupportDrag}"))); if (EnableDrag) { switch (eventId.Name) { case "KeyDown": return(ScriptCommands.IfEquals(DragDropLiteCommand.DragDropModeKey, "Lite", HubScriptCommands.IfKeyGesture(new KeyGesture(Key.Escape), detachAdornerAndResetDragDrop))); case "PreviewMouseDown": case "PreviewTouchDown": return(_cmdDic.PreviewMouseDown ?? (_cmdDic.PreviewMouseDown = ScriptCommands.AssignGlobalParameterDic("{DragDrop}", false, //Set Default value for CanDrag first. ScriptCommands.Assign("{DragDrop.CanDrag}", false, false, //Find a DataContext that implement SupportDrag, and if assigned HubScriptCommands.IfHasDataContext("{EventArgs.OriginalSource}", DataContextType.SupportDrag, //and item under mouse (ISelectable) IsSelected. DragDropScriptCommands.IfItemUnderMouseIsSelected( //Notify MouseDrag can drag. ScriptCommands.Assign("{DragDrop.CanDrag}", true, false, //Prevent MultiSelect from starting. HubScriptCommands.SetRoutedEventHandled()) )))))); case "TouchDrag": case "MouseDrag": return(_cmdDic.MouseDrag ?? (_cmdDic.MouseDrag = ScriptCommands.AssignGlobalParameterDic("{DragDrop}", false, //If not handled. HubScriptCommands.IfNotRoutedEventHandled( //IfCanDrag (assigned from PreviewMouseDown) ScriptCommands.IfTrue("{DragDrop.CanDrag}", //Reset CanDrag ScriptCommands.Assign("{DragDrop.CanDrag}", false, false, //Mark handled, prevent MultiSelect from processing. HubScriptCommands.SetRoutedEventHandled( //If changed IsDraggingProperty, Find DataContext that support ISupportDrag to {ISupportDrag} variable. HubScriptCommands.AssignDataContext("{EventArgs.OriginalSource}", DataContextType.SupportDrag, "{DragDrop.SupportDrag}", null, false, //Determine DragMethod and call QueryDrag(). DragDropScriptCommands.StartLiteDrag("{DragDrop.SupportDrag}") )))))))); } } if (EnableDrop) { switch (eventId.Name) { case "QueryCursor": return(_cmdDic.GiveFeedback ?? (_cmdDic.GiveFeedback = ScriptCommands.AssignGlobalParameterDic("{DragDrop}", false, //If QueryDropResult returns none, set cursor to not droppable. ScriptCommands.IfEquals(DragDropLiteCommand.DragDropModeKey, "Lite", HubScriptCommands.QueryDropEffects("{ISupportDrop}", "{DragDrop.Draggables}", "{DataObj}", DragDropLiteCommand.DragDropEffectsKey, "{DragDrop.QueryDropResult}", false, ScriptCommands.IfEquals("{DragDrop.QueryDropResult}", QueryDropEffects.None, HubScriptCommands.SetCustomCursor(Cursors.No), HubScriptCommands.SetCustomCursor(Cursors.Arrow))))))); case "TouchMove": case "MouseMove": return(_cmdDic.MouseMove ?? (_cmdDic.MouseMove = HubScriptCommands.ThrottleTouchDrag(5, ScriptCommands.AssignGlobalParameterDic("{DragDrop}", false, //If not handled. HubScriptCommands.IfNotRoutedEventHandled( ScriptCommands.IfEquals(DragDropLiteCommand.DragDropModeKey, "Lite", HubScriptCommands.AssignDataContext("{EventArgs.OriginalSource}", DataContextType.SupportDrop, "{ISupportDrop}", "{ElementSupportDrop}", false, //And if there's one, //If Moved to different support drop. ScriptCommands.IfEquals("{ISupportDrop}", DragDropLiteCommand.DragDropDropTargetKey, DragDropScriptCommands.UpdateAdornerPointerPosition("{DragDrop.Adorner}"), HubScriptCommands.QueryDropEffects("{ISupportDrop}", "{DragDrop.Draggables}", "{DataObj}", DragDropLiteCommand.DragDropEffectsKey, "{DragDrop.QueryDropResult}", false, ScriptCommands.SetPropertyValue(DragDropLiteCommand.DragDropDropTargetKey, (ISupportDrop p) => p.IsDraggingOver, false, ScriptCommands.Assign(new Dictionary <string, object>() { { DragDropLiteCommand.DragDropDropTargetKey, "{ISupportDrop}" }, //Store SupportDrop property to global for future use. { "{DragDrop.ElementSupportDrop}", "{ElementSupportDrop}" }, //Store SupportDrop element to global for future use. { "{EventArgs.Handled}", true } //Mark RoutedEvent handled. }, false, //ScriptCommands.IfNotEquals("{DragDrop.QueryDropResult}", QueryDropEffects.None, //Attach DragAdorner and update it. ScriptCommands.SetPropertyValue(DragDropLiteCommand.DragDropDropTargetKey, (ISupportDrop p) => p.IsDraggingOver, true, DragDropScriptCommands.AttachAdorner( "{DragDrop.AdornerLayer}", "{DragDrop.Adorner}", "{ISupportDrop}", "{DragDrop.DragMethod}", "{DragDrop.Draggables}")) /*DragDropScriptCommands.DetachAdorner("{DragDrop.AdornerLayer}", "{DragDrop.Adorner}")*/))))))))))); case "TouchUp": case "PreviewMouseUp": return(_cmdDic.MouseUp ?? (_cmdDic.MouseUp = ScriptCommands.AssignGlobalParameterDic("{DragDrop}", false, ScriptCommands.IfEquals(DragDropLiteCommand.DragDropModeKey, "Lite", //Find DataContext that support ISupportDrop HubScriptCommands.AssignDataContext("{EventArgs.OriginalSource}", DataContextType.SupportDrop, "{ISupportDrop}", "{ElementSupportDrop}", false, //If ISupportDrop found. ScriptCommands.IfAssigned("{ISupportDrop}", ////Obtain DataObject from event and Call ISupportDrop.QueryDrop() to get IDraggables[] and QueryDropResult. HubScriptCommands.QueryDropEffects("{ISupportDrop}", "{DragDrop.Draggables}", "{DataObj}", DragDropLiteCommand.DragDropEffectsKey, "{DragDrop.QueryDropResult}", false, //If QueryShellDragInfo Success, if DragMethod... ScriptCommands.IfEquals(QueryDrag.DragMethodKey, DragMethod.Menu, HubScriptCommands.SetRoutedEventHandled( HubScriptCommands.ShowDragAdornerContextMenu("{DragDrop.Adorner}", "{DragDrop.QueryDropResult.SupportedEffects}", "{DragDrop.QueryDropResult.PreferredEffect}", "{ResultEffect}", //After menu closed... ScriptCommands.IfEquals("{ResultEffect}", DragDropEffectsEx.None, //If User choose None (click on empty area), detach and reset. detachAdornerAndResetDragDrop, //Otherwise, call ISupportDrop.Drop() HubScriptCommands.QueryDrop("{DragDrop.SupportDrag}", "{ISupportDrop}", "{DragDrop.Draggables}", "{DataObj}", "{ResultEffect}", "{DragDrop.DropResult}", false, //And detach adorner. detachAdornerAndResetDragDrop)))), //If DragMethod is not Menu, Drop immediately. HubScriptCommands.QueryDrop("{DragDrop.SupportDrag}", "{ISupportDrop}", "{DragDrop.Draggables}", "{DataObj}", "{DragDrop.QueryDropResult.PreferredEffect}", "{DragDrop.DropResult}", false, detachAdornerAndResetDragDrop))), //If QueryDropEffects is None, drag failed, detach adorner. detachAdornerAndResetDragDrop)))))); } } switch (eventId.Name) { case "PreviewKeyDown": return (ScriptCommands.AssignGlobalParameterDic("{DragDrop}", false, ScriptCommands.IfEquals(DragDropLiteCommand.DragDropModeKey, "Lite", HubScriptCommands.IfKeyGesture(new KeyGesture(Key.Escape), detachAdornerAndResetDragDrop)))); case "PreviewMouseUp": return (ScriptCommands.AssignGlobalParameterDic("{DragDrop}", false, ScriptCommands.IfEquals(DragDropLiteCommand.DragDropModeKey, "Lite", DragDropScriptCommands.DetachAdorner("{DragDrop.AdornerLayer}", "{DragDrop.Adorner}")))); } return(base.onEvent(eventId)); }
protected override FileExplorer.Script.IScriptCommand onEvent(RoutedEvent eventId) { switch (eventId.Name) { case "KeyDown": return (ScriptCommands.AssignGlobalParameterDic("{DragDrop}", false, //If current drag drop mode is Canvas, ScriptCommands.IfEquals(DragDropLiteCommand.DragDropModeKey, "Canvas", //And Escape is pressed. HubScriptCommands.IfKeyGesture("Esc", //Cancel Canvas drop (by clear {DragDrop} parameters) DragDropScriptCommands.CancelCanvasDrag( //Set {EventArgs.Handled} to true. HubScriptCommands.SetRoutedEventHandled( //and Detach adorner. HubScriptCommands.DettachSelectedItemsAdorner("SelectedItemsAdorner}"))))))); case "PreviewTouchDown": case "PreviewMouseDown": return //Find a DataContext that implement SupportDrag. (HubScriptCommands.AssignDataContext("{EventArgs.OriginalSource}", DataContextType.SupportDrag, "{ISupportDrag}", null, false, //And If there's one. ScriptCommands.IfAssigned("{ISupportDrag}", //Calculate a number of positions. HubScriptCommands.ObtainPointerPosition( //Assign the datacontext item to {ItemUnderMouse} HubScriptCommands.AssignItemUnderMouse("{ItemUnderMouse}", false, //And set Sender's StartDraggingItem to {ItemUnderMouse} ScriptCommands.IfAssigned("{ItemUnderMouse}", ScriptCommands.IfTrue("{ItemUnderMouse.IsSelected}", HubScriptCommands.SetDependencyProperty("{Sender}", UIEventHubProperties.StartDraggingItemProperty, "{ItemUnderMouse}")))))))); case "TouchDrag": case "MouseDrag": return //If event not marked handled. (HubScriptCommands.IfNotRoutedEventHandled( HubScriptCommands.IfDependencyPropertyEqualDefaultValue <object>("{Sender}", UIEventHubProperties.StartDraggingItemProperty, //If StartDraggingProperty = null, return. ResultCommand.NoError, //If StartDraggingProperty != null, Check and set IsDraggingProperty to true. HubScriptCommands.SetDependencyPropertyIfDifferentValue("{Sender}", UIEventHubProperties.IsDraggingProperty, true, //If changed IsDraggingProperty, Find DataContext that support ISupportDrag to {ISupportDrag} variable. HubScriptCommands.AssignDataContext("{EventArgs.OriginalSource}", DataContextType.SupportDrag, "{ISupportDrag}", null, false, //If ISupportDrag is assigned to a non-null value, //Initialize DragLiteParameters (in {DragDrop} global parameterDic). DragDropScriptCommands.StartCanvasDrag("{ISupportDrag}", //then set {EventArgs.Handled} to true. HubScriptCommands.SetRoutedEventHandled( //And attach/update adorner. HubScriptCommands.AttachSelectedItemsAdorner("{SelectedItemsAdorner}", HubScriptCommands.UpdateSelectedItemsAdorner("{SelectedItemsAdorner}"))))) , null)))); case "MouseMove": case "TouchMove": return //Only 1 of 5 TouchEvent will be processed (HubScriptCommands.ThrottleTouchDrag(5, ScriptCommands.AssignGlobalParameterDic("{DragDrop}", false, ScriptCommands.IfEquals(DragDropLiteCommand.DragDropModeKey, "Canvas", HubScriptCommands.ObtainPointerPosition( //Update adorner CentrePosition. HubScriptCommands.UpdateSelectedItemsAdorner("{SelectedItemsAdorner}")))))); case "PreviewTouchUp": case "PreviewMouseUp": return (HubScriptCommands.SetDependencyPropertyIfDifferentValue("{Sender}", UIEventHubProperties.IsDraggingProperty, false, HubScriptCommands.SetDependencyPropertyValue <object>("{Sender}", UIEventHubProperties.StartDraggingItemProperty, null, //Update position of each IPostionAware and clear {DragDrop} parameters) DragDropScriptCommands.EndCanvasDrag( //Set {EventArgs.Handled} to true. HubScriptCommands.SetRoutedEventHandled( //Detach adorner. HubScriptCommands.DettachSelectedItemsAdorner("SelectedItemsAdorner}")))))); } return(base.onEvent(eventId)); }
protected override IScriptCommand executeInner(ParameterDic pm, Control sender, RoutedEventArgs evnt, IUIInput input, IList <IUIInputProcessor> inpProcs) { if (!pm.HasValue <ParameterDic>("{DragDrop}")) { ScriptCommands.AssignGlobalParameterDic("{DragDrop}", false).Execute(pm); } if (!pm.HasValue <Point>(CurrentPositionAdjustedKey)) { HubScriptCommands.ObtainPointerPosition().Execute(pm); } logger.Debug(State.ToString()); switch (State) { case DragDropLiteState.StartLite: case DragDropLiteState.StartCanvas: string mode = State == DragDropLiteState.StartLite ? "Lite" : "Canvas"; if (dragStart(pm, input, mode)) { foreach (var item in pm.GetValue <IEnumerable <IDraggable> >(DragDropDraggingItemsKey) .Where(i => (State == DragDropLiteState.StartLite) || i is IPositionAware)) { item.IsDragging = true; } return(NextCommand); } else { return(FailCommand); } case DragDropLiteState.EndLite: case DragDropLiteState.EndCanvas: case DragDropLiteState.CancelCanvas: //foreach (var item in pm.GetValue<IEnumerable<IDraggable>>(DragDropDraggingItemsKey)) // item.IsDragging = true; if (pm.HasValue <Point>(DragDropStartPositionKey)) { Point currentPosition = pm.GetValue <Point>(CurrentPositionAdjustedKey); Point startPosition = pm.GetValue <Point>(DragDropStartPositionKey); Vector movePt = currentPosition - startPosition; var items = pm.GetValue <IEnumerable <IDraggable> >(DragDropDraggingItemsKey); foreach (var item in items) { item.IsDragging = false; } if (State == DragDropLiteState.EndCanvas) { foreach (var posAwareItem in items.Cast <IPositionAware>()) { posAwareItem.OffsetPosition(movePt); } } } dragEnd(pm); return(NextCommand); default: return(ResultCommand.Error(new NotSupportedException(State.ToString()))); } }
protected override FileExplorer.Script.IScriptCommand onEvent(RoutedEvent eventId) { if (EnableDrag) { switch (eventId.Name) { case "PreviewMouseDown": return(_cmdDic.PreviewMouseDown ?? (_cmdDic.PreviewMouseDown = ScriptCommands.AssignGlobalParameterDic("{DragDrop}", false, //Set Default value for CanDrag first. ScriptCommands.Assign("{DragDrop.CanDrag}", false, false, //Find a DataContext that implement SupportDrag, and if assigned HubScriptCommands.IfHasDataContext("{EventArgs.OriginalSource}", DataContextType.SupportShellDrag, //and item under mouse (ISelectable) IsSelected. DragDropScriptCommands.IfItemUnderMouseIsSelected( //Notify MouseDrag can drag. ScriptCommands.Assign("{DragDrop.CanDrag}", true, false, //Prevent MultiSelect from starting. HubScriptCommands.SetRoutedEventHandled()) )))))); case "MouseDrag": return(_cmdDic.MouseDrag ?? (_cmdDic.MouseDrag = ScriptCommands.AssignGlobalParameterDic("{DragDrop}", false, //If not handled. HubScriptCommands.IfNotRoutedEventHandled( //IfCanDrag (assigned from PreviewMouseDown) ScriptCommands.IfTrue("{DragDrop.CanDrag}", //Reset CanDrag ScriptCommands.Assign("{DragDrop.CanDrag}", false, false, //Mark handled, prevent MultiSelect from processing. HubScriptCommands.SetRoutedEventHandled( //If changed IsDraggingProperty, Find DataContext that support ISupportDrag to {ISupportDrag} variable. HubScriptCommands.AssignDataContext("{EventArgs.OriginalSource}", DataContextType.SupportShellDrag, "{DragDrop.SupportDrag}", null, false, //Determine DragMethod and call QueryDrag(). DragDropScriptCommands.StartShellDrag("{DragDrop.SupportDrag}") )))))))); case "PreviewMouseUp": return(_cmdDic.PreviewMouseUp ?? (_cmdDic.PreviewMouseUp = ScriptCommands.AssignGlobalParameterDic("{DragDrop}", false, //HubScriptCommands.SetDependencyPropertyValue("{Sender}", AttachedProperties.IsDraggingProperty, false, ScriptCommands.IfEquals(QueryDrag.DragMethodKey, DragMethod.Menu, ResultCommand.NoError, //This is defined in drop, detach if there's an adorner. DragDropScriptCommands.DetachAdorner("{DragDrop.AdornerLayer}", "{DragDrop.Adorner}"))))); case "MouseMove": return(_cmdDic.MouseMove ?? (_cmdDic.MouseMove = HubScriptCommands.IfDependencyProperty("{Sender}", UIEventHubProperties.IsDraggingProperty, ComparsionOperator.Equals, true, HubScriptCommands.SetRoutedEventHandled()))); } } if (EnableDrop) { switch (eventId.Name) { case "DragEnter": return(_cmdDic.DragEnter ?? (_cmdDic.DragEnter = ScriptCommands.AssignGlobalParameterDic("{DragDrop}", false, //Find DataContext that support IShellDrop HubScriptCommands.AssignDataContext("{EventArgs.OriginalSource}", DataContextType.SupportShellDrop, "{ISupportDrop}", "{ElementSupportDrop}", false, //And if there's one, ScriptCommands.IfAssigned("{ISupportDrop}", HubScriptCommands.QueryShellDragInfo("{ISupportDrop}", "{DataObj}", "{DragDrop.Draggables}", "{DragDrop.QueryDropResult}", false, //Otherwise, ScriptCommands.Assign(new Dictionary <string, object>() { { "{DragDrop.SupportDrop}", "{ISupportDrop}" }, //Store SupportDrop property to global for future use. { "{DragDrop.ElementSupportDrop}", "{ElementSupportDrop}" }, //Store SupportDrop element to global for future use. { "{ISupportDrop.IsDraggingOver}", true }, //Set DataContext.IsDraggingOver to true. { "{EventArgs.Handled}", true } //Mark RoutedEvent handled. }, false, //Attach DragAdorner and update it. DragDropScriptCommands.AttachAdorner( "{DragDrop.AdornerLayer}", "{DragDrop.Adorner}", "{ISupportDrop}", "{DragDrop.DragMethod}", "{DragDrop.Draggables}"))), DragDropScriptCommands.DetachAdorner("{DragDrop.AdornerLayer}", "{DragDrop.Adorner}")))))); case "GiveFeedback": return(_cmdDic.GiveFeedback ?? (_cmdDic.GiveFeedback = ScriptCommands.AssignGlobalParameterDic("{DragDrop}", false, //If QueryDropResult returns none, set cursor to not droppable. ScriptCommands.IfEquals("{DragDrop.QueryDropResult}", QueryDropEffects.None, HubScriptCommands.SetCustomCursor(Cursors.No))))); case "DragOver": return(_cmdDic.DragOver ?? (_cmdDic.DragOver = ScriptCommands.AssignGlobalParameterDic("{DragDrop}", false, DragDropScriptCommands.UpdateAdornerPointerPosition("{DragDrop.Adorner}")))); case "DragLeave": return(_cmdDic.DragLeave ?? (_cmdDic.DragLeave = ScriptCommands.AssignGlobalParameterDic("{DragDrop}", false, ScriptCommands.SetPropertyValue("{DragDrop.SupportDrop}", "IsDraggingOver", false, //Detach adorner if DragLeave current element. ScriptCommands.IfAssigned("{DragDrop.SupportDrop}", DragDropScriptCommands.DetachAdorner("{DragDrop.AdornerLayer}", "{DragDrop.Adorner}")))))); case "Drop": IScriptCommand detachAdornerAndResetDragDrop = ScriptCommands.SetPropertyValue("{DragDrop.SupportDrop}", "IsDraggingOver", false, DragDropScriptCommands.DetachAdorner("{DragDrop.AdornerLayer}", "{DragDrop.Adorner}", ScriptCommands.Reset(null, "{DragDrop.Adorner}", "{DragDrop.AdornerLayer}", "{DragDrop.SupportDrop}", "{DragDrop.Draggables}"))); return(_cmdDic.Drop ?? (_cmdDic.Drop = ScriptCommands.AssignGlobalParameterDic("{DragDrop}", false, //Find DataContext that support ISupportShellDrop HubScriptCommands.AssignDataContext("{EventArgs.OriginalSource}", DataContextType.SupportShellDrop, "{ISupportDrop}", "{ElementSupportDrop}", false, //If ISupportDrop found. ScriptCommands.IfAssigned("{ISupportDrop}", ////Obtain DataObject from event and Call ISupportDrop.QueryDrop() to get IDraggables[] and QueryDropResult. HubScriptCommands.SetRoutedEventHandled( HubScriptCommands.QueryShellDragInfo("{ISupportDrop}", "{DataObj}", "{DragDrop.Draggables}", "{DragDrop.QueryDropResult}", false, //If QueryShellDragInfo Success, if DragMethod... ScriptCommands.IfEquals(QueryDrag.DragMethodKey, DragMethod.Menu, //Backup because ISupportDrag parameter is reset after this command is completed. ScriptCommands.Assign("{DragDrop.SupportDragBackup}", "{DragDrop.SupportDrag}", false, //is Menu, then Show Menu. HubScriptCommands.ShowDragAdornerContextMenu("{DragDrop.Adorner}", "{DragDrop.QueryDropResult.SupportedEffects}", "{DragDrop.QueryDropResult.PreferredEffect}", "{ResultEffect}", //After menu closed... ScriptCommands.IfEquals("{ResultEffect}", DragDropEffectsEx.None, //If User choose None (click on empty area), detach and reset. detachAdornerAndResetDragDrop, //Otherwise, call ISupportDrop.Drop() HubScriptCommands.QueryDrop("{DragDrop.SupportDragBackup}", "{ISupportDrop}", "{DragDrop.Draggables}", "{DataObj}", "{ResultEffect}", "{DragDrop.DropResult}", false, //And detach adorner. detachAdornerAndResetDragDrop)))), //If DragMethod is not Menu, Drop immediately. HubScriptCommands.QueryDrop("{DragDrop.SupportDrag}", "{ISupportDrop}", "{DragDrop.Draggables}", "{DataObj}", "{DragDrop.QueryDropResult.PreferredEffect}", "{DragDrop.DropResult}", false, detachAdornerAndResetDragDrop)), //If QueryDropEffects is None, drag failed, detach adorner. detachAdornerAndResetDragDrop))))))); } } return(base.onEvent(eventId)); }