private bool ApplyGlass() { try { this.Background = new SolidColorBrush(Color.FromArgb(0, 0, 0, 0)); // Obtain the window handle for WPF application IntPtr mainWindowPtr = new WindowInteropHelper(this).Handle; HwndSource mainWindowSrc = HwndSource.FromHwnd(mainWindowPtr); mainWindowSrc.CompositionTarget.BackgroundColor = Color.FromArgb(50, 16, 25, 39); // Get System Dpi System.Drawing.Graphics desktop = System.Drawing.Graphics.FromHwnd(mainWindowPtr); float DesktopDpiX = desktop.DpiX; float DesktopDpiY = desktop.DpiY; // Set Margins NativeMethods.MARGINS margins = new NativeMethods.MARGINS(); // Extend glass frame into client area // Note that the default desktop Dpi is 96dpi. The margins are // adjusted for the system Dpi. margins.cxLeftWidth = Convert.ToInt32(5 * (DesktopDpiX / 96)); margins.cxRightWidth = Convert.ToInt32(5 * (DesktopDpiX / 96)); margins.cyTopHeight = Convert.ToInt32((int)this.ActualHeight); margins.cyBottomHeight = Convert.ToInt32(5 * (DesktopDpiX / 96)); int hr = NativeMethods.DwmExtendFrameIntoClientArea(mainWindowSrc.Handle, ref margins); // if (hr < 0) { //DwmExtendFrameIntoClientArea Failed return(false); } return(true); } // If not Vista, paint background white. catch (DllNotFoundException) { Application.Current.MainWindow.Background = Brushes.White; } return(false); }
private bool ApplyGlass() { try { this.Background = new SolidColorBrush( Color.FromArgb( 0, 0, 0, 0 ) ); // Obtain the window handle for WPF application IntPtr mainWindowPtr = new WindowInteropHelper( this ).Handle; HwndSource mainWindowSrc = HwndSource.FromHwnd( mainWindowPtr ); mainWindowSrc.CompositionTarget.BackgroundColor = Color.FromArgb( 50, 16, 25, 39 ); // Get System Dpi System.Drawing.Graphics desktop = System.Drawing.Graphics.FromHwnd( mainWindowPtr ); float DesktopDpiX = desktop.DpiX; float DesktopDpiY = desktop.DpiY; // Set Margins NativeMethods.MARGINS margins = new NativeMethods.MARGINS(); // Extend glass frame into client area // Note that the default desktop Dpi is 96dpi. The margins are // adjusted for the system Dpi. margins.cxLeftWidth = Convert.ToInt32( 5 * ( DesktopDpiX / 96 ) ); margins.cxRightWidth = Convert.ToInt32( 5 * ( DesktopDpiX / 96 ) ); margins.cyTopHeight = Convert.ToInt32( (int)this.ActualHeight ); margins.cyBottomHeight = Convert.ToInt32( 5 * ( DesktopDpiX / 96 ) ); int hr = NativeMethods.DwmExtendFrameIntoClientArea( mainWindowSrc.Handle, ref margins ); // if ( hr < 0 ) { //DwmExtendFrameIntoClientArea Failed return false; } return true; } // If not Vista, paint background white. catch ( DllNotFoundException ) { Application.Current.MainWindow.Background = Brushes.White; } return false; }