author | cavaliet |
Wed, 07 Oct 2009 17:16:46 +0200 | |
changeset 135 | 84b3bf5ee3d2 |
parent 130 | 192da585bee5 |
child 136 | 8b513df1b446 |
permissions | -rw-r--r-- |
55 | 1 |
using System; |
2 |
using System.Collections.Generic; |
|
3 |
using System.Linq; |
|
4 |
using System.Text; |
|
5 |
using System.Windows; |
|
6 |
using System.Windows.Controls; |
|
7 |
using System.Windows.Data; |
|
8 |
using System.Windows.Documents; |
|
9 |
using System.Windows.Input; |
|
10 |
using System.Windows.Media; |
|
11 |
using System.Windows.Media.Imaging; |
|
12 |
using System.Windows.Navigation; |
|
13 |
using System.Windows.Shapes; |
|
128
90c29e979ef4
Drag and drop of annotations from timeline, first step
cavaliet
parents:
55
diff
changeset
|
14 |
using Microsoft.Surface.Presentation.Controls; |
90c29e979ef4
Drag and drop of annotations from timeline, first step
cavaliet
parents:
55
diff
changeset
|
15 |
using Microsoft.Surface.Presentation; |
90c29e979ef4
Drag and drop of annotations from timeline, first step
cavaliet
parents:
55
diff
changeset
|
16 |
|
135
84b3bf5ee3d2
First step of drag and drop annotation from a timeline to an other player
cavaliet
parents:
130
diff
changeset
|
17 |
using FingersDance.Data; |
84b3bf5ee3d2
First step of drag and drop annotation from a timeline to an other player
cavaliet
parents:
130
diff
changeset
|
18 |
using FingersDance.ViewModels; |
128
90c29e979ef4
Drag and drop of annotations from timeline, first step
cavaliet
parents:
55
diff
changeset
|
19 |
using FingersDance.Views; |
55 | 20 |
|
21 |
namespace FingersDance.Views |
|
22 |
{ |
|
23 |
/// <summary> |
|
24 |
/// Interaction logic for TimelineView.xaml |
|
25 |
/// </summary> |
|
26 |
public partial class TimelineView : UserControl |
|
27 |
{ |
|
28 |
public TimelineView() |
|
29 |
{ |
|
30 |
InitializeComponent(); |
|
31 |
} |
|
128
90c29e979ef4
Drag and drop of annotations from timeline, first step
cavaliet
parents:
55
diff
changeset
|
32 |
|
90c29e979ef4
Drag and drop of annotations from timeline, first step
cavaliet
parents:
55
diff
changeset
|
33 |
private void listview_PreviewContactDown(object sender, Microsoft.Surface.Presentation.ContactEventArgs e) |
90c29e979ef4
Drag and drop of annotations from timeline, first step
cavaliet
parents:
55
diff
changeset
|
34 |
{ |
90c29e979ef4
Drag and drop of annotations from timeline, first step
cavaliet
parents:
55
diff
changeset
|
35 |
FrameworkElement findSource = e.OriginalSource as FrameworkElement; |
90c29e979ef4
Drag and drop of annotations from timeline, first step
cavaliet
parents:
55
diff
changeset
|
36 |
SurfaceListBoxItem draggedElement = null; |
90c29e979ef4
Drag and drop of annotations from timeline, first step
cavaliet
parents:
55
diff
changeset
|
37 |
|
90c29e979ef4
Drag and drop of annotations from timeline, first step
cavaliet
parents:
55
diff
changeset
|
38 |
// Find the touched SurfaceListBoxItem object. |
90c29e979ef4
Drag and drop of annotations from timeline, first step
cavaliet
parents:
55
diff
changeset
|
39 |
while (draggedElement == null && findSource != null) |
90c29e979ef4
Drag and drop of annotations from timeline, first step
cavaliet
parents:
55
diff
changeset
|
40 |
{ |
90c29e979ef4
Drag and drop of annotations from timeline, first step
cavaliet
parents:
55
diff
changeset
|
41 |
if ((draggedElement = findSource as SurfaceListBoxItem) == null) |
90c29e979ef4
Drag and drop of annotations from timeline, first step
cavaliet
parents:
55
diff
changeset
|
42 |
{ |
90c29e979ef4
Drag and drop of annotations from timeline, first step
cavaliet
parents:
55
diff
changeset
|
43 |
findSource = VisualTreeHelper.GetParent(findSource) as FrameworkElement; |
90c29e979ef4
Drag and drop of annotations from timeline, first step
cavaliet
parents:
55
diff
changeset
|
44 |
} |
90c29e979ef4
Drag and drop of annotations from timeline, first step
cavaliet
parents:
55
diff
changeset
|
45 |
} |
90c29e979ef4
Drag and drop of annotations from timeline, first step
cavaliet
parents:
55
diff
changeset
|
46 |
|
90c29e979ef4
Drag and drop of annotations from timeline, first step
cavaliet
parents:
55
diff
changeset
|
47 |
if (draggedElement == null) |
90c29e979ef4
Drag and drop of annotations from timeline, first step
cavaliet
parents:
55
diff
changeset
|
48 |
{ |
90c29e979ef4
Drag and drop of annotations from timeline, first step
cavaliet
parents:
55
diff
changeset
|
49 |
return; |
90c29e979ef4
Drag and drop of annotations from timeline, first step
cavaliet
parents:
55
diff
changeset
|
50 |
} |
90c29e979ef4
Drag and drop of annotations from timeline, first step
cavaliet
parents:
55
diff
changeset
|
51 |
|
90c29e979ef4
Drag and drop of annotations from timeline, first step
cavaliet
parents:
55
diff
changeset
|
52 |
// Create the cursor visual. |
90c29e979ef4
Drag and drop of annotations from timeline, first step
cavaliet
parents:
55
diff
changeset
|
53 |
ContentControl cursorVisual = new ContentControl() |
90c29e979ef4
Drag and drop of annotations from timeline, first step
cavaliet
parents:
55
diff
changeset
|
54 |
{ |
90c29e979ef4
Drag and drop of annotations from timeline, first step
cavaliet
parents:
55
diff
changeset
|
55 |
Content = new TimelineAnnotationView() |
90c29e979ef4
Drag and drop of annotations from timeline, first step
cavaliet
parents:
55
diff
changeset
|
56 |
{ |
90c29e979ef4
Drag and drop of annotations from timeline, first step
cavaliet
parents:
55
diff
changeset
|
57 |
DataContext = findSource.DataContext |
90c29e979ef4
Drag and drop of annotations from timeline, first step
cavaliet
parents:
55
diff
changeset
|
58 |
} |
90c29e979ef4
Drag and drop of annotations from timeline, first step
cavaliet
parents:
55
diff
changeset
|
59 |
}; |
90c29e979ef4
Drag and drop of annotations from timeline, first step
cavaliet
parents:
55
diff
changeset
|
60 |
|
130
192da585bee5
debug for adding annotations on timeline. Data AnnotationViewModel and TimelineAnnotationView changed to keep annotation TcBegin from visual margin.
cavaliet
parents:
128
diff
changeset
|
61 |
// We apply the current scale to the dragged annotation |
192da585bee5
debug for adding annotations on timeline. Data AnnotationViewModel and TimelineAnnotationView changed to keep annotation TcBegin from visual margin.
cavaliet
parents:
128
diff
changeset
|
62 |
((TimelineAnnotationView)cursorVisual.Content).RenderTransform = this.RenderTransform; |
128
90c29e979ef4
Drag and drop of annotations from timeline, first step
cavaliet
parents:
55
diff
changeset
|
63 |
|
90c29e979ef4
Drag and drop of annotations from timeline, first step
cavaliet
parents:
55
diff
changeset
|
64 |
// Add a handler. This will enable the application to change the visual cues. |
90c29e979ef4
Drag and drop of annotations from timeline, first step
cavaliet
parents:
55
diff
changeset
|
65 |
//SurfaceDragDrop.AddTargetChangedHandler(cursorVisual, OnTargetChanged); |
90c29e979ef4
Drag and drop of annotations from timeline, first step
cavaliet
parents:
55
diff
changeset
|
66 |
|
90c29e979ef4
Drag and drop of annotations from timeline, first step
cavaliet
parents:
55
diff
changeset
|
67 |
// Create a list of input devices. Add the contacts that |
90c29e979ef4
Drag and drop of annotations from timeline, first step
cavaliet
parents:
55
diff
changeset
|
68 |
// are currently captured within the dragged element and |
90c29e979ef4
Drag and drop of annotations from timeline, first step
cavaliet
parents:
55
diff
changeset
|
69 |
// the current contact (if it isn't already in the list). |
90c29e979ef4
Drag and drop of annotations from timeline, first step
cavaliet
parents:
55
diff
changeset
|
70 |
List<InputDevice> devices = new List<InputDevice>(); |
90c29e979ef4
Drag and drop of annotations from timeline, first step
cavaliet
parents:
55
diff
changeset
|
71 |
devices.Add(e.Contact); |
90c29e979ef4
Drag and drop of annotations from timeline, first step
cavaliet
parents:
55
diff
changeset
|
72 |
foreach (Contact contact in draggedElement.ContactsCapturedWithin) |
90c29e979ef4
Drag and drop of annotations from timeline, first step
cavaliet
parents:
55
diff
changeset
|
73 |
{ |
90c29e979ef4
Drag and drop of annotations from timeline, first step
cavaliet
parents:
55
diff
changeset
|
74 |
if (contact != e.Contact) |
90c29e979ef4
Drag and drop of annotations from timeline, first step
cavaliet
parents:
55
diff
changeset
|
75 |
{ |
90c29e979ef4
Drag and drop of annotations from timeline, first step
cavaliet
parents:
55
diff
changeset
|
76 |
devices.Add(contact); |
90c29e979ef4
Drag and drop of annotations from timeline, first step
cavaliet
parents:
55
diff
changeset
|
77 |
} |
90c29e979ef4
Drag and drop of annotations from timeline, first step
cavaliet
parents:
55
diff
changeset
|
78 |
} |
90c29e979ef4
Drag and drop of annotations from timeline, first step
cavaliet
parents:
55
diff
changeset
|
79 |
|
90c29e979ef4
Drag and drop of annotations from timeline, first step
cavaliet
parents:
55
diff
changeset
|
80 |
// Get the drag source object |
90c29e979ef4
Drag and drop of annotations from timeline, first step
cavaliet
parents:
55
diff
changeset
|
81 |
ItemsControl dragSource = ItemsControl.ItemsControlFromItemContainer(draggedElement); |
90c29e979ef4
Drag and drop of annotations from timeline, first step
cavaliet
parents:
55
diff
changeset
|
82 |
|
90c29e979ef4
Drag and drop of annotations from timeline, first step
cavaliet
parents:
55
diff
changeset
|
83 |
bool startDragOkay = |
90c29e979ef4
Drag and drop of annotations from timeline, first step
cavaliet
parents:
55
diff
changeset
|
84 |
SurfaceDragDrop.BeginDragDrop( |
90c29e979ef4
Drag and drop of annotations from timeline, first step
cavaliet
parents:
55
diff
changeset
|
85 |
dragSource, // The SurfaceListBox object that the cursor is dragged out from. |
90c29e979ef4
Drag and drop of annotations from timeline, first step
cavaliet
parents:
55
diff
changeset
|
86 |
draggedElement, // The SurfaceListBoxItem object that is dragged from the drag source. |
90c29e979ef4
Drag and drop of annotations from timeline, first step
cavaliet
parents:
55
diff
changeset
|
87 |
cursorVisual, // The visual element of the cursor. |
90c29e979ef4
Drag and drop of annotations from timeline, first step
cavaliet
parents:
55
diff
changeset
|
88 |
draggedElement.DataContext, // The data associated with the cursor. |
90c29e979ef4
Drag and drop of annotations from timeline, first step
cavaliet
parents:
55
diff
changeset
|
89 |
devices, // The input devices that start dragging the cursor. |
90c29e979ef4
Drag and drop of annotations from timeline, first step
cavaliet
parents:
55
diff
changeset
|
90 |
DragDropEffects.Move); // The allowed drag-and-drop effects of the operation. |
90c29e979ef4
Drag and drop of annotations from timeline, first step
cavaliet
parents:
55
diff
changeset
|
91 |
|
90c29e979ef4
Drag and drop of annotations from timeline, first step
cavaliet
parents:
55
diff
changeset
|
92 |
// If the drag began successfully, set e.Handled to true. |
90c29e979ef4
Drag and drop of annotations from timeline, first step
cavaliet
parents:
55
diff
changeset
|
93 |
// Otherwise SurfaceListBoxItem captures the contact |
90c29e979ef4
Drag and drop of annotations from timeline, first step
cavaliet
parents:
55
diff
changeset
|
94 |
// and causes the drag operation to fail. |
90c29e979ef4
Drag and drop of annotations from timeline, first step
cavaliet
parents:
55
diff
changeset
|
95 |
e.Handled = startDragOkay; |
90c29e979ef4
Drag and drop of annotations from timeline, first step
cavaliet
parents:
55
diff
changeset
|
96 |
|
90c29e979ef4
Drag and drop of annotations from timeline, first step
cavaliet
parents:
55
diff
changeset
|
97 |
} |
90c29e979ef4
Drag and drop of annotations from timeline, first step
cavaliet
parents:
55
diff
changeset
|
98 |
|
55 | 99 |
} |
100 |
} |