Beispiel #1
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            if (_window == null || !_window.TryGetTarget(out var window))
            {
                return;
            }

            window.Loaded -= Window_Loaded;

            var windowHelper = new WindowInteropHelper(window);

            var accent           = new NativeMethods.AccentPolicy();
            var accentStructSize = Marshal.SizeOf(accent);

            accent.AccentState = _enable?NativeMethods.AccentState.ACCENT_ENABLE_BLURBEHIND:NativeMethods.AccentState.ACCENT_DISABLED; //NativeMethods.AccentState.ACCENT_ENABLE_BLURBEHIND;

            var accentPtr = Marshal.AllocHGlobal(accentStructSize);

            Marshal.StructureToPtr(accent, accentPtr, false);

            var data = new NativeMethods.WindowCompositionAttributeData
            {
                Attribute  = NativeMethods.WindowCompositionAttribute.WCA_ACCENT_POLICY,
                SizeOfData = accentStructSize,
                Data       = accentPtr
            };

            _ = NativeMethods.SetWindowCompositionAttribute(windowHelper.Handle, ref data);

            Marshal.FreeHGlobal(accentPtr);
            _window.SetTarget(null);
        }
Beispiel #2
0
        private void _window_Loaded(object sender, RoutedEventArgs e)
        {
            var windowHelper = new WindowInteropHelper(_window);

            var accent           = new NativeMethods.AccentPolicy();
            var accentStructSize = Marshal.SizeOf(accent);

            accent.AccentState = NativeMethods.AccentState.ACCENT_ENABLE_BLURBEHIND;

            var accentPtr = Marshal.AllocHGlobal(accentStructSize);

            Marshal.StructureToPtr(accent, accentPtr, false);

            var data = new NativeMethods.WindowCompositionAttributeData
            {
                Attribute  = NativeMethods.WindowCompositionAttribute.WCA_ACCENT_POLICY,
                SizeOfData = accentStructSize,
                Data       = accentPtr
            };

            NativeMethods.SetWindowCompositionAttribute(windowHelper.Handle, ref data);

            Marshal.FreeHGlobal(accentPtr);
        }