Example #1
0
        /// <summary>
        /// Extends the glass frame of a window
        /// </summary>
        public static bool ExtendGlassFrame(Window window, Thickness margin)
        {
            if (!IsDwmCompositionEnabled)
            {
                return(false);
            }

            IntPtr hwnd = new WindowInteropHelper(window).Handle;

            if (hwnd == IntPtr.Zero)
            {
                throw new InvalidOperationException("The Window must be shown before extending glass.");
            }

            HwndSource source = HwndSource.FromHwnd(hwnd);

            // Set the background to transparent from both the WPF and Win32 perspectives
            window.Background = Brushes.Transparent;
            source.CompositionTarget.BackgroundColor = Colors.Transparent;

            Interop.Margins margins = new Interop.Margins(margin);
            Interop.DwmExtendFrameIntoClientArea(hwnd, ref margins);
            return(true);
        }
Example #2
0
        /// <summary>
        /// Extends the glass frame of a window
        /// </summary>
        public static bool ExtendGlassFrame(Window window, Thickness margin)
        {
            if (!IsDwmCompositionEnabled)
                return false;

            IntPtr hwnd = new WindowInteropHelper(window).Handle;
            if (hwnd == IntPtr.Zero)
                throw new InvalidOperationException("The Window must be shown before extending glass.");

            HwndSource source = HwndSource.FromHwnd(hwnd);

            // Set the background to transparent from both the WPF and Win32 perspectives
            window.Background = Brushes.Transparent;
            source.CompositionTarget.BackgroundColor = Colors.Transparent;

            Interop.Margins margins = new Interop.Margins(margin);
            Interop.DwmExtendFrameIntoClientArea(hwnd, ref margins);
            return true;
        }