添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
[DllImport("dwmapi.dll", PreserveSig = false)] static extern void DwmExtendFrameIntoClientArea ( IntPtr hWnd , ref MARGINS pMarInset ); [DllImport("dwmapi.dll", PreserveSig = false)] static extern bool DwmIsCompositionEnabled (); 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." ); // 将Win32或者WPF程序背景设置为透明 window . Background = Brushes . Transparent ; HwndSource . FromHwnd ( hwnd ). CompositionTarget . BackgroundColor = Colors . Transparent ; MARGINS margins = new MARGINS ( margin ); DwmExtendFrameIntoClientArea ( hwnd , ref margins ); return true ;

然后你只需要重写 OnSourceInitialized 方法即可。

protected override void OnSourceInitialized(EventArgs e)
    base.OnSourceInitialized(e);
    GlassHelper.ExtendGlassFrame(this, new Thickness(-1));