Exemplo n.º 1
0
    private void OnApplicationTreeDragOver(object sender, Telerik.Windows.DragDrop.DragEventArgs e)
    {
        var options = DragDropPayloadManager.GetDataFromObject(e.Data, TreeViewDragDropOptions.Key) as TreeViewDragDropOptions;

        if (options == null)
        {
            return;
        }

        // The condition after the first OR operator is needed to deny the drop of items in Application File. (sub-items)
        RadTreeViewItem dropTargetItem = options.DropTargetItem;

        var draggedItem = options.DraggedItems.First();

        if (dropTargetItem == null ||
            (dropTargetItem != null &&
             options.DropTargetItem.DataContext is Resource &&
             options.DropPosition == DropPosition.Inside) ||
            draggedItem is PartitionViewModel)
        {
            options.DropAction = DropAction.None;
        }

        options.UpdateDragVisual();
    }
Exemplo n.º 2
0
        private void OnRowDragOver(object sender, Telerik.Windows.DragDrop.DragEventArgs e)
        {
            var row     = sender as GridViewRow;
            var details = DragDropPayloadManager.GetDataFromObject(e.Data, "DropDetails") as DropIndicationDetails;

            if (details == null || row == null)
            {
                return;
            }

            details.CurrentDraggedOverItem = row.DataContext;

            if (details.CurrentDraggedItem == details.CurrentDraggedOverItem)
            {
                e.Effects = DragDropEffects.None;
                e.Handled = true;
                return;
            }

            details.CurrentDropPosition = GetDropPositionFromPoint(e.GetPosition(row), row);
            int dropIndex       = (this.AssociatedObject.Items as IList).IndexOf(row.DataContext);
            int draggedItemIdex = (this.AssociatedObject.Items as IList).IndexOf(DragDropPayloadManager.GetDataFromObject(e.Data, "DraggedItem"));

            if (dropIndex >= row.GridViewDataControl.Items.Count - 1 && details.CurrentDropPosition == DropPosition.After)
            {
                details.DropIndex = dropIndex;
                this.ShowDropPositionFeedbackPresenter(this.AssociatedObject, row, details.CurrentDropPosition);
                return;
            }

            dropIndex         = draggedItemIdex > dropIndex ? dropIndex : dropIndex - 1;
            details.DropIndex = details.CurrentDropPosition == DropPosition.Before ? dropIndex : dropIndex + 1;

            this.ShowDropPositionFeedbackPresenter(this.AssociatedObject, row, details.CurrentDropPosition);
        }
Exemplo n.º 3
0
        private void OnDrop(object sender, Telerik.Windows.DragDrop.DragEventArgs e)
        {
            var draggedItem = DragDropPayloadManager.GetDataFromObject(e.Data, "DraggedItem");
            var details     = DragDropPayloadManager.GetDataFromObject(e.Data, "DropDetails") as DropIndicationDetails;

            if (details == null || draggedItem == null)
            {
                return;
            }

            if (e.Effects == DragDropEffects.Move || e.Effects == DragDropEffects.All)
            {
                ((sender as RadGridView).ItemsSource as IList).Remove(draggedItem);
            }

            if (e.Effects != DragDropEffects.None)
            {
                var collection = (sender as RadGridView).ItemsSource as IList;
                int index      = details.DropIndex < 0 ? 0 : details.DropIndex;
                index = details.DropIndex > collection.Count - 1 ? collection.Count : index;

                collection.Insert(index, draggedItem);
            }

            HideDropPositionFeedbackPresenter();
        }
Exemplo n.º 4
0
    // Forbids the local machine tree view to drop anything
    private void OnLocalMachineTreeDragOver(object sender, Telerik.Windows.DragDrop.DragEventArgs e)
    {
        var options = DragDropPayloadManager.GetDataFromObject(e.Data, TreeViewDragDropOptions.Key) as TreeViewDragDropOptions;

        if (options != null)
        {
            options.DropAction = DropAction.None;
            options.UpdateDragVisual();

            e.Handled = true;
        }
    }
Exemplo n.º 5
0
    private void OnApplicationTreeDrop(object sender, Telerik.Windows.DragDrop.DragEventArgs e)
    {
        var options = DragDropPayloadManager.GetDataFromObject(e.Data, TreeViewDragDropOptions.Key) as TreeViewDragDropOptions;

        if (options == null)
        {
            return;
        }

        MediaFile draggedItem = options.DraggedItems.FirstOrDefault() as MediaFile;

        if (draggedItem == null)
        {
            return;
        }

        RadTreeViewItem dropTargetItem = options.DropTargetItem;

        if (dropTargetItem == null)
        {
            return;
        }

        var dropItemModel = dropTargetItem.DataContext;

        if (dropItemModel == null)
        {
            return;
        }

        var dropTree = sender as RadTreeView;

        if (dropTree != null)
        {
            // Disable drop in Application File.
            if (dropItemModel is Resource && options.DropAction == DropAction.None)
            {
                e.Handled = true;
                return;
            }

            // Drop in Application.
            if (dropItemModel is ApplicationViewModel || dropItemModel is Resource)
            {
                options.DropAction = DropAction.Copy;
                options.UpdateDragVisual();

                ApplicationViewModel destinationFolder = null;
                if (dropItemModel is ApplicationViewModel)
                {
                    // Dropping inside Application.
                    destinationFolder = dropItemModel as ApplicationViewModel;
                }
                else
                {
                    // Dropping Before or After an Application Resource.
                    destinationFolder = options.DropTargetItem.ParentItem.DataContext as ApplicationViewModel;
                }

                if (destinationFolder == null)
                {
                    return;
                }

                Resource file = new Resource()
                {
                    ImageFilePath = new System.Windows.Media.Imaging.BitmapImage(new Uri(draggedItem.ImageFilePath, UriKind.RelativeOrAbsolute)),
                    Title         = draggedItem.ImageTitle
                };

                destinationFolder.Resources.Add(file);
            }
        }
    }