@@ -13,15 +13,17 @@ namespace GongSolutions.Wpf.DragDrop
13
13
/// <summary>
14
14
/// Holds information about a the target of a drag drop operation.
15
15
/// </summary>
16
- ///
16
+ ///
17
17
/// <remarks>
18
- /// The <see cref="DropInfo"/> class holds all of the framework's information about the current
19
- /// target of a drag. It is used by <see cref="IDropTarget.DragOver"/> method to determine whether
18
+ /// The <see cref="DropInfo"/> class holds all of the framework's information about the current
19
+ /// target of a drag. It is used by <see cref="IDropTarget.DragOver"/> method to determine whether
20
20
/// the current drop target is valid, and by <see cref="IDropTarget.Drop"/> to perform the drop.
21
21
/// </remarks>
22
22
public class DropInfo : IDropInfo
23
23
{
24
- private readonly ItemsControl itemParent ;
24
+ private readonly DragEventArgs eventArgs ;
25
+ private ItemsControl itemParent ;
26
+ private bool ? acceptChildItem ;
25
27
26
28
/// <inheritdoc />
27
29
public object Data { get ; set ; }
@@ -152,6 +154,20 @@ public bool IsSameDragDropContextAsSource
152
154
/// <inheritdoc />
153
155
public EventType EventType { get ; }
154
156
157
+ /// <inheritdoc />
158
+ public bool AcceptChildItem
159
+ {
160
+ get => this . acceptChildItem . GetValueOrDefault ( ) ;
161
+ set
162
+ {
163
+ if ( value != this . acceptChildItem . GetValueOrDefault ( ) )
164
+ {
165
+ this . acceptChildItem = value ;
166
+ this . Update ( ) ;
167
+ }
168
+ }
169
+ }
170
+
155
171
/// <summary>
156
172
/// Initializes a new instance of the DropInfo class.
157
173
/// </summary>
@@ -161,6 +177,7 @@ public bool IsSameDragDropContextAsSource
161
177
/// <param name="eventType">The type of the underlying event (tunneled or bubbled).</param>
162
178
public DropInfo ( object sender , DragEventArgs e , [ CanBeNull ] IDragInfo dragInfo , EventType eventType )
163
179
{
180
+ this . eventArgs = e ;
164
181
this . DragInfo = dragInfo ;
165
182
this . KeyStates = e . KeyStates ;
166
183
this . EventType = eventType ;
@@ -200,12 +217,14 @@ public DropInfo(object sender, DragEventArgs e, [CanBeNull] IDragInfo dragInfo,
200
217
// visual target can be null, so give us a point...
201
218
this . DropPosition = this . VisualTarget != null ? e . GetPosition ( this . VisualTarget ) : new Point ( ) ;
202
219
203
- if ( this . VisualTarget is TabControl )
220
+ this . Update ( ) ;
221
+ }
222
+
223
+ private void Update ( )
224
+ {
225
+ if ( this . VisualTarget is TabControl && ! HitTestUtilities . HitTest4Type < TabPanel > ( this . VisualTarget , this . DropPosition ) )
204
226
{
205
- if ( ! HitTestUtilities . HitTest4Type < TabPanel > ( this . VisualTarget , this . DropPosition ) )
206
- {
207
- return ;
208
- }
227
+ return ;
209
228
}
210
229
211
230
if ( this . VisualTarget is ItemsControl itemsControl )
@@ -256,10 +275,11 @@ public DropInfo(object sender, DragEventArgs e, [CanBeNull] IDragInfo dragInfo,
256
275
257
276
var tvItemIsExpanded = tvItem is { HasHeader : true , HasItems : true , IsExpanded : true } ;
258
277
var itemRenderSize = tvItemIsExpanded ? tvItem . GetHeaderSize ( ) : item . RenderSize ;
278
+ this . acceptChildItem ??= tvItem != null ;
259
279
260
280
if ( this . VisualTargetOrientation == Orientation . Vertical )
261
281
{
262
- var currentYPos = e . GetPosition ( item ) . Y ;
282
+ var currentYPos = this . eventArgs . GetPosition ( item ) . Y ;
263
283
var targetHeight = itemRenderSize . Height ;
264
284
265
285
var topGap = targetHeight * 0.25 ;
@@ -285,7 +305,7 @@ public DropInfo(object sender, DragEventArgs e, [CanBeNull] IDragInfo dragInfo,
285
305
this . InsertPosition = RelativeInsertPosition . BeforeTargetItem ;
286
306
}
287
307
288
- if ( currentYPos > topGap && currentYPos < bottomGap )
308
+ if ( this . AcceptChildItem && currentYPos > topGap && currentYPos < bottomGap )
289
309
{
290
310
if ( tvItem != null )
291
311
{
@@ -300,7 +320,7 @@ public DropInfo(object sender, DragEventArgs e, [CanBeNull] IDragInfo dragInfo,
300
320
}
301
321
else
302
322
{
303
- var currentXPos = e . GetPosition ( item ) . X ;
323
+ var currentXPos = this . eventArgs . GetPosition ( item ) . X ;
304
324
var targetWidth = itemRenderSize . Width ;
305
325
306
326
if ( this . VisualTargetFlowDirection == FlowDirection . RightToLeft )
@@ -328,7 +348,7 @@ public DropInfo(object sender, DragEventArgs e, [CanBeNull] IDragInfo dragInfo,
328
348
}
329
349
}
330
350
331
- if ( currentXPos > targetWidth * 0.25 && currentXPos < targetWidth * 0.75 )
351
+ if ( this . AcceptChildItem && currentXPos > targetWidth * 0.25 && currentXPos < targetWidth * 0.75 )
332
352
{
333
353
if ( tvItem != null )
334
354
{
0 commit comments