Exemple #1
0
 private void DragDropTarget_Drop(object sender, Microsoft.Windows.DragEventArgs e)
 {
     try
     {
         if (e.Data.GetDataPresent(typeof(ItemDragEventArgs)))
         {
             ItemDragEventArgs   cItemDragEventArgs   = (ItemDragEventArgs)e.Data.GetData(typeof(ItemDragEventArgs));
             SelectionCollection aSelectionCollection = (SelectionCollection)cItemDragEventArgs.Data;
             object oItemSelected = aSelectionCollection.Select(o => o.Item).FirstOrDefault();
             if (null != oItemSelected && Microsoft.Windows.DragDropEffects.Move == cItemDragEventArgs.Effects)
             {
                 if (_ui_lbLeft == cItemDragEventArgs.DragSource && _ui_dlbRight == sender)
                 {
                     SelectionChange(oItemSelected, true);
                 }
                 else if (_ui_tvLeft == cItemDragEventArgs.DragSource && _ui_dtvRight == sender)
                 {
                     SelectionChange(oItemSelected, true);
                 }
                 else if (_ui_lbRight == cItemDragEventArgs.DragSource && _ui_dlbLeft == sender)
                 {
                     SelectionChange(oItemSelected, false);
                 }
                 else if (_ui_tvRight == cItemDragEventArgs.DragSource && _ui_dtvLeft == sender)
                 {
                     SelectionChange(oItemSelected, false);
                 }
             }
         }
     }
     catch (Exception ex)
     {
         (new controls.childs.sl.MsgBox()).ShowError(ex);
     }
 }
Exemple #2
0
        protected override void OnItemDragStarting(ItemDragEventArgs eventArgs)
        {
            SelectionCollection selectionCollection = eventArgs.Data as SelectionCollection;

            foreach (Selection selection in selectionCollection)
            {
                if (selection.Item.GetType().Equals(typeof(Block)))
                {
                    if (((Block)selection.Item).flag_isPackage)
                    {
                        eventArgs.Cancel  = true;
                        eventArgs.Handled = true;
                    }
                    else
                    {
                        base.OnItemDragStarting(eventArgs);
                        ListBox listBox     = eventArgs.DragSource as ListBox;
                        var     testingList = listBox.ItemsSource;
                        if (testingList.GetType().Equals(typeof(ObservableCollection <Block>)))
                        {
                            ObservableCollection <Block> list = testingList as ObservableCollection <Block>;
                            listBox.ItemsSource = null;
                            var itemsToRemove = list.Where(item => !item.flag_isPackage).ToArray();
                            foreach (var item in itemsToRemove)
                            {
                                list.Remove(item);
                            }
                            listBox.ItemsSource = list;

                            listBox.ScrollIntoView(listBox.Items.ElementAt(0));
                        }
                    }
                }
            }
        }
        protected override void OnItemDroppedOnTarget(ItemDragEventArgs args)
        {
            //Debug.WriteLine("Editor On Item drop");
            ListBox             listBox             = args.DragSource as ListBox;
            SelectionCollection selectionCollection = args.Data as SelectionCollection;

            foreach (Selection selection in selectionCollection)
            {
                if (selection.Item.GetType().Equals(typeof(Block)))
                {
                    move = false;
                    if (MainPage.communicate.trash)
                    {
                        MainPage.communicate.trash = false;
                        listBox.ItemsSource        = tree.Delete(((Block)selection.Item).index);
                    }
                }
            }
            try
            {
                base.OnItemDroppedOnTarget(args);
                listBox.ItemsSource = tree.ListRefresh();
                Refresh(listBox);
            }
            catch (Exception exe)
            {
            }
        }
        protected override void OnItemDragStarting(ItemDragEventArgs eventArgs)
        {
            //Debug.WriteLine("Editor drag start");
            SelectionCollection selectionCollection = eventArgs.Data as SelectionCollection;

            foreach (Selection selection in selectionCollection)
            {
                if (selection.Item.GetType().Equals(typeof(Block)))
                {
                    if (((Block)selection.Item).Text.Contains("END"))
                    {
                        eventArgs.Cancel  = true;
                        eventArgs.Handled = true;
                    }
                    else
                    {
                        if (!MainPage.communicate.socket) //check to see that you are not moving a socket
                        {
                            move      = true;
                            fromIndex = ((Block)selection.Item).index;
                        }
                        base.OnItemDragStarting(eventArgs);
                    }
                }
            }
        }
