protected override void OnRenderSizeChanged(SizeChangedInfo sizeInfo) { base.OnRenderSizeChanged(sizeInfo); // // In WPF, using layered windows to make non-rectangular windows incurs a huge performance hit // in rendering because the rendering system has to get a device context from GDI, which is // currently only supported in software. // // To avoid this, we use interop to get access to old Win32 functions to programmatically describe // what the shape of our window will be. We do this whenever the size changes to make sure the window's // shape remains the same. // // Note: ScaleUI is a class Mike Malinak wrote to account for different DPI settings. I will elaborate // more on WPF and DPI in a future blog post // First, we create the rounded portion of the title bar area with a call to CreateRoundRectRgn IntPtr titleArea = GDI32.CreateRoundRectRgn( 0, 0, (int)ScaleUI.UpScaleX(sizeInfo.NewSize.Width), (int)ScaleUI.UpScaleY(MainContentBorder.ActualHeight), 12, 12); //IntPtr clientArea = GDI32.CreateRoundRectRgn( // 0, // 0, // (int)ScaleUI.UpScaleX(sizeInfo.NewSize.Width), // (int)ScaleUI.UpScaleY(MainContentBorder.ActualHeight) + 10, // 10, // 10); //// Next, we create a rectangle for the client area //IntPtr clientArea = GDI32.CreateRectRgn( // 0, // (int)ScaleUI.UpScaleY(MainContentBorder.ActualHeight), // (int)ScaleUI.UpScaleX(sizeInfo.NewSize.Width), // (int)ScaleUI.UpScaleY(sizeInfo.NewSize.Height)); //// After the regions have been created, you have to combine them //IntPtr windowArea = GDI32.CreateRectRgn(0, 0, 0, 0); //GDI32.CombineRgn(windowArea, titleArea, clientArea, GDI32.CombineRgnStyles.RGN_OR); // Last, SetWindowRgn tells GDI what the windows final shape will look like var win = new System.Windows.Interop.WindowInteropHelper(this); User32.SetWindowRgn(win.Handle, titleArea, true); }