@@ -16,6 +16,7 @@ public class GlowWindowBehavior : Behavior<Window>
16
16
private GlowWindow left , right , top , bottom ;
17
17
private DispatcherTimer makeGlowVisibleTimer ;
18
18
private IntPtr handle ;
19
+ private HwndSource hwndSource ;
19
20
20
21
private bool IsGlowDisabled
21
22
{
@@ -34,16 +35,16 @@ private bool IsWindowTransitionsEnabled
34
35
return metroWindow != null && metroWindow . WindowTransitionsEnabled ;
35
36
}
36
37
}
37
-
38
+
38
39
protected override void OnAttached ( )
39
40
{
40
41
base . OnAttached ( ) ;
41
42
42
43
this . AssociatedObject . SourceInitialized += ( o , args ) =>
43
44
{
44
45
this . handle = new WindowInteropHelper ( this . AssociatedObject ) . Handle ;
45
- var hwndSource = HwndSource . FromHwnd ( this . handle ) ;
46
- hwndSource ? . AddHook ( this . AssociatedObjectWindowProc ) ;
46
+ this . hwndSource = HwndSource . FromHwnd ( this . handle ) ;
47
+ this . hwndSource ? . AddHook ( this . AssociatedObjectWindowProc ) ;
47
48
} ;
48
49
this . AssociatedObject . Loaded += this . AssociatedObjectOnLoaded ;
49
50
this . AssociatedObject . Unloaded += this . AssociatedObjectUnloaded ;
@@ -158,6 +159,11 @@ private void AssociatedObjectOnLoaded(object sender, RoutedEventArgs routedEvent
158
159
159
160
private IntPtr AssociatedObjectWindowProc ( IntPtr hwnd , int msg , IntPtr wParam , IntPtr lParam , ref bool handled )
160
161
{
162
+ if ( hwndSource ? . RootVisual == null )
163
+ {
164
+ return IntPtr . Zero ;
165
+ }
166
+
161
167
switch ( ( WM ) msg )
162
168
{
163
169
case WM . WINDOWPOSCHANGED :
0 commit comments