//will restore the scatterviewitem to visible when the user drops the item where it is not able //to be dropped private void Scatter_DragCanceled(object sender, SurfaceDragDropEventArgs e) { PhotoData data = e.Cursor.Data as PhotoData; ScatterViewItem svi = scatter.ItemContainerGenerator.ContainerFromItem(data) as ScatterViewItem; if (svi != null) { svi.Visibility = Visibility.Visible; } }
/// 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; }
///Allows you to drag items from the LibraryContainer to the ScatterView and drop them private void Scatter_Drop(object sender, SurfaceDragDropEventArgs e) { PhotoData e1 = (PhotoData)e.Cursor.Data; //if it isn't already on the Scatterview, add it to the source collection if (!ScatterItems.Contains(e.Cursor.Data)) { e1 = (PhotoData)e.Cursor.Data; ScatterItems.Add(e1); } //get the ScatterViewItem that Scatter automatically generated. ScatterViewItem svi = scatter.ItemContainerGenerator.ContainerFromItem(e.Cursor.Data) as ScatterViewItem; svi.Visibility = System.Windows.Visibility.Visible; svi.Width = e.Cursor.Visual.ActualWidth; svi.Height = e.Cursor.Visual.ActualHeight; svi.Center = e.Cursor.GetPosition(scatter); svi.Orientation = e.Cursor.GetOrientation(scatter); svi.Background = Brushes.Transparent; //setting e.handled to true ensures that default behavior is not performed e.Handled = true; }