예제 #1
0
 public static void ClearAllSurfaceDragCursor(this SurfaceWindow _window)
 {
     foreach (SurfaceDragCursor cursor in SurfaceDragDrop.GetAllCursors(_window))
     {
         SurfaceDragDrop.CancelDragDrop(cursor);
     }
 }
예제 #2
0
        private void OnMainDrag(object sender, InputEventArgs e)
        {
            FrameworkElement   findSource     = e.OriginalSource as FrameworkElement;
            SurfaceListBoxItem draggedElement = null;

            // Find the touched SurfaceListBoxItem object.
            while (draggedElement == null && findSource != null)
            {
                if ((draggedElement = findSource as SurfaceListBoxItem) == null)
                {
                    findSource = VisualTreeHelper.GetParent(findSource) as FrameworkElement;
                }
            }

            if (draggedElement == null)
            {
                return;
            }

            // Create the cursor visual.
            ContentControl cursorVisual = new ContentControl()
            {
                Content = draggedElement.DataContext,
                Style   = FindResource("CursorStyle") as Style
            };

            // Add a handler. This will enable the application to change the visual cues.
            SurfaceDragDrop.AddTargetChangedHandler(cursorVisual, OnTargetChanged);

            // Create a list of input devices. Add the touches that
            // are currently captured within the dragged element and
            // the current touch (if it isn't already in the list).
            List <InputDevice> devices = new List <InputDevice>();

            devices.Add(e.Device);
            foreach (TouchDevice touch in draggedElement.TouchesCapturedWithin)
            {
                if (touch != e.Device)
                {
                    devices.Add(touch);
                }
            }

            // Get the drag source object
            ItemsControl dragSource = ItemsControl.ItemsControlFromItemContainer(draggedElement);

            SurfaceDragCursor startDragOkay =
                SurfaceDragDrop.BeginDragDrop(
                    dragSource,                 // The SurfaceListBox object that the cursor is dragged out from.
                    draggedElement,             // The SurfaceListBoxItem object that is dragged from the drag source.
                    cursorVisual,               // The visual element of the cursor.
                    draggedElement.DataContext, // The data associated with the cursor.
                    devices,                    // The input devices that start dragging the cursor.
                    DragDropEffects.Move);      // The allowed drag-and-drop effects of the operation.

            // If the drag began successfully, set e.Handled to true.
            // Otherwise SurfaceListBoxItem captures the touch
            // and causes the drag operation to fail.
            e.Handled = (startDragOkay != null);
        }
        /// Will be used when the user touches an element on the scatterview
        /// will gather the required data for the drag and drop operation and start it
        /// Once user has dropped item, either a DragCanceled or DragCompleted event will be fired,
        /// depending on where the item is dropped 
        /// If they drop the item on the ScatterView or LibraryContainer the DragCompleted Event will fire
        /// If they drop it to the left of the right of the LibraryContainer the DragCanceled event will fire 
        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;

            //create the cursor visual
            ContentControl cursorVisual = new ContentControl()
            {
                Content= draggedElement.DataContext,
                Style = FindResource("CursorStyle") as Style
            };

            //create the list of input devices 
            //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,
                draggedElement,
                cursorVisual,
                draggedElement.DataContext,
                devices,
                DragDropEffects.Move);

            //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;
        }
예제 #4
0
        private void StartDragDrop(ListBox sourceListBox, InputEventArgs e)
        {
            DependencyObject downSource = InputDeviceHelper.GetDragSource(e.Device);

            Debug.Assert(downSource != null);

            SurfaceListBoxItem draggedListBoxItem = GetVisualAncestor <SurfaceListBoxItem>(downSource);

            if (draggedListBoxItem == null)
            {
                return;
            }

            SimpleCard data = draggedListBoxItem.Content as SimpleCard;

            // Create a new ScatterViewItem as cursor visual.
            ScatterViewItem cursorVisual = new ScatterViewItem();

            cursorVisual.Style   = (Style)FindResource("ScatterItemStyle");
            cursorVisual.Content = data;

            IEnumerable <InputDevice> devices = null;

            TouchEventArgs touchEventArgs = e as TouchEventArgs;

            if (touchEventArgs != null)
            {
                devices = MergeInputDevices(draggedListBoxItem.TouchesCapturedWithin, e.Device);
            }
            else
            {
                devices = new List <InputDevice>(new InputDevice[] { e.Device });
            }

            SurfaceDragCursor cursor = SurfaceDragDrop.BeginDragDrop(HandListBox, draggedListBoxItem, cursorVisual, data, devices, DragDropEffects.All);

            // Reset the input device's state.

            InputDeviceHelper.ClearDeviceState(e.Device);

            ((ObservableCollection <SimpleCard>) this.HandListBox.ItemsSource).Remove(data);
        }
