예제 #1
0
        private void UpdateBlur(Visual backgroundVisual)
        {
            if (!BlurEnabled)
            {
                return;
            }

            var backgroundRenderTarget = new RenderTargetBitmap((int)ItemPanel.RenderSize.Width, (int)ItemPanel.RenderSize.Height, 96, 96, PixelFormats.Pbgra32);

            backgroundRenderTarget.Render(backgroundVisual);
            backgroundRenderTarget.Freeze();

            var itemPanelLocation = ItemPanel.PointToScreen(new Point(0, 0));
            var offset            = PointFromScreen(itemPanelLocation);

            var blurRegion = BuildRegionFromBitmap(backgroundRenderTarget, offset);
            var handle     = new WindowInteropHelper(this).Handle;

            var blurBehind = new Api.DWM_BLURBEHIND
            {
                fEnable = true,
                fTransitionOnMaximized = true,
                dwFlags  = Api.DWM_BB.BlurRegion | Api.DWM_BB.Enable | Api.DWM_BB.TransitionMaximized,
                hRgnBlur = blurRegion.GetHrgn(System.Drawing.Graphics.FromHwnd(handle))
            };

            Api.DwmEnableBlurBehindWindow(handle, ref blurBehind);
        }