Пример #1
0
        //When the user enters a drop target with a dragged image, the image is dropped in the appropriate location
        private void OnDropTargetDragEnter(object sender, SurfaceDragDropEventArgs e)
        {
            PhotoData data = e.Cursor.Data as PhotoData;

            if (!data.CanDrop)
            {
                e.Effects = DragDropEffects.Move;
            }
        }
Пример #2
0
        // When the user initializes drag and drop functions, the cursor changes to reflect selected image
        private void Scatter_PreviewTouchDown(object sender, TouchEventArgs e)
        {
            FrameworkElement findSource     = e.OriginalSource as FrameworkElement;
            ScatterViewItem  draggedElement = null;

            //find the ScatterViewItem object that is being touched
            while (draggedElement == null && findSource != null)
            {
                if ((draggedElement = findSource as ScatterViewItem) == null)
                {
                    findSource = VisualTreeHelper.GetParent(findSource) as FrameworkElement;
                }
            }
            if (draggedElement == null)
            {
                return;
            }
            PhotoData      data         = draggedElement.Content as PhotoData;
            ContentControl cursorVisual = new ContentControl()
            {
                Content = draggedElement.DataContext,
                Style   = FindResource("CursorStyle") as Style
            };

            //create the list of input devices and the feducial markers
            //add the touches that are currently captured within the dragged elt and
            //the current touch (if it isn't already in the list)
            List <InputDevice> devices = new List <InputDevice>();

            devices.Add(e.TouchDevice);
            foreach (TouchDevice touch in draggedElement.TouchesCapturedWithin)
            {
                if (touch != e.TouchDevice)
                {
                    devices.Add(touch);
                }
            }
            //get the drag source object
            ItemsControl dragSource = ItemsControl.ItemsControlFromItemContainer(draggedElement);

            //the scatterview object that the cursor is dragged out from
            SurfaceDragDrop.BeginDragDrop(
                dragSource,                 //the scatterview object that the cursor is dragged out from
                draggedElement,             //the ScatterViewItem object that is dragged from the drag source
                cursorVisual,               //the visual element of the cursor
                draggedElement.DataContext, //the data attached with the cursor
                devices,                    //the input devices that start dragging the cursor
                DragDropEffects.None);      //the allowed drag-and-drop

            //this prevents the default touch operator from happening
            e.Handled = true;

            //hide the scatterviewitem for now. we will remove it if the dragdrop is successful
            draggedElement.Visibility = Visibility.Hidden;
        }
Пример #3
0
 // When the user drops a dragged item into the drop target, the cursor image changes from that image to default cursor
 private void OnTargetChanged(object sender, TargetChangedEventArgs e)
 {
     if (e.Cursor.CurrentTarget != null)
     {
         PhotoData data = e.Cursor.Data as PhotoData;
         e.Cursor.Visual.Tag = (data.CanDrop) ? "CanDrop" : "CannotDrop";
     }
     else
     {
         e.Cursor.Visual.Tag = null;
     }
 }