예제 #5
0
 private void OnExileButtonLoaded(object sender, RoutedEventArgs e)
 {
     SurfaceDragDrop.AddDropHandler(ExileButton, OnExileButtonCursorDrop);
 }
예제 #6
0
 private void OnLoaded(object sender, RoutedEventArgs e)
 {
     SurfaceDragDrop.AddDropHandler(this, OnCursorDrop);
 }
        private void DragSourcePreviewInputDeviceDown(object sender, InputEventArgs 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;
            }

            DragableImageItem data = draggedElement.Content as DragableImageItem;

            // If the data has not been specified as draggable,
            // or the ScatterViewItem cannot move, return.
            if (data == null || !data.CanDrag || !draggedElement.CanMove)
            {
                return;
            }

            // Set the dragged element. This is needed in case the drag operation is canceled.
            data.DraggedElement = draggedElement;

            // Create the cursor visual.
            ContentControl cursorVisual = new ContentControl()
            {
                Content = draggedElement.DataContext,
                Style   = FindResource("CursorStyle") as Style
            };

            // Create a list of input devices,
            // and add the device passed to this event handler.
            List <InputDevice> devices = new List <InputDevice>();

            devices.Add(e.Device);

            // If there are touch devices captured within the element,
            // add them to the list of input devices.
            foreach (InputDevice device in draggedElement.TouchesCapturedWithin)
            {
                if (device != e.Device)
                {
                    devices.Add(device);
                }
            }

            // Get the drag source object.
            ItemsControl dragSource = ItemsControl.ItemsControlFromItemContainer(draggedElement);

            // Start the drag-and-drop operation.
            SurfaceDragCursor cursor =
                SurfaceDragDrop.BeginDragDrop(
                    // The ScatterView object that the cursor is dragged out from.
                    dragSource,
                    // The ScatterViewItem object that is dragged from the drag source.
                    draggedElement,
                    // The visual element of the cursor.
                    cursorVisual,
                    // The data attached with the cursor.
                    draggedElement.DataContext,
                    // The input devices that start dragging the cursor.
                    devices,
                    // The allowed drag-and-drop effects of the operation.
                    DragDropEffects.Move);

            // If the cursor was created, the drag-and-drop operation was successfully started.
            if (cursor != null)
            {
                // Hide the ScatterViewItem.
                draggedElement.Visibility = Visibility.Hidden;

                // This event has been handled.
                e.Handled = true;
            }
        }
예제 #8
0
        /*
         * Function called if the mouse button is down
         */
        private void OnDragSourcePreviewMouseDown(object sender, MouseButtonEventArgs 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;
                }
            }
            // In case no element has been clicked
            if (draggedElement == null)
            {
                return;
            }


            SimpleCard data = draggedElement.Content as SimpleCard;

            // If the data has not been specified as draggable,
            // or the ScatterViewItem cannot move, return.
            if (data == null)
            {
                return;
            }

            // Create the cursor visual.
            ScatterViewItem cursorVisual = new ScatterViewItem()
            {
                Content = draggedElement.DataContext,
                Style   = FindResource("ScatterItemStyle") as Style
            };

            // Create a list of input devices. Add the touches that
            // are currently captured within the dragged element and
            // the current touch (if it isn't already in the list).
            List <InputDevice> devices = new List <InputDevice>();

            devices.Add(e.Device);
            foreach (TouchDevice touch in draggedElement.TouchesCapturedWithin)
            {
                if (touch != e.Device)
                {
                    devices.Add(touch);
                }
            }

            // Get the drag source object
            ItemsControl dragSource = ItemsControl.ItemsControlFromItemContainer(draggedElement);

            SurfaceDragCursor startDragOkay =
                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.Move);      // The allowed drag-and-drop effects of the operation.

            if (startDragOkay != null)
            {
                // Set e.Handled to true, otherwise the ScatterViewItem will capture the touch
                // and cause the BeginDragDrop to fail.
                e.Handled = true;
                // Hide the ScatterViewItem.
                draggedElement.Visibility = Visibility.Hidden;
            }

            // Remove the element from the container
            ((ObservableCollection <SimpleCard>) this.scatterView.ItemsSource).Remove(data);
        }