Exemple #5
0
        /// <summary>
        /// Returns data as a SelectionCollection.
        /// </summary>
        /// <param name="data">The data object.</param>
        /// <returns>A selection collection.</returns>
        internal static SelectionCollection ToSelectionCollection(object data)
        {
            //------------------------
            // The purpose of this method is to wrap data into a "Selection" class
            // (unless it is already a Selection), and then put the Selection
            // into a SelectionCollection (unless it is already a SelectionCollection).
            //------------------------

            if (data == null)
            {
                return(new SelectionCollection());
            }

            SelectionCollection selectionCollection = data as SelectionCollection;

            if (selectionCollection == null)
            {
                selectionCollection = new SelectionCollection();
                Selection selection = data as Selection;
                if (selection == null)
                {
                    selection = new Selection(data);
                }
                selectionCollection.Add(selection);
            }

            return(selectionCollection);
        }
        /// <summary>
        /// Adds all selected items when drag operation begins.
        /// </summary>
        /// <param name="eventArgs">Information about the event.</param>
        protected override void OnItemDragStarting(ItemDragEventArgs eventArgs)
        {
            SelectionCollection selectionCollection = new SelectionCollection(this.DataGrid.SelectedItems.OfType <object>());

            eventArgs.Data = selectionCollection;

            CardPanel cardPanel = new CardPanel();
            IEnumerable <DataGridRow> itemContainers =
                (from item in selectionCollection.Select(selection => selection.Item)
                 let row =
                     this.DataGrid
                     .GetVisualDescendants()
                     .OfType <DataGridRow>()
                     .FirstOrDefault()
                     where row != null
                     select row);

            foreach (DataGridRow row in itemContainers)
            {
                cardPanel.Children.Add(new Image {
                    Source = new WriteableBitmap(row, new TranslateTransform())
                });
            }

            eventArgs.DragDecoratorContent = cardPanel;

            eventArgs.Handled = true;
            base.OnItemDragStarting(eventArgs);
        }
        protected bool IsTreeViewItemDraggedInDescendent(SW.DragEventArgs args)
        {
            ItemDragEventArgs itemDragEventArgs = args.Data.GetData() as ItemDragEventArgs;

            if (itemDragEventArgs != null)
            {
                ItemsControl itemsControl = GetDropTarget(args);
                if (itemsControl == null)
                {
                    return(false);
                }

                ItemsControl dragSource = itemDragEventArgs.DragSource as ItemsControl;
                // If the items control that contains the item being dragged over has the drag source as a descendent
                if (dragSource != null && itemsControl.GetVisualAncestors().Contains(dragSource))
                {
                    SelectionCollection            selectionCollection    = GetSelectionCollection(itemDragEventArgs.Data);
                    IEnumerable <DependencyObject> visualAncestorsAndSelf = itemsControl.GetVisualAncestorsAndSelf().ToList();

                    return(selectionCollection.Any(selection => !selection.Index.HasValue || visualAncestorsAndSelf.Any(ancestor => dragSource.ItemContainerGenerator.IndexFromContainer(ancestor) == selection.Index.Value)));
                }
            }
            // Can only tell if dragging into descendent if drag operation
            // originated from a DragDropTarget object, and the data has
            // information about the index of the dragged item within its
            // DragSource.
            return(false);
        }
        /// <summary>
        /// Returns a value indicating whether a TreeViewItem being dragged
        /// directly above or below itself.  If there are no indices in the
        /// selection the answer is result is always true.
        /// </summary>
        /// <param name="args">Information about a drag event.</param>
        /// <returns>A value indicating whether the TreeViewItem being dragged
        /// directly above or below itself.</returns>
        protected bool IsTreeViewItemDraggedDirectlyAboveOrBelowSelf(SW.DragEventArgs args)
        {
            ItemsControl      dropTarget        = GetDropTarget(args);
            ItemDragEventArgs itemDragEventArgs = args.Data.GetData() as ItemDragEventArgs;

            if (itemDragEventArgs != null && itemDragEventArgs.DragSource != null && itemDragEventArgs.DragSource == dropTarget)
            {
                SelectionCollection selectionCollection = GetSelectionCollection(itemDragEventArgs.Data);
                int index = GetDropTargetInsertionIndex(dropTarget, args);
                return(selectionCollection.Any(selection => !selection.Index.HasValue || selection.Index.Value == index));
            }
            return(false);
        }
        private void PerfilxPermisoTarget_Drop(object sender, Microsoft.Windows.DragEventArgs e)
        {
            object              data                = e.Data.GetData(e.Data.GetFormats()[0]);
            ItemDragEventArgs   dragEventArgs       = data as ItemDragEventArgs;
            SelectionCollection selectionCollection = dragEventArgs.Data as SelectionCollection;

            if (selectionCollection != null)
            {
                IEnumerable <T_Permiso> permisos = selectionCollection.Select(selection => selection.Item).OfType <T_Permiso>();
                if (permisos.Any())
                {
                    foreach (T_Permiso per in permisos)
                    {
                        vm.ListPermiso.Add(per);
                    }
                }
            }
        }
        protected override void OnItemDragStarting(ItemDragEventArgs eventArgs)
        {
            SelectionCollection selectionCollection = eventArgs.Data as SelectionCollection;

            foreach (Selection selection in selectionCollection)
            {
                if (selection.Item.GetType().Equals(typeof(Block)))
                {
                    ListBox listBox     = eventArgs.DragSource as ListBox;
                    var     testingList = listBox.ItemsSource;
                    if (testingList.GetType().Equals(typeof(ObservableCollection <Block>)))
                    {
                        ObservableCollection <Block> blockList = testingList as ObservableCollection <Block>;
                        list = new ObservableCollection <Block>();
                        foreach (Block b in blockList)
                        {
                            list.Add(b);
                        }
                    }
                    base.OnItemDragStarting(eventArgs);
                }
            }
        }
        public static IEnumerable <T> GetData <T>(this DragEventArgs args)
        {
            IEnumerable <T> results = null;

            // Get the dropped data from the Data property and cast it to the first format.
            ItemDragEventArgs dragEventArgs = args.Data.GetData(args.Data.GetFormats()[0]) as ItemDragEventArgs;

            if (dragEventArgs == null)
            {
                return(results);
            }

            // Get the collection of items
            SelectionCollection selectionCollection = dragEventArgs.Data as SelectionCollection;

            if (selectionCollection != null)
            {
                // cast each item to what is expected
                results = selectionCollection.Select(selection => selection.Item).OfType <T>();
            }

            return(results);
        }
Exemple #12
0
        void OnDropped(PointerRoutedEventArgs e)
#endif
        {
            _popup.IsOpen = false;

            //We no longer have use for the popup
            _popup.Child = null;
            _popup       = null;

            // Prepare the event arguments:
            Selection           selection           = new Selection(_sourceItemContainer);
            SelectionCollection selectionCollection = SelectionCollection.ToSelectionCollection(selection);

            // Get the DragDropTarget element that is under the pointer, if any:
            TItemContainerType targetItemContainer;
            DragDropTarget <TItemsControlType, TItemContainerType> dragDropTargetUnderPointer = GetDragDropTargetUnderPointer(_pointerX, _pointerY, out targetItemContainer);

            if (dragDropTargetUnderPointer != null)
            {
                //---------------------------------
                // IF A DROP TARGET IS FOUND
                //---------------------------------

                // Check if drop is allowed:
                if (dragDropTargetUnderPointer.AllowDrop && !_isDragCancelled)
                {
                    TItemsControlType targetContainer = (TItemsControlType)dragDropTargetUnderPointer.Content; // Note: a "container" is for example a Panel in case of PanekDragDropTarget.

                    // Check if we are dropping on the source element itself (ie. from the source to the placeholder that we put in place of the source) (cf. "ItemDropOnSource" event):
                    if (ContainerFromIndex(targetContainer, _indexOfSourceContainerWithinItemsControl) == _sourcePlaceholder)
                    {
                        //---------------------------------
                        // IF WE ARE DROPPING THE SOURCE ON ITSELF
                        //---------------------------------

                        // Put the dragged element back to where it was:
                        PutSourceBackToOriginalPlace();

                        //Raise the "ItemDroppedOnSource" Event
                        if (dragDropTargetUnderPointer.ItemDroppedOnSource != null)
                        {
                            // Prepare the event args:
                            DataObject dataObject = new DataObject();
                            dataObject.SetData("ItemDragEventArgs", new ItemDragEventArgs(selectionCollection));

#if !(BRIDGE && MIGRATION)
                            dragDropTargetUnderPointer.ItemDroppedOnSource(dragDropTargetUnderPointer, new MS.DragEventArgs(dataObject, e));
#endif
                        }
                    }
                    //else we drop on another DragDropTarget
                    else
                    {
                        //---------------------------------
                        // IF WE ARE DROPPING ON ANOTHER DRAGDROPTARGET
                        //---------------------------------

                        // Remove the temporary placeholder (see the comment where the placeholder is defined):
                        this.RemoveItemAtIndex(_sourceItemsControl, _indexOfSourceContainerWithinItemsControl);

                        // Raise the Drop event:
                        if (dragDropTargetUnderPointer.Drop != null)
                        {
                            // Prepare the event args:
                            DataObject dataObject = new DataObject();
                            dataObject.SetData("ItemDragEventArgs", new ItemDragEventArgs(selectionCollection));

                            // Raise the Drop event:
#if !(BRIDGE && MIGRATION)
                            dragDropTargetUnderPointer.Drop(dragDropTargetUnderPointer, new MS.DragEventArgs(dataObject, e));
#endif
                        }

                        // Put the source into the target:
                        dragDropTargetUnderPointer.AddItem((TItemsControlType)dragDropTargetUnderPointer.Content, _sourceItemContainer);
                    }
                }
                //Can't drop so we put what was in the popup back in the content
                else
                {
                    // Put the dragged element back to where it was:
                    PutSourceBackToOriginalPlace();
                }
            }
            //not a DragDropTarget under the pointer so we put what was in the popup back in the content
            else
            {
                // Put the dragged element back to where it was:
                PutSourceBackToOriginalPlace();
            }

            // Raise the "ItemDragCompleted" event:
            if (ItemDragCompleted != null)
            {
                ItemDragCompleted(this, new ItemDragEventArgs(selectionCollection));
            }
        }
