--- a/src/FingersDance.Views/TimelineView.xaml.cs Wed Sep 30 16:58:58 2009 +0200
+++ b/src/FingersDance.Views/TimelineView.xaml.cs Fri Oct 02 18:49:07 2009 +0200
@@ -11,6 +11,11 @@
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
+using Microsoft.Surface.Presentation.Controls;
+using Microsoft.Surface.Presentation;
+
+using FingersDance.Views;
+using FingersDance.ViewModels;
namespace FingersDance.Views
{
@@ -23,5 +28,73 @@
{
InitializeComponent();
}
+
+ private void listview_PreviewContactDown(object sender, Microsoft.Surface.Presentation.ContactEventArgs 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 = new TimelineAnnotationView()
+ {
+ DataContext = findSource.DataContext
+ }
+ };
+
+ // TO DO : apply the good scale to the TAV because the dragged one has scale at 1.
+
+
+ // 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 contacts that
+ // are currently captured within the dragged element and
+ // the current contact (if it isn't already in the list).
+ List<InputDevice> devices = new List<InputDevice>();
+ devices.Add(e.Contact);
+ foreach (Contact contact in draggedElement.ContactsCapturedWithin)
+ {
+ if (contact != e.Contact)
+ {
+ devices.Add(contact);
+ }
+ }
+
+ // Get the drag source object
+ ItemsControl dragSource = ItemsControl.ItemsControlFromItemContainer(draggedElement);
+
+ bool 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 contact
+ // and causes the drag operation to fail.
+ e.Handled = startDragOkay;
+
+ }
+
+
}
}