5
5
6
6
namespace GongSolutions . Wpf . DragDrop
7
7
{
8
+ using JetBrains . Annotations ;
9
+
8
10
public abstract class DropTargetAdorner : Adorner
9
11
{
10
12
public DropTargetAdorner ( UIElement adornedElement , IDropInfo dropInfo )
@@ -14,8 +16,9 @@ public DropTargetAdorner(UIElement adornedElement, IDropInfo dropInfo)
14
16
this . IsHitTestVisible = false ;
15
17
this . AllowDrop = false ;
16
18
this . SnapsToDevicePixels = true ;
17
- this . m_AdornerLayer = AdornerLayer . GetAdornerLayer ( adornedElement ) ;
18
- this . m_AdornerLayer . Add ( this ) ;
19
+ this . adornerLayer = AdornerLayer . GetAdornerLayer ( adornedElement ) ;
20
+ // can be null but should normally not be null
21
+ this . adornerLayer ? . Add ( this ) ;
19
22
}
20
23
21
24
public IDropInfo DropInfo { get ; set ; }
@@ -25,15 +28,20 @@ public DropTargetAdorner(UIElement adornedElement, IDropInfo dropInfo)
25
28
/// </summary>
26
29
public Pen Pen { get ; set ; } = new Pen ( Brushes . Gray , 2 ) ;
27
30
28
- public void Detatch ( )
31
+ public void Detach ( )
29
32
{
30
- if ( ! m_AdornerLayer . Dispatcher . CheckAccess ( ) )
33
+ if ( this . adornerLayer is null )
34
+ {
35
+ return ;
36
+ }
37
+
38
+ if ( ! this . adornerLayer . Dispatcher . CheckAccess ( ) )
31
39
{
32
- m_AdornerLayer . Dispatcher . Invoke ( this . Detatch ) ;
40
+ this . adornerLayer . Dispatcher . Invoke ( this . Detach ) ;
33
41
return ;
34
42
}
35
43
36
- this . m_AdornerLayer . Remove ( this ) ;
44
+ this . adornerLayer . Remove ( this ) ;
37
45
}
38
46
39
47
internal static DropTargetAdorner Create ( Type type , UIElement adornedElement , IDropInfo dropInfo )
@@ -42,9 +50,11 @@ internal static DropTargetAdorner Create(Type type, UIElement adornedElement, ID
42
50
{
43
51
throw new InvalidOperationException ( "The requested adorner class does not derive from DropTargetAdorner." ) ;
44
52
}
53
+
45
54
return type . GetConstructor ( new [ ] { typeof ( UIElement ) , typeof ( DropInfo ) } ) ? . Invoke ( new object [ ] { adornedElement , dropInfo } ) as DropTargetAdorner ;
46
55
}
47
56
48
- private readonly AdornerLayer m_AdornerLayer ;
57
+ [ CanBeNull ]
58
+ private readonly AdornerLayer adornerLayer ;
49
59
}
50
60
}
0 commit comments