Exemple #13
0
        private void MovePopupAndRaiseEvents(double horizontalChange, double verticalChange)
        {
#if !(BRIDGE && MIGRATION)
            if (_popup != null)
            {
                //popup moving with the pointer
                _popup.HorizontalOffset += horizontalChange;
                _popup.VerticalOffset   += verticalChange;
            }

            // Prepare the "DragEventArgs" to pass to the raised events:
            Selection           selection           = new Selection(_sourceItemContainer);
            SelectionCollection selectionCollection = SelectionCollection.ToSelectionCollection(selection);
            DataObject          dataObject          = new DataObject();
            dataObject.SetData("ItemDragEventArgs", new ItemDragEventArgs(selectionCollection));
            MS.DragEventArgs dragOverEventArgs = new MS.DragEventArgs(dataObject);

            // Get the DragDropTarget element that is under the pointer, if any:
            TItemContainerType targetItemContainer;
            DragDropTarget <TItemsControlType, TItemContainerType> dragDropTargetUnderPointer = GetDragDropTargetUnderPointer(_pointerX, _pointerY, out targetItemContainer);

            // Check if the element under the pointer has changed since the last PointerMoved:
            if (_previousdragDropTargetUnderPointer != dragDropTargetUnderPointer)
            {
                //---------------------------------
                // IF WHAT IS UNDER THE POINTER HAS CHANGED
                //---------------------------------

                // Raise the DragLeave event of the element that was under the pointer before:
                if (_previousdragDropTargetUnderPointer != null && _previousdragDropTargetUnderPointer.DragLeave != null)
                {
                    _previousdragDropTargetUnderPointer.DragLeave(_previousdragDropTargetUnderPointer, new MS.DragEventArgs(dataObject));

                    // Reset the value of "_isDragCancelled" when leaving a control. This variable lets the user prevent a Drop on an element when the user sets e.Handled=true in the "DragOver" event of that element.
                    _isDragCancelled = false;
                }
                // Remember the element that is under the pointer:
                _previousdragDropTargetUnderPointer = dragDropTargetUnderPointer;

                // Raise the DragEnter event of the new element that is under the pointer:
                if (dragDropTargetUnderPointer != null && dragDropTargetUnderPointer.DragEnter != null)
                {
                    dragDropTargetUnderPointer.DragEnter(dragDropTargetUnderPointer, new MS.DragEventArgs(dataObject));
                }
            }

            if (dragDropTargetUnderPointer != null)
            {
                //---------------------------------
                // IF UNDER THE POINTER THERE IS A DRAGDROPPANEL
                //---------------------------------

                // Raise the DragOver:
                dragDropTargetUnderPointer.OnDragOver(dragOverEventArgs);

                // Cancel the drag drop operation if the user has marked the DragOver event as "handled":
                if (dragOverEventArgs.Handled && dragOverEventArgs.Effects == DragDropEffects.None)
                {
                    _isDragCancelled = true;
                }
            }

            // Show the appropriate icon depending on whether it is possible to drop or not:
            if (dragDropTargetUnderPointer != null && dragDropTargetUnderPointer.AllowDrop && !_isDragCancelled)
            {
                //---------------------------------
                // SHOW ICON "DRAG ALLOWED"
                //---------------------------------
                _iconArrow.Visibility = Visibility.Visible;
                _iconStop.Visibility  = Visibility.Collapsed;
            }
            else
            {
                //---------------------------------
                // SHOW ICON "DRAG FORBIDDEN"
                //---------------------------------
                _iconArrow.Visibility = Visibility.Collapsed;
                _iconStop.Visibility  = Visibility.Visible;
            }
#endif
        }
Exemple #14
0
        private void DragDropTarget_PointerPressed(object sender, PointerRoutedEventArgs e)
