Skip to content

Commit c900c5b

Browse files
committed
check for RootVisual in GlowWindowBehavior
1 parent d47e2f0 commit c900c5b

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/MahApps.Metro/MahApps.Metro.Shared/Behaviours/GlowWindowBehavior.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public class GlowWindowBehavior : Behavior<Window>
1616
private GlowWindow left, right, top, bottom;
1717
private DispatcherTimer makeGlowVisibleTimer;
1818
private IntPtr handle;
19+
private HwndSource hwndSource;
1920

2021
private bool IsGlowDisabled
2122
{
@@ -34,16 +35,16 @@ private bool IsWindowTransitionsEnabled
3435
return metroWindow != null && metroWindow.WindowTransitionsEnabled;
3536
}
3637
}
37-
38+
3839
protected override void OnAttached()
3940
{
4041
base.OnAttached();
4142

4243
this.AssociatedObject.SourceInitialized += (o, args) =>
4344
{
4445
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);
4748
};
4849
this.AssociatedObject.Loaded += this.AssociatedObjectOnLoaded;
4950
this.AssociatedObject.Unloaded += this.AssociatedObjectUnloaded;
@@ -158,6 +159,11 @@ private void AssociatedObjectOnLoaded(object sender, RoutedEventArgs routedEvent
158159

159160
private IntPtr AssociatedObjectWindowProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
160161
{
162+
if (hwndSource?.RootVisual == null)
163+
{
164+
return IntPtr.Zero;
165+
}
166+
161167
switch ((WM)msg)
162168
{
163169
case WM.WINDOWPOSCHANGED:

0 commit comments

Comments
 (0)