/// <summary> /// Extends the glass frame. /// </summary> /// <param name="window">The window.</param> /// <param name="margin">The margin.</param> /// <returns></returns> public static bool ExtendGlassFrame(Window window, Thickness margin) { if(!DwmIsCompositionEnabled()) { return false; } 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 SolidColorBrush background = new SolidColorBrush(Colors.Red); background.Opacity = 0.5; window.Background = Brushes.Transparent; HwndSource.FromHwnd(hwnd).CompositionTarget.BackgroundColor = Colors.Transparent; MARGINS margins = new MARGINS(margin); DwmExtendFrameIntoClientArea(hwnd, ref margins); return true; }
static extern void DwmExtendFrameIntoClientArea(IntPtr hwnd, ref MARGINS margins);
/* Verbreitert den Rahmen des Fensters entsprechend den Einstellungen in Padding */ private void ExtendFrame() { if(this.IsGlassFrameEnabled) { if(this.DesignMode == false) { // Wenn nicht im Design-Modus: den Rahmen verbreitern MARGINS margins = new MARGINS() { Left = this.Padding.Left, Top = this.Padding.Top, Right = this.Padding.Right, Bottom = this.Padding.Bottom }; DwmExtendFrameIntoClientArea(this.Handle, ref margins); } } }
public static extern int DwmExtendFrameIntoClientArea( IntPtr hWnd, ref MARGINS pMarInset );