#endif
        {
            //----------------------------------
            // DRAG OPERATION STARTS HERE
            //----------------------------------

            // Prevent the PointerPressed event from bubbling up so that if there are two nested DragDropTargets, only the inner one will be dragged:
            e.Handled = true;

            // We verify that drag operation is not taking place, which can lead a case if we missed the pointer released event due to a glitch such as moving the mouse outside the browser and releasing
            if (!_isPointerCaptured)
            {
                // Reset some variables:
                _isDragCancelled = false;
                _previousdragDropTargetUnderPointer = null;

                // Remember the current pointer position:
#if MIGRATION
                _pointerX = e.GetPosition(null).X;
                _pointerY = e.GetPosition(null).Y;
#else
                _pointerX = e.GetCurrentPoint(null).Position.X;
                _pointerY = e.GetCurrentPoint(null).Position.Y;
#endif
                // Get the source DragDropTarget element that is under the pointer, if any:
                DragDropTarget <TItemsControlType, TItemContainerType> sourceDragDropTarget = GetDragDropTargetUnderPointer(_pointerX, _pointerY, out _sourceItemContainer);
                if (sourceDragDropTarget != this)
                {
                    throw new Exception("The DragDropTarget is not supposed to support dragging an outer DragDropTarget in case of nested DragDropTargets.");
                }

                // We do something only if the source exists (ie. if an item was found under the pointer):
                if (_sourceItemContainer != null)
                {
                    // Get a reference to the ItemsControl:
                    _sourceItemsControl = (TItemsControlType)this.Content; // Note: there is no risk of InvalidCastException because the type has been tested before, and the derived class (PanelDragDropTarget) also verifies the type in the "OnContentChanged" method.

                    // Capture the pointer so that when dragged outside the DragDropPanel, we can still get its position:
    #if MIGRATION
                    this.CaptureMouse();
    #else
                    this.CapturePointer(e.Pointer);
    #endif
                    // Remember that the pointer is currently captured:
                    _isPointerCaptured = true;
                    _capturedPointer   = e.Pointer;

                    //Size of the content
                    double height;
                    double width;
                    if (_sourceItemContainer is FrameworkElement)
                    {
                        Size actualSize = (_sourceItemContainer as FrameworkElement).INTERNAL_GetActualWidthAndHeight();
                        height = actualSize.Height;
                        width  = actualSize.Width;
                    }
                    else
                    {
                        height = double.NaN;
                        width  = double.NaN;
                    }

                    // Prepare the arguments of the "ItemDragStarting" event:
                    Selection           selection                 = new Selection(_sourceItemContainer);
                    SelectionCollection selectionCollection       = SelectionCollection.ToSelectionCollection(selection);
                    ItemDragEventArgs   itemDragStartingEventArgs = new ItemDragEventArgs(selectionCollection);

                    // Raise the "ItemDragStarting" event:
                    if (ItemDragStarting != null)
                    {
                        ItemDragStarting(this, itemDragStartingEventArgs);
                    }

                    // Show the popup, unless the user has cancelled the drag operation:
                    if (itemDragStartingEventArgs.Handled && itemDragStartingEventArgs.Cancel)
                    {
                        //----------------------------------
                        // CANCELLED BY USER
                        //----------------------------------

                        if (_isPointerCaptured)
                        {
                            // Stop capturing the pointer:
                            _isPointerCaptured = false;

#if MIGRATION
                            this.ReleaseMouseCapture();
#else
                            this.ReleasePointerCapture(_capturedPointer);
#endif
                        }
                    }
                    else
                    {
                        //----------------------------------
                        // SHOW POPUP
                        //----------------------------------

                        // Put a placeholder in place of the source that will occupy the same space. This is useful to: 1) let the user drop over the source itself (cf. "ItemDroppedOnSource" event), and 2) prevent the other elements from being displaced during the drag operation.
                        RemoveSourceAndPutTransparentPlaceholderInPlace(height, width);

                        // Put the source into a popup:
                        StackPanel stackPanelInPopUp = GeneratePopupContent(_sourceItemContainer, out _iconStop, out _iconArrow);
                        this._popup = new Popup()
                        {
                            Child = stackPanelInPopUp,
                            HorizontalAlignment        = HorizontalAlignment.Left,
                            VerticalAlignment          = VerticalAlignment.Top,
                            HorizontalContentAlignment = HorizontalAlignment.Left,
                            VerticalContentAlignment   = VerticalAlignment.Top,
                            IsHitTestVisible           = false
                        };

                        // Set the popup position:
                        this._popup.HorizontalOffset = this._pointerX;
                        this._popup.VerticalOffset   = this._pointerY;

                        // Show the popup:
                        this._popup.IsOpen = true;
                    }
                }
            }
        }
 /// <summary>
 /// Initializes a new instance of the ItemDragEventArgs class.
 /// </summary>
 internal ItemDragEventArgs(SelectionCollection data)
 {
     this.Data = data;
 }
        /// <summary>
        /// Adds all selected items when drag operation begins.
        /// </summary>
        /// <param name="eventArgs">Information about the event.</param>
        protected override void OnItemDragStarting(ItemDragEventArgs eventArgs)
        {
            SelectionCollection selectionCollection = new SelectionCollection();

            // If panel is virtualized there is no way of knowing the precise
            // index of each selected item.
            Panel itemsHost = this.ListBox.GetItemsHost();

            if (itemsHost is VirtualizingPanel)
            {
                foreach (object item in this.ListBox.SelectedItems)
                {
                    selectionCollection.Add(new Selection(item));
                }

                // Adding the item dragged even if it isn't selected
                SelectionCollection defaultSelectionCollection = SelectionCollection.ToSelectionCollection(eventArgs.Data);

                if (defaultSelectionCollection.Count == 1 && !selectionCollection.Any(selection => object.Equals(selection.Item, defaultSelectionCollection[0].Item)))
                {
                    selectionCollection.Add(defaultSelectionCollection[0]);
                }
            }
            else
            {
                for (int cnt = 0; cnt < this.ListBox.Items.Count; cnt++)
                {
                    ListBoxItem listBoxItem = this.ListBox.ItemContainerGenerator.ContainerFromIndex(cnt) as ListBoxItem;
                    if (listBoxItem.IsSelected)
                    {
                        selectionCollection.Add(new Selection(cnt, this.ListBox.Items[cnt]));
                    }
                }

                // Adding the item dragged even if it isn't selected
                SelectionCollection defaultSelectionCollection = GetSelectionCollection(eventArgs.Data);
                if (defaultSelectionCollection.Count == 1)
                {
                    if (selectionCollection.All(selection => selection.Index != defaultSelectionCollection[0].Index))
                    {
                        selectionCollection.Add(defaultSelectionCollection[0]);
                    }
                }
            }

            eventArgs.Data = selectionCollection;

            CardPanel cardPanel = new CardPanel();
            IEnumerable <UIElement> itemContainers =
                selectionCollection.SelectedItems
                .Select(item => this.ListBox.ItemContainerGenerator.ContainerFromItem(item))
                .Where(item => item != null)
                .OfType <UIElement>();

            foreach (ListBoxItem row in itemContainers)
            {
                cardPanel.Children.Add(new Image {
                    Source = new WriteableBitmap(row, new TranslateTransform())
                });
            }

            eventArgs.DragDecoratorContent = cardPanel;

            eventArgs.Handled = true;
            base.OnItemDragStarting(eventArgs);
        }
