public static bool ExtendGlassFrame(Window window, Thickness margin) { if (!Native.DwmIsCompositionEnabled()) { return(false); } try { IntPtr hwnd = new WindowInteropHelper(window).Handle; if (hwnd == IntPtr.Zero) { throw new InvalidOperationException("The Window must be shown before extending glass."); } // Set the background to transparent from both the WPF and Win32 perspectives window.Background = Brushes.Transparent; HwndSource.FromHwnd(hwnd).CompositionTarget.BackgroundColor = Colors.Transparent; Native.MARGINS margins = new Native.MARGINS(margin); Native.DwmExtendFrameIntoClientArea(hwnd, ref margins); return(true); } catch (Exception ex) { LogWriter.Log(ex, "Error • Glass"); } return(false); }
public static bool RetractGlassFrame(Window window) { if (!Native.DwmIsCompositionEnabled()) { return(false); } try { var hwnd = new WindowInteropHelper(window).Handle; if (hwnd == IntPtr.Zero) { throw new InvalidOperationException("The Window must be shown before retracting the glass."); } #region Set the background to transparent from both the WPF and Win32 perspectives var brush = window.TryFindResource("Panel.Background.Level3") as SolidColorBrush ?? new SolidColorBrush(Color.FromArgb(255, 241, 241, 241)); window.Background = brush; var hwndSource = HwndSource.FromHwnd(hwnd); if (hwndSource?.CompositionTarget != null) { hwndSource.CompositionTarget.BackgroundColor = brush.Color; } #endregion var margins = new Native.Margins(new Thickness(0, 0, 0, 0)); Native.DwmExtendFrameIntoClientArea(hwnd, ref margins); return(true); } catch (Exception ex) { LogWriter.Log(ex, "Error • Retracting Glass"); } return(false); }