示例#1
0
        internal static void StaticEnableBlur(System.Windows.Window win, uint accentColor = 0x00FFFFFF)
        {
            var windowHelper = new WindowInteropHelper(win);

            AcrylicHelper.EnableBlur(windowHelper.Handle, accentColor);

            win.CommandBindings.Add(new CommandBinding(SystemCommands.CloseWindowCommand,
                                                       (_, __) => { SystemCommands.CloseWindow(win); }));
            win.CommandBindings.Add(new CommandBinding(SystemCommands.MinimizeWindowCommand,
                                                       (_, __) => { SystemCommands.MinimizeWindow(win); }));
            win.CommandBindings.Add(new CommandBinding(SystemCommands.MaximizeWindowCommand,
                                                       (_, __) => { SystemCommands.MaximizeWindow(win); }));
            win.CommandBindings.Add(new CommandBinding(SystemCommands.RestoreWindowCommand,
                                                       (_, __) => { SystemCommands.RestoreWindow(win); }));

            void ContentRendered(object?sender, EventArgs e)
            {
                if (win.SizeToContent != SizeToContent.Manual)
                {
                    win.InvalidateMeasure();
                }

                win.ContentRendered -= ContentRendered;
            }

            win.ContentRendered += ContentRendered;
        }
示例#2
0
        internal static void EnableBlur(Window win)
        {
            var windowHelper = new WindowInteropHelper(win);

            // ウィンドウに半透明のアクリル効果を適用する
            AcrylicHelper.EnableBlur(windowHelper.Handle);

            // タイトルバーの各種ボタンで利用するコマンドの設定
            win.CommandBindings.Add(new CommandBinding(SystemCommands.CloseWindowCommand, (_, __) => { SystemCommands.CloseWindow(win); }));
            win.CommandBindings.Add(new CommandBinding(SystemCommands.MinimizeWindowCommand, (_, __) => { SystemCommands.MinimizeWindow(win); }));
            win.CommandBindings.Add(new CommandBinding(SystemCommands.MaximizeWindowCommand, (_, __) => { SystemCommands.MaximizeWindow(win); }));
            win.CommandBindings.Add(new CommandBinding(SystemCommands.RestoreWindowCommand, (_, __) => { SystemCommands.RestoreWindow(win); }));


            // WPFのSizeToContentのバグ対策
            // (WindowChrome使用時に、SizeToContentのウィンドウサイズ計算が正しく行われない)
            void onContentRendered(object sender, EventArgs e)
            {
                if (win.SizeToContent != SizeToContent.Manual)
                {
                    win.InvalidateMeasure();
                }

                win.ContentRendered -= onContentRendered;
            }

            win.ContentRendered += onContentRendered;
        }
示例#3
0
        protected override void OnOpened(RoutedEventArgs e)
        {
            base.OnOpened(e);
            var hwnd = (HwndSource)HwndSource.FromVisual(this);

            AcrylicHelper.EnableBlur(hwnd.Handle, AccentFlagsType.Popup);
        }
示例#4
0
        protected override void OnActivated(EventArgs e)
        {
            base.OnActivated(e);
            //Background = (SolidColorBrush)App.Current.Resources["BlurWindowBackgroundBrush"];
            var ptr = new WindowInteropHelper(this).Handle;

            AcrylicHelper.EnableBlur(ptr);
        }
示例#5
0
        protected override void OnOpened(EventArgs e)
        {
            base.OnOpened(e);

            var hwnd = (HwndSource)HwndSource.FromVisual(this.Child);

            AcrylicHelper.EnableBlur(hwnd.Handle);
        }
示例#6
0
        protected override void OnOpened(EventArgs e)
        {
            base.OnOpened(e);

            var accent      = (Color)GetValue(AcrylicElement.AccentColorProperty);
            var accentColor = (uint)(accent.A << 24 | accent.R << 18 | accent.G << 12 | accent.B);
            var hwnd        = ((HwndSource)PresentationSource.FromVisual(Child)) !;

            AcrylicHelper.EnableBlur(hwnd.Handle, accentColor, AccentFlagsType.Popup);
        }
示例#7
0
        internal static void EnableBlur(Window win)
        {
            var windowHelper = new WindowInteropHelper(win);

            // ウィンドウに半透明のアクリル効果を適用する
            AcrylicHelper.EnableBlur(windowHelper.Handle);

            // タイトルバーの各種ボタンで利用するコマンドの設定
            win.CommandBindings.Add(new CommandBinding(SystemCommands.CloseWindowCommand, (_, __) => { SystemCommands.CloseWindow(win); }));
            win.CommandBindings.Add(new CommandBinding(SystemCommands.MinimizeWindowCommand, (_, __) => { SystemCommands.MinimizeWindow(win); }));
            win.CommandBindings.Add(new CommandBinding(SystemCommands.MaximizeWindowCommand, (_, __) => { SystemCommands.MaximizeWindow(win); }));
            win.CommandBindings.Add(new CommandBinding(SystemCommands.RestoreWindowCommand, (_, __) => { SystemCommands.RestoreWindow(win); }));
        }
        internal static void EnableBlur(Window win)
        {
            var windowHelper = new WindowInteropHelper(win);

            AcrylicHelper.EnableBlur(windowHelper.Handle);

            // WPF WindowChrome bug with SizeToContent workaround
            void OnContentRendered(object sender, EventArgs e)
            {
                if (win.SizeToContent != SizeToContent.Manual)
                {
                    win.InvalidateMeasure();
                }

                win.ContentRendered -= OnContentRendered;
            }

            win.ContentRendered += OnContentRendered;
        }
示例#9
0
        private void BlurSubMenu()
        {
            var firstSubItem = ItemContainerGenerator.ContainerFromIndex(0);

            if (firstSubItem == null)
            {
                return;
            }

            var container = VisualTreeHelper.GetParent(firstSubItem) as Visual;

            if (container == null)
            {
                return;
            }

            DependencyObject parent = container;
            int borderIndex         = 0;

            while (parent != null)
            {
                if (parent is Border b)
                {
                    // only put color on the first border (transparent colors will add up otherwise)
                    if (borderIndex == 0)
                    {
                        b.Background = new SolidColorBrush(Color.FromArgb(80, 0, 0, 0));
                    }
                    else
                    {
                        b.Background = Brushes.Transparent;
                    }

                    borderIndex++;
                }

                parent = VisualTreeHelper.GetParent(parent);
            }

            AcrylicHelper.EnableBlur(container);
        }
 public void SetWindowBlur(IntPtr hWnd)
 {
     AcrylicHelper.EnableBlur(hWnd);
 }
示例#11
0
        protected override void OnOpened(RoutedEventArgs e)
        {
            base.OnOpened(e);

            AcrylicHelper.EnableBlur(this);
        }