Exemple #17
0
        /*
         * Event method that is called when a socket item is dropped on destination.
         * Preforms functions based on the communication class.
         * Set the communication flag for socket to false (handled).
         * Calls parent method
         */
        protected override void OnItemDroppedOnTarget(ItemDragEventArgs args)
        {
            Debug.WriteLine("socket on item drop");
            ListBox listBox = args.DragSource as ListBox;

            SelectionCollection selectionCollection = args.Data as SelectionCollection;

            foreach (Selection selection in selectionCollection)
            {
                if (selection.Item.GetType().Equals(typeof(Block)))
                {
                    //create the block based on selection block
                    Block copyBlock = MainPage.createProgramStructureBlock(((Block)selection.Item).typeID);
                    if (copyBlock == null)
                    {
                        if (!((Block)selection.Item).Text.Contains("END"))
                        {
                            copyBlock = ((Block)selection.Item).cloneSelf(true);
                        }
                        else
                        {
                            copyBlock = MainPage.createReservedBlock(((Block)selection.Item).Text);
                        }
                    }

                    if (MainPage.communicate.trash)          //socket moved to trash
                    {
                        MainPage.communicate.trash  = false; //let trash know that socket finished move
                        listBox.Background.Opacity  = 1;     //show empty socket
                        listBox.BorderBrush.Opacity = 1;     //show empty socket
                    }
                    else if (MainPage.communicate.editor)    //socket moved to editor (removed communicate.socket to see if communication error is fixed)
                    {
                        //copyBlock goes here
                        if (listBox.Items.Count == 0)
                        {
                            Debigulate(listBox);
                            if (socketType.Contains(copyBlock.Text))
                            {
                                ResizeAndAdd(listBox, copyBlock);
                            }
                            else if (isConstant && copyBlock.flag_isConstant)
                            {
                                ResizeAndAdd(listBox, copyBlock);
                            }
                            else if (isCondition && copyBlock.flag_isCondition)
                            {
                                ResizeAndAdd(listBox, copyBlock);
                            }
                        }

                        MainPage.communicate.editor = false; //let editor know that that socket was added and move finished
                    }
                    else //socket moved else where...need to have a check to see if it was added
                    {
                        if (listBox.Items.Count == 0)
                        {
                            listBox.Background.Opacity  = 1; //show empty socket
                            listBox.BorderBrush.Opacity = 1; //show empty socket
                        }
                    }
                }
            }
            base.OnItemDroppedOnTarget(args);
            MainPage.communicate.socket = false; //save that moveing socket is finished

            //returning the block to normal size, if neccessary
            Debigulate(listBox);
        }
Exemple #18
0
        /*
         * Event method that is called when an item is dropped into socket.
         * Checks to see if block can be added to socket and prefroms functions based on those checks.
         * Set the communication flag for socket to false (handled).
         */
        protected override void OnDropOverride(Microsoft.Windows.DragEventArgs args)
        {
            Debug.WriteLine("socket drop");
            if ((args.AllowedEffects & Microsoft.Windows.DragDropEffects.Link) == Microsoft.Windows.DragDropEffects.Link ||
                (args.AllowedEffects & Microsoft.Windows.DragDropEffects.Move) == Microsoft.Windows.DragDropEffects.Move)
            {
                //changed
                //gets the data format which is a ItemDragEventArgs
                object data = args.Data.GetData(args.Data.GetFormats()[0]);

                //changed
                //cast from generic object to ItemDragEventArgs and add to SelectionCollection
                ItemDragEventArgs   itemDragEventArgs   = data as ItemDragEventArgs;
                SelectionCollection selectionCollection = itemDragEventArgs.Data as SelectionCollection;
                //changed
                //get the target & source listbox from DragEventArgs
                ListBox dropTarget = GetDropTarget(args);

                //Copy from parent method
                if (dropTarget != null && selectionCollection.All(selection => CanAddItem(dropTarget, selection.Item)))
                {
                    if ((args.Effects & Microsoft.Windows.DragDropEffects.Move) == Microsoft.Windows.DragDropEffects.Move)
                    {
                        args.Effects = Microsoft.Windows.DragDropEffects.Move;
                    }
                    else
                    {
                        args.Effects = Microsoft.Windows.DragDropEffects.Link;
                    }

                    int?index = GetDropTargetInsertionIndex(dropTarget, args);

                    if (index != null)
                    {
                        if (args.Effects == Microsoft.Windows.DragDropEffects.Move && itemDragEventArgs != null && !itemDragEventArgs.DataRemovedFromDragSource)
                        {
                            itemDragEventArgs.RemoveDataFromDragSource();
                        }

                        //major change place at top of the listbox to act as a stack for undo
                        //needs to have its own method

                        foreach (Selection selection in selectionCollection)
                        {
                            if (selection.Item.GetType().Equals(typeof(Block)))
                            {
                                //creat copy block of the selection item
                                Block copyBlock = MainPage.createProgramStructureBlock(((Block)selection.Item).typeID);
                                if (copyBlock == null || (copyBlock != null && !copyBlock.type.Equals("STATEMENT"))) //check to make sure that you are not adding a STATEMENT to SOCKET
                                {
                                    Block selected = (Block)selection.Item;
                                    //check to make sure that you are not dragging into self
                                    dropTarget = preventOuroboros(itemDragEventArgs, dropTarget, selected, selected);

                                    if (copyBlock == null)
                                    {
                                        if (!((Block)selection.Item).Text.Equals("END"))
                                        {
                                            copyBlock = (selected).cloneSelf(true);
                                        }
                                        else
                                        {
                                            copyBlock = MainPage.createReservedBlock(selected.Text);
                                        }
                                    }

                                    //check to make sure that if there are more than 1 socket that they match
                                    if (SocketReader.socketCompatable(dropTarget, copyBlock))
                                    {
                                        //alter comboboxes if needed
                                        if (checkRestrictions(dropTarget, copyBlock))
                                        {
                                            if (copyBlock.ToString().Equals("DIRECTION"))
                                            {
                                                directionalCombos(dropTarget, copyBlock);
                                            }

                                            //flag to check if an element did move
                                            //used for cloneSockets check
                                            bool flag_DidAdd = false;

                                            //Add item to socket if allowed
                                            if (socketType.Contains(copyBlock.Text) || (copyBlock.returnType != null && socketType.Contains(copyBlock.returnType)))
                                            {
                                                ResizeAndAdd(dropTarget, copyBlock);
                                                flag_DidAdd = true;
                                            }
                                            else if (isConstant && copyBlock.flag_isConstant)
                                            {
                                                ResizeAndAdd(dropTarget, copyBlock);
                                                flag_DidAdd = true;
                                            }
                                            else if (isCondition && copyBlock.flag_isCondition)
                                            {
                                                ResizeAndAdd(dropTarget, copyBlock);
                                                flag_DidAdd = true;
                                            }

                                            //clone sockets if item was added
                                            if (copyBlock.flag_hasSocks && flag_DidAdd)
                                            {
                                                copyBlock = cloneSockets(selected, copyBlock);
                                            }
                                            if (!flag_DidAdd)
                                            {
                                                ErrorMessage(1);
                                            }
                                        }
                                    }
                                    else
                                    {
                                        ErrorMessage(2);
                                    }
                                }
                                else
                                {
                                    ErrorMessage(3);
                                }
                            }
                        }
                        //socket is no longer dragging
                        MainPage.communicate.socket = false; //try to fix half of the communication error
                    }
                }
                else
                {
                    args.Effects = Microsoft.Windows.DragDropEffects.None;
                }

                if (args.Effects != args.AllowedEffects)
                {
                    args.Handled = true;
                }
            }
        }
