Mercurial > silverbladetech
comparison Chronosv2/source/DragAndDrop/ListBoxDragDropDataProvider.cs @ 10:443821e55f06
Initial cleaned up add from Codeplex files
author | stevenh7776 stevenhollidge@hotmail.com |
---|---|
date | Tue, 21 Feb 2012 17:25:44 +0700 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
9:904a9faadf8b | 10:443821e55f06 |
---|---|
1 using System; | |
2 using System.Diagnostics; | |
3 using System.Windows; | |
4 using System.Windows.Controls; | |
5 using System.Windows.Controls.Primitives; | |
6 using System.Windows.Input; | |
7 using System.Xml; | |
8 | |
9 namespace Chronos.Presentation.DragAndDrop | |
10 { | |
11 public sealed class ListBoxDragDropDataProvider : IDataDropObjectProvider | |
12 { | |
13 #region · Fields · | |
14 | |
15 private ListBox list; | |
16 | |
17 #endregion | |
18 | |
19 #region · Properties · | |
20 | |
21 public DragDropProviderActions SupportedActions | |
22 { | |
23 get | |
24 { | |
25 return DragDropProviderActions.Data | | |
26 DragDropProviderActions.Visual | | |
27 DragDropProviderActions.Unparent | | |
28 DragDropProviderActions.MultiFormatData; | |
29 } | |
30 } | |
31 | |
32 #endregion | |
33 | |
34 #region · Constructors · | |
35 | |
36 public ListBoxDragDropDataProvider(ListBox list) | |
37 { | |
38 this.list = list; | |
39 } | |
40 | |
41 #endregion | |
42 | |
43 #region · IDataDropObjectProvider Members · | |
44 | |
45 public void AppendData (ref IDataObject data, MouseEventArgs e) | |
46 { | |
47 if (!(this.list.InputHitTest(e.GetPosition(e.OriginalSource as UIElement)) is ListBox) | |
48 && !(this.list.InputHitTest(e.GetPosition(e.OriginalSource as UIElement)) is ScrollViewer) | |
49 && !(e.OriginalSource is Thumb)) | |
50 { | |
51 object o = this.list.SelectedItem; | |
52 | |
53 // This is cheating .. just for an example's sake.. | |
54 Debug.Assert(!data.GetDataPresent(DataFormats.Text)); | |
55 | |
56 if (o.GetType() == typeof(XmlElement)) | |
57 { | |
58 data.SetData(DataFormats.Text, ((XmlElement)o).OuterXml); | |
59 } | |
60 else | |
61 { | |
62 data.SetData(DataFormats.Text, o.ToString()); | |
63 } | |
64 | |
65 Debug.Assert(!data.GetDataPresent(o.GetType().ToString())); | |
66 | |
67 data.SetData(o.GetType().ToString(), o); | |
68 } | |
69 else | |
70 { | |
71 data = null; | |
72 } | |
73 } | |
74 | |
75 public object GetData() | |
76 { | |
77 return this.list.SelectedItem; | |
78 } | |
79 | |
80 public UIElement GetVisual(MouseEventArgs e) | |
81 { | |
82 return this.list.ItemContainerGenerator.ContainerFromItem(this.list.SelectedItem) as UIElement; | |
83 } | |
84 | |
85 public void GiveFeedback(System.Windows.GiveFeedbackEventArgs args) | |
86 { | |
87 throw new NotImplementedException("Forgot to check the Supported actions??"); | |
88 } | |
89 | |
90 public void ContinueDrag(System.Windows.QueryContinueDragEventArgs args) | |
91 { | |
92 throw new NotImplementedException("Forgot to check the Supported actions??"); | |
93 } | |
94 | |
95 public bool UnParent() | |
96 { | |
97 // We are passing data, nothing to unparent | |
98 throw new NotImplementedException("We are passing data, nothing to unparent... what up "); | |
99 } | |
100 | |
101 #endregion | |
102 } | |
103 } |