Beispiel #1
0
        /// <summary>
        /// Handles the DragSource_MouseLeftButtonUp of the drag source. Completes the dragging operation and perform the drop if applies.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The envet args instance containing event data.</param>
        private void DragSource_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            this.dragSource.ReleaseMouseCapture();

            if (this.IsDragging)
            {
                IList <FrameworkElement> dropZones = this.CheckDropZones(e);

                foreach (FrameworkElement dropZone in dropZones)
                {
                    ICommand command = DragDropManager.GetDropCommand(dropZone);

                    if (command != null)
                    {
                        DropPayload dropPayload = new DropPayload
                        {
                            DraggedItem      = DragDropManager.GetDragData(this.dragSource),
                            RelativePosition = e.GetPosition(dropZone),
                            MouseEventArgs   = e,
                            DropData         = DragDropManager.GetDropData(dropZone),
                        };
                        command.Execute(dropPayload);
                    }
                }
            }

            this.DragPopupChild.Children.Clear();
            this.DragPopup.IsOpen = false;
            this.IsDragging       = false;
        }
        private void HandleDrop(DropPayload dropPayload)
        {
            Asset draggedAsset = dropPayload.DraggedItem as Asset;

            if (draggedAsset != null)
            {
                this.Asset = draggedAsset;
            }
        }
Beispiel #3
0
        /// <summary>
        /// Drops an asset to a folder.
        /// </summary>
        /// <param name="dropPayload">The drop payload that contains the drop information.</param>
        private void DropAssetOnFolder(DropPayload dropPayload)
        {
            FolderAsset folderAsset = dropPayload.DropData as FolderAsset;
            Asset       asset       = dropPayload.DraggedItem as Asset;

            if (folderAsset != null)
            {
                this.AddAssetToFolder(asset, folderAsset.Id);
                this.RefreshCurrentAssets();
            }
        }
        /// <summary>
        /// Handles the MouseMove of the drag source. Shows a visual notification if the asset can be dropped or not..
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The envet args instance containing event data.</param>
        private void DragSource_MouseMove(object sender, MouseEventArgs e)
        {
            if (this.IsDragging)
            {
                if (this.DragPopup != null && this.DragPopupChild != null && this.DragPopupChild.Children.Count > 0 &&
                    this.DragPopupChild.ActualHeight > 0 && this.DragPopupChild.ActualWidth > 0)
                {
                    this.DragPopupChild.Opacity = 1;
                    Point point = e.GetPosition(Application.Current.RootVisual);

                    const double HeightOffset              = 15;
                    double       currentVerticalPosition   = point.Y - this.DragPopupChild.ActualHeight + HeightOffset;
                    double       currentHorizontalPosition = point.X - (this.DragPopupChild.ActualWidth / 2);
                    this.DragPopup.VerticalOffset   = currentVerticalPosition;
                    this.DragPopup.HorizontalOffset = currentHorizontalPosition;

                    FrameworkElement dropZone = this.GetDropZone(e);

                    if (dropZone != null)
                    {
                        bool result = true;

                        if (dropZone != null)
                        {
                            ICommand command = DragDropManager.GetDropCommand(dropZone);

                            if (command != null)
                            {
                                DropPayload dropPayload = new DropPayload
                                {
                                    DraggedItem      = DragDropManager.GetDragData(this.dragSource),
                                    RelativePosition = e.GetPosition(dropZone),
                                    MouseEventArgs   = e,
                                    DropData         = DragDropManager.GetDropData(dropZone),
                                    CustomData       = DragDropManager.GetCustomData(this.dragSource)
                                };

                                result = command.CanExecute(dropPayload);
                            }

                            this.ShowDragDrop(result);
                        }
                    }
                    else
                    {
                        this.ShowDragDrop(false);
                    }
                }
            }
        }
        public void ShouldUpdateHasAssetWhenExecutingDropCommand()
        {
            var viewModel = this.CreateViewModel();

            DropPayload dropPayload = new DropPayload();
            VideoAsset  asset       = new VideoAsset();

            dropPayload.DraggedItem = asset;

            Assert.IsFalse(viewModel.HasAsset);

            viewModel.DropCommand.Execute(dropPayload);

            Assert.IsTrue(viewModel.HasAsset);
        }
        public void ShouldUpdateCurrentAssetWhenExecutingDropCommand()
        {
            var viewModel = this.CreateViewModel();

            DropPayload dropPayload = new DropPayload();
            VideoAsset  asset       = new VideoAsset();

            dropPayload.DraggedItem = asset;

            Assert.IsNull(viewModel.Asset);

            viewModel.DropCommand.Execute(dropPayload);

            Assert.IsNotNull(viewModel.Asset);
            Assert.AreSame(asset, viewModel.Asset);
        }
        /// <summary>
        /// Drops an asset to a folder.
        /// </summary>
        /// <param name="dropPayload">The drop payload that contains the drop information.</param>
        private void DropAssetOnFolder(DropPayload dropPayload)
        {
            FolderAsset folderAsset = dropPayload.DropData as FolderAsset;
            Asset       asset       = dropPayload.DraggedItem as Asset;

            if (folderAsset != null)
            {
                this.AddAssetToFolder(asset, folderAsset.Id);
                this.RefreshCurrentAssets();
            }
            else if (this.currentFolderAsset != null)
            {
                this.AddAssetToFolder(asset, this.currentFolderAsset.Id);
                this.RefreshCurrentAssets();
            }
            else
            {
                if (asset != null && !this.Assets.Contains(asset))
                {
                    this.AddAsset(asset);
                }
            }
        }
 private bool CanHandleDrop(DropPayload dropPayload)
 {
     return(this.IsDisplayed && (dropPayload.DraggedItem != this.VideoAssetInOut));
 }