comparison Chronosv2/source/DragAndDrop/TreeviewDragDropDataProvider.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.Windows;
3 using System.Windows.Controls;
4 using System.Windows.Controls.Primitives;
5 using System.Windows.Input;
6 using System.Xml;
7 using Chronos.Extensions.Windows;
8
9 namespace Chronos.Presentation.DragAndDrop
10 {
11 public sealed class TreeViewDragDropDataProvider : IDataDropObjectProvider
12 {
13 #region · Fields ·
14
15 private TreeView treeview;
16
17 #endregion
18
19 #region · Properties ·
20
21 public DragDropProviderActions SupportedActions
22 {
23 get
24 {
25 return DragDropProviderActions.Data |
26 DragDropProviderActions.MultiFormatData;
27 }
28 }
29
30 #endregion
31
32 #region · Constructors ·
33
34 public TreeViewDragDropDataProvider(TreeView treeview)
35 {
36 this.treeview = treeview;
37 }
38
39 #endregion
40
41 #region · IDataDropObjectProvider Members ·
42
43 public void AppendData(ref IDataObject data, MouseEventArgs e)
44 {
45 if (!(this.treeview.InputHitTest(e.GetPosition(e.OriginalSource as UIElement)) is TreeView)
46 && !(this.treeview.InputHitTest(e.GetPosition(e.OriginalSource as UIElement)) is ScrollViewer)
47 && !(e.OriginalSource is Thumb))
48 {
49 TreeViewItem selectedUIelement = this.GetVisual(e).GetParent<TreeViewItem>();
50
51 if (selectedUIelement != null && selectedUIelement.Items.Count == 0)
52 {
53 object selectedItem = this.treeview.SelectedItem;
54
55 if (selectedItem != null)
56 {
57 if (selectedItem.GetType() == typeof(XmlElement))
58 {
59 data.SetData(DataFormats.Text, ((XmlElement)selectedItem).OuterXml);
60 }
61 else
62 {
63 data.SetData(DataFormats.Text, selectedItem.ToString());
64 }
65
66 data.SetData(selectedItem.GetType().ToString(), selectedItem);
67 }
68 else
69 {
70 data = null;
71 }
72 }
73 else
74 {
75 data = null;
76 }
77 }
78 else
79 {
80 data = null;
81 }
82 }
83
84 public object GetData()
85 {
86 return this.treeview.SelectedItem;
87 }
88
89 public UIElement GetVisual(MouseEventArgs e)
90 {
91 // return this.treeview.ItemContainerGenerator.ContainerFromItem(this.treeview.SelectedItem) as UIElement;
92 return e.OriginalSource as UIElement;
93 }
94
95 public void GiveFeedback(System.Windows.GiveFeedbackEventArgs args)
96 {
97 throw new NotImplementedException("Forgot to check the Supported actions??");
98 }
99
100 public void ContinueDrag(System.Windows.QueryContinueDragEventArgs args)
101 {
102 throw new NotImplementedException("Forgot to check the Supported actions??");
103 }
104
105 public bool UnParent()
106 {
107 // We are passing data, nothing to unparent
108 throw new NotImplementedException("We are passing data, nothing to unparent... what up ");
109 }
110
111 #endregion
112 }
113 }