Exemple #19
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Selector"/> class.
        /// </summary>
        /// <param name="uv">The Ultraviolet context.</param>
        /// <param name="name">The identifying name of this element within a layout.</param>
        public Selector(UltravioletContext uv, String name)
            : base(uv, name)
        {
            this.selection = new SelectionCollection(this);

            this.selection.CollectionItemAdded += selection_CollectionItemAdded;
            this.selection.CollectionItemRemoved += selection_CollectionItemRemoved;
            this.selection.CollectionReset += selection_CollectionReset;
        }
        protected override void OnDropOverride(Microsoft.Windows.DragEventArgs args)
        {
            //Debug.WriteLine("Editor Drop");
            if ((args.AllowedEffects & Microsoft.Windows.DragDropEffects.Link) == Microsoft.Windows.DragDropEffects.Link ||
                (args.AllowedEffects & Microsoft.Windows.DragDropEffects.Move) == Microsoft.Windows.DragDropEffects.Move)
            {
                //changed
                //gets the data format which is a ItemDragEventArgs
                object data = args.Data.GetData(args.Data.GetFormats()[0]);

                //changed
                //cast from generic object to ItemDragEventArgs and add to SelectionCollection
                ItemDragEventArgs   itemDragEventArgs   = data as ItemDragEventArgs;
                SelectionCollection selectionCollection = itemDragEventArgs.Data as SelectionCollection;

                //changed
                //get the target & source listbox from DragEventArgs
                ListBox dropTarget = GetDropTarget(args);
                //ListBox src = (ListBox)itemDragEventArgs.DragSource;

                if (dropTarget != null && selectionCollection.All(selection => CanAddItem(dropTarget, selection.Item)))
                {
                    if ((args.Effects & Microsoft.Windows.DragDropEffects.Move) == Microsoft.Windows.DragDropEffects.Move)
                    {
                        args.Effects = Microsoft.Windows.DragDropEffects.Move;
                    }
                    else
                    {
                        args.Effects = Microsoft.Windows.DragDropEffects.Link;
                    }

                    int?index = GetDropTargetInsertionIndex(dropTarget, args);

                    if (index != null)
                    {
                        if (args.Effects == Microsoft.Windows.DragDropEffects.Move && itemDragEventArgs != null && !itemDragEventArgs.DataRemovedFromDragSource)
                        {
                            itemDragEventArgs.RemoveDataFromDragSource();
                        }

                        //major change place at top of the listbox to act as a stack for undo
                        //needs to have its own method
                        foreach (Selection selection in selectionCollection)
                        {
                            if (selection.Item.GetType().Equals(typeof(Block)))
                            {
                                //socket was added to the editor
                                if (MainPage.communicate.socket)
                                {
                                    MainPage.communicate.editor = true;  //let the socket know that it will need to be replaced
                                    MainPage.communicate.socket = false; //trying to fix the error

                                    //catching constant into constant in a first level block
                                    Block selected = selection.Item as Block;
                                    if (selected.flag_isConstant || selected.flag_isRobotConstant)
                                    {
                                        dropTarget = itemDragEventArgs.DragSource as ListBox;
                                        dropTarget.Items.Add(selected);
                                    }
                                }
                                else if (move) //moving in the editor window
                                {
                                    move = false;
                                    //Debug.WriteLine("move from " + fromIndex + " to " + index.Value);
                                    if (index.Value < dropTarget.Items.Count && (((Block)dropTarget.Items[index.Value]).Text.Equals("ELSE") || ((Block)dropTarget.Items[index.Value]).Text.Equals("ELSEIF")))
                                    {
                                        dropTarget.ItemsSource = tree.Move(fromIndex, fromIndex);
                                    }
                                    else
                                    {
                                        dropTarget.ItemsSource = tree.Move(fromIndex, index.Value);
                                    }
                                }
                                else
                                {
                                    Debug.WriteLine(((Block)selection.Item).typeID);
                                    Block copyBlock = MainPage.createProgramStructureBlock(((Block)selection.Item).typeID);

                                    if (copyBlock == null)
                                    {
                                        if (!((Block)selection.Item).Text.Equals("END"))
                                        {
                                            copyBlock = ((Block)selection.Item).cloneSelf(true);
                                        }
                                        //else if (((Block)selection.Item).Text.Equals("METHOD"))
                                        //    copyBlock = ((Block)selection.Item).cloneSelf();
                                        else
                                        {
                                            copyBlock = MainPage.createReservedBlock(((Block)selection.Item).Text);
                                        }
                                    }
                                    if (copyBlock.checkType("STATEMENT"))
                                    {
                                        if (copyBlock.flag_requiresEndIf)
                                        {
                                            //check if it is an else or else if and make sure that count and index are not 0 or null to preform operatoins

                                            if (copyBlock.flag_followsIfOnly && dropTarget.Items.Count > 0 && index.Value > 0)
                                            {
                                                //check previous index for end if block
                                                //add if it exist
                                                if (((Block)dropTarget.Items[index.Value - 1]).Text.Equals("ENDIF"))
                                                {
                                                    if (copyBlock.Text.Equals("ELSE"))
                                                    {
                                                        //check to see if there is already an else
                                                        if (index.Value < dropTarget.Items.Count && (((Block)dropTarget.Items[index.Value]).Text.Equals("ELSE") || ((Block)dropTarget.Items[index.Value]).Text.Equals("ELSEIF")))
                                                        {
                                                        }
                                                        else
                                                        {
                                                            Block endBlock = MainPage.createReservedBlock("ENDELSE");//.cloneSelf();
                                                            dropTarget.ItemsSource = tree.AddWithChild(copyBlock, endBlock, index.Value);
                                                        }
                                                    }
                                                    else
                                                    {
                                                        Block endBlock = MainPage.createReservedBlock("ENDIF");//.cloneSelf();
                                                        dropTarget.ItemsSource = tree.AddWithChild(copyBlock, endBlock, index.Value);
                                                    }
                                                }
                                            }
                                            else if (!copyBlock.flag_followsIfOnly)
                                            {
                                                //doesn't allow if to be placed inbetween an if and else-if or else
                                                if (index.Value < dropTarget.Items.Count && (((Block)dropTarget.Items[index.Value]).Text.Equals("ELSEIF") || ((Block)dropTarget.Items[index.Value]).Text.Equals("ELSE")))
                                                {
                                                }
                                                else
                                                {
                                                    Block endBlock = MainPage.createReservedBlock("ENDIF");//.cloneSelf();
                                                    dropTarget.ItemsSource = tree.AddWithChild(copyBlock, endBlock, index.Value);
                                                }
                                            }
                                        }
                                        else if (index.Value < dropTarget.Items.Count && (((Block)dropTarget.Items[index.Value]).Text.Equals("ELSE") || ((Block)dropTarget.Items[index.Value]).Text.Equals("ELSEIF")))
                                        {
                                        }
                                        else if (copyBlock.flag_requiresEndLoop)
                                        {
                                            Block endBlock = MainPage.createReservedBlock("ENDLOOP");//.cloneSelf();
                                            dropTarget.ItemsSource = tree.AddWithChild(copyBlock, endBlock, index.Value);
                                        }
                                        else
                                        {
                                            dropTarget.ItemsSource = tree.Add(copyBlock, index.Value);
                                        }
                                    }
                                }
                            }
                        }
                        Refresh(dropTarget);
                    }
                }
                else
                {
                    args.Effects = Microsoft.Windows.DragDropEffects.None;
                }

                if (args.Effects != args.AllowedEffects)
                {
                    args.Handled = true;
                }
            }
        }
Exemple #21
0
        protected override void OnDropOverride(Microsoft.Windows.DragEventArgs args)
        {
            //Debug.WriteLine("AllowAdd: " + AllowAdd);
            //Debug.WriteLine("trash");
            MainPage.communicate.trash = true;
            if (AllowAdd)
            {
                if ((args.AllowedEffects & Microsoft.Windows.DragDropEffects.Link) == Microsoft.Windows.DragDropEffects.Link ||
                    (args.AllowedEffects & Microsoft.Windows.DragDropEffects.Move) == Microsoft.Windows.DragDropEffects.Move)
                {
                    //changed
                    //gets the data format which is a ItemDragEventArgs
                    object data = args.Data.GetData(args.Data.GetFormats()[0]);

                    //changed
                    //cast from generic object to ItemDragEventArgs and add to SelectionCollection
                    ItemDragEventArgs   itemDragEventArgs   = data as ItemDragEventArgs;
                    SelectionCollection selectionCollection = itemDragEventArgs.Data as SelectionCollection;

                    //changed
                    //get the target listbox from DragEventArgs
                    ListBox dropTarget = GetDropTarget(args);

                    if (dropTarget != null && selectionCollection.All(selection => CanAddItem(dropTarget, selection.Item)))
                    {
                        if ((args.Effects & Microsoft.Windows.DragDropEffects.Move) == Microsoft.Windows.DragDropEffects.Move)
                        {
                            args.Effects = Microsoft.Windows.DragDropEffects.Move;
                        }
                        else
                        {
                            args.Effects = Microsoft.Windows.DragDropEffects.Link;
                        }

                        int?index = GetDropTargetInsertionIndex(dropTarget, args);
                        //Debug.WriteLine("?index: " + index.Value);
                        if (index != null)
                        {
                            if (args.Effects == Microsoft.Windows.DragDropEffects.Move && itemDragEventArgs != null && !itemDragEventArgs.DataRemovedFromDragSource)
                            {
                                itemDragEventArgs.RemoveDataFromDragSource();
                            }

                            //major change place at top of the listbox to act as a stack for undo
                            foreach (Selection selection in selectionCollection)
                            {
                                InsertItem(dropTarget, 0, selection.Item);
                            }
                        }
                    }
                    else
                    {
                        args.Effects = Microsoft.Windows.DragDropEffects.None;
                    }

                    if (args.Effects != args.AllowedEffects)
                    {
                        args.Handled = true;
                    }
                }
                AllowAdd = false;
            }
        }
Exemple #22
0
 public SheetMerger()
 {
     Settings = new MergeSettings();
     Sheets   = new SelectionCollection <Sheet>();
 }
        private void CommitSelection()
        {
            if (SelectionHandlingCount != 0)
            {
                throw new InvalidOperationException();
            }

            try
            {
                SelectionHandlingCount = -1;

                CoerceSelectionResume();

                if (Selection.Equals(SelectionResume) && SelectionCollection.Version == SelectionCollectionResume.Version)
                {
                    return;
                }

                var selection    = SelectionResume;
                var oldSelection = Selection;

                var oldSelectedItem   = oldSelection.Item;
                var oldSelectedIndex  = oldSelection.Index;
                var oldSelectedValue  = oldSelection.Value;
                var oldSelectedSource = oldSelection.Source;

                var newSelectedItem   = selection.Item;
                var newSelectedIndex  = selection.Index;
                var newSelectedValue  = selection.Value;
                var newSelectedSource = selection.Source;

                Selection = selection;

                if (SupportsItem)
                {
                    if (ReferenceEquals(ReadSelectedItem(), newSelectedItem) == false)
                    {
                        WriteSelectedItem(newSelectedItem);

                        newSelectedItem = ReadSelectedItem();
                    }
                }

                if (SupportsSource)
                {
                    if (ReferenceEquals(ReadSelectedSource(), newSelectedSource) == false)
                    {
                        WriteSelectedSource(newSelectedSource);

                        newSelectedSource = ReadSelectedSource();
                    }
                }

                if (SupportsIndex)
                {
                    if (ReadSelectedIndex() != newSelectedIndex)
                    {
                        WriteSelectedIndex(newSelectedIndex);

                        newSelectedIndex = ReadSelectedIndex();
                    }
                }

                if (SupportsValue)
                {
                    if (CompareValues(ReadSelectedValue(), newSelectedValue) == false)
                    {
                        WriteSelectedValue(newSelectedValue);

                        newSelectedValue = ReadSelectedValue();
                    }
                }

                var newSelection = new Selection <TItem>(newSelectedIndex, newSelectedItem, newSelectedSource, newSelectedValue);

                if (newSelection.Equals(Selection) == false)
                {
                    throw new InvalidOperationException();
                }

                if (MultipleSelection)
                {
                    foreach (var oldSelectionCollection in SelectionCollection)
                    {
                        if (SelectionCollectionResume.ContainsItem(oldSelectionCollection.Item) == false)
                        {
                            SetItemSelected(oldSelectionCollection.Item, false);
                        }
                    }

                    foreach (var newSelectionCollection in SelectionCollectionResume)
                    {
                        if (SelectionCollection.ContainsItem(newSelectionCollection.Item) == false)
                        {
                            SetItemSelected(newSelectionCollection.Item, true);
                        }
                    }

                    SelectionCollection.CopyFrom(SelectionCollectionResume);
                    SelectionCollectionResume.Clear();
                }
                else if (ReferenceEquals(oldSelectedItem, newSelectedItem) == false)
                {
                    SetItemSelected(oldSelectedItem, false);
                    SetItemSelected(newSelectedItem, true);
                }

                var raiseSelectionChanged = false;

                if (ReferenceEquals(newSelectedItem, oldSelectedItem) == false)
                {
                    RaiseOnSelectedItemChanged(oldSelectedItem, newSelectedItem);

                    raiseSelectionChanged = true;
                }

                if (ReferenceEquals(newSelectedSource, oldSelectedSource) == false)
                {
                    RaiseOnSelectedSourceChanged(oldSelectedSource, newSelectedSource);

                    raiseSelectionChanged = true;
                }

                if (newSelectedIndex != oldSelectedIndex)
                {
                    RaiseOnSelectedIndexChanged(oldSelectedIndex, newSelectedIndex);

                    raiseSelectionChanged = true;
                }

                if (CompareValues(oldSelectedValue, newSelectedValue) == false)
                {
                    RaiseOnSelectedValueChanged(oldSelectedValue, newSelectedValue);

                    raiseSelectionChanged = true;
                }

                if (raiseSelectionChanged)
                {
                    RaiseOnSelectionChanged(oldSelection, newSelection);
                }

                LockedItem = SelectedItem;

                SelectionCollectionChanged?.Invoke(SelectionCollection, ResetNotifyCollectionChangedEventArgs);
                SelectionCollectionPropertyChanged?.Invoke(SelectionCollection, CountPropertyChangedEventArgs);
            }
            finally
            {
                SelectionHandlingCount = 0;
            }
        }
Exemple #24
0
 public SheetSet(string pathToFile)
     : base(pathToFile)
 {
     Sheets = new SelectionCollection <Sheet>();
 }
Exemple #25
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Scintilla" /> class.
        /// </summary>
        public Scintilla()
        {
            // WM_DESTROY workaround
            if (Scintilla.reparentGlobal.HasValue)
                reparent = (bool)Scintilla.reparentGlobal;

            // We don't want .NET to use GetWindowText because we manage ('cache') our own text
            base.SetStyle(ControlStyles.CacheText, true);

            // Necessary control styles (see TextBoxBase)
            base.SetStyle(ControlStyles.StandardClick |
                     ControlStyles.StandardDoubleClick |
                     ControlStyles.UseTextForAccessibility |
                     ControlStyles.UserPaint,
                     false);

            this.borderStyle = BorderStyle.Fixed3D;

            Lines = new LineCollection(this);
            Styles = new StyleCollection(this);
            Indicators = new IndicatorCollection(this);
            Margins = new MarginCollection(this);
            Markers = new MarkerCollection(this);
            Selections = new SelectionCollection(this);
        }
        public void Execute(object parameter)
        {
            //Version using Drop event:
            var param = parameter as System.Windows.DragEventArgs;

            if (param != null)
            {
                var castedParameter = param.Data.GetData("ItemDragEventArgs") as ItemDragEventArgs;

                int newItemOrder = -1;

                //We get the item on which the element was dropped:
                var elements = VisualTreeHelper.FindElementsInHostCoordinates(param.GetPosition(null).Position, _column.ColumnDefinition._kanBanControl);
                FrameworkElement elementDroppedOn = elements.ElementAt(0) as FrameworkElement;
                while (elementDroppedOn != null &&                                                                                //we go up the visual tree until we reached the root or...
                       (elementDroppedOn.DataContext == null || elementDroppedOn.DataContext.GetType() != typeof(ItemViewModel))) //...until we found an element that has the ItemViewModel as DataContext
                {
                    elementDroppedOn = elementDroppedOn.Parent as FrameworkElement;
                }
                if (elementDroppedOn != null)
                {
                    //todo: find a way to know in which half of the DropElement the dragged element was dropped.
                    //      We could do with comparing the position at which it was dropped with the position of the root of the item card
                    //          (but it need us to find said root - could be done by going up the visual tree until we find an element whose DataContext is not an ItemViewModel
                    //          -> the last one with the ItemViewModel should be the root element)
                    //      We could try to know it the cursor was on the Header or the body of the card.


                    //for now, we will consider the element dropped above:
                    newItemOrder = ((ItemViewModel)elementDroppedOn.DataContext).ItemOrder + 1; //Reminder: we have chosen to have the items with the bigger order number higher on the displayed list.
                }

                //Version using ItemDragCompleted event (this one doesn't seem good because the sender is the column from which the item comes):
                //var castedParameter = parameter as ItemDragEventArgs;
                //if(castedParameter != null)
                //{
                SelectionCollection selectionCollection = castedParameter.Data as SelectionCollection;
                if (selectionCollection.Count > 0)
                {
                    Selection        selection     = selectionCollection.ElementAt(0); //we can only drag one item so it is at the position 0.
                    FrameworkElement container     = selection.Item as FrameworkElement;
                    ItemViewModel    itemViewModel = container.DataContext as ItemViewModel;
                    if (itemViewModel != null)
                    {
                        itemViewModel.ItemOrder = newItemOrder;
                        UpdateItemOrders(newItemOrder);

                        itemViewModel.ItemColumnId = _column.ColumnDefinition.Id;

                        //force a refresh of the KanBanControl:
                        //todo: find a way to only refresh the Column itself.
                        var kanBanControl = _column.ColumnDefinition._kanBanControl;
                        var columns       = kanBanControl.Columns;
                        kanBanControl.Columns = null;
                        kanBanControl.Columns = columns;

                        // Raise the "ItemMoved" event:
                        kanBanControl.OnItemMoved(itemViewModel);

                        //keep the following to only refresh the column itself. It cannot be used properly currently as it causes a bug where the items are duplicated.
                        ////refresh the elements of the column:
                        //_column.Dispatcher.BeginInvoke( () =>
                        //{
                        //    _column.UnalteredItemsCollection.Add(itemViewModel); //we add the item manually because the whole collection was not refreshed in the process. This should change with Smooth refresh.
                        //    _column.SetOrderedItemsCollection();
                        //    });
                        //_column.SetOrderedItemsCollection();
                    }
                }
            }
        }