@@ -44,9 +44,6 @@ To allow dragging outside the TreeView and dropping on a custom target, follow t
44
44
Draggable="true"
45
45
OnDragStart="@OnDragStart"
46
46
OnDrop="@TreeViewDropHandler">
47
- <TreeViewBindings>
48
- <TreeViewBinding ParentIdField="Parent"></TreeViewBinding>
49
- </TreeViewBindings>
50
47
</TelerikTreeView>
51
48
52
49
@* <TelerikSvgIcon Icon="@SvgIcon.Plus"></TelerikSvgIcon> - Render the desired icon to get its path. *@
@@ -56,10 +53,10 @@ To allow dragging outside the TreeView and dropping on a custom target, follow t
56
53
@onpointerenter="@((PointerEventArgs args) => IsPointerOverCustomTarget = true)"
57
54
@onpointerout="@((PointerEventArgs args) => IsPointerOverCustomTarget = false)">
58
55
59
- @foreach (var item in DroppedItems)
56
+ @foreach (var item in DroppedItems)
60
57
{
61
- @item.Text
62
- <br/>
58
+ @item.Text
59
+ <br />
63
60
}
64
61
</div>
65
62
@@ -83,8 +80,8 @@ To allow dragging outside the TreeView and dropping on a custom target, follow t
83
80
84
81
@code {
85
82
private TreeItem DraggedtItem { get; set; }
86
- private List<TreeItem> Data { get; set; }
87
- private IEnumerable<object> ExpandedItems { get; set; }
83
+ private List<TreeItem> Data { get; set; } = new List<TreeItem>();
84
+ private IEnumerable<object> ExpandedItems { get; set; } = Enumerable.Empty<object>();
88
85
private List<TreeItem> DroppedItems { get; set; } = new List<TreeItem>();
89
86
private bool IsPointerOverCustomTarget { get; set; }
90
87
private bool IsItemAlreadyInCustomTarget { get; set; }
@@ -100,10 +97,10 @@ To allow dragging outside the TreeView and dropping on a custom target, follow t
100
97
private void CustomTargetDropHandler()
101
98
{
102
99
if (DraggedtItem != null && !IsItemAlreadyInCustomTarget)
103
- {
100
+ {
104
101
DroppedItems.Add(DraggedtItem);
105
102
}
106
- }
103
+ }
107
104
108
105
private void TreeViewDropHandler(TreeViewDropEventArgs args)
109
106
{
@@ -117,14 +114,14 @@ To allow dragging outside the TreeView and dropping on a custom target, follow t
117
114
118
115
Data.Remove(item);
119
116
120
- if (item.Parent != null && !Data.Any(x => item.Parent == x.Parent ))
117
+ if (item.ParentId != null && !Data.Any(x => item.ParentId == x.ParentId ))
121
118
{
122
- Data.FirstOrDefault(x => x.Id == item.Parent ).HasChildren = false;
119
+ Data.FirstOrDefault(x => x.Id == item.ParentId ).HasChildren = false;
123
120
}
124
121
125
122
if (args.DropPosition == TreeViewDropPosition.Over)
126
123
{
127
- item.Parent = destinationItem.Id;
124
+ item.ParentId = destinationItem.Id;
128
125
destinationItem.HasChildren = true;
129
126
130
127
Data.Add(item);
@@ -133,7 +130,7 @@ To allow dragging outside the TreeView and dropping on a custom target, follow t
133
130
{
134
131
var index = Data.IndexOf(destinationItem);
135
132
136
- item.Parent = destinationItem.Parent ;
133
+ item.ParentId = destinationItem.ParentId ;
137
134
138
135
if (args.DropPosition == TreeViewDropPosition.After)
139
136
{
@@ -149,16 +146,16 @@ To allow dragging outside the TreeView and dropping on a custom target, follow t
149
146
150
147
private bool IsChild(TreeItem item, TreeItem destinationItem)
151
148
{
152
- if (destinationItem?.Parent == null || item == null)
149
+ if (destinationItem?.ParentId == null || item == null)
153
150
{
154
151
return false;
155
152
}
156
- else if (destinationItem.Parent ?.Equals(item.Id) == true)
153
+ else if (destinationItem.ParentId ?.Equals(item.Id) == true)
157
154
{
158
155
return true;
159
156
}
160
157
161
- var parentDestinationItem = Data.FirstOrDefault(e => e.Id.Equals(destinationItem.Parent ));
158
+ var parentDestinationItem = Data.FirstOrDefault(e => e.Id.Equals(destinationItem.ParentId ));
162
159
163
160
return IsChild(item, parentDestinationItem);
164
161
}
@@ -191,15 +188,15 @@ To allow dragging outside the TreeView and dropping on a custom target, follow t
191
188
public class TreeItem
192
189
{
193
190
public int Id { get; set; }
194
- public int? Parent { get; set; }
191
+ public int? ParentId { get; set; }
195
192
public string Text { get; set; }
196
193
public ISvgIcon Icon { get; set; }
197
194
public bool HasChildren { get; set; }
198
195
199
196
public TreeItem(int id, int? parent, string text, ISvgIcon icon, bool hasChildren)
200
197
{
201
198
Id = id;
202
- Parent = parent;
199
+ ParentId = parent;
203
200
Text = text;
204
201
Icon = icon;
205
202
HasChildren = hasChildren;
0 commit comments