Пример #1
0
        /// <summary>
        /// Initializes the WindowChromeBehavior which is needed to render the custom WindowChrome.
        /// </summary>
        private void InitializeGlowWindowBehavior()
        {
            var behavior = new GlowWindowBehavior();

            BindingOperations.SetBinding(behavior, GlowWindowBehavior.GlowDepthProperty, new Binding {
                Path = new PropertyPath(GlowDepthProperty), Source = this
            });
            BindingOperations.SetBinding(behavior, GlowWindowBehavior.GlowColorProperty, new Binding {
                Path = new PropertyPath(GlowColorProperty), Source = this
            });
            BindingOperations.SetBinding(behavior, GlowWindowBehavior.NonActiveGlowColorProperty, new Binding {
                Path = new PropertyPath(NonActiveGlowColorProperty), Source = this
            });
            BindingOperations.SetBinding(behavior, GlowWindowBehavior.UseRadialGradientForCornersProperty, new Binding {
                Path = new PropertyPath(UseRadialGradientForCornersProperty), Source = this
            });
            BindingOperations.SetBinding(behavior, GlowWindowBehavior.IsGlowTransitionEnabledProperty, new Binding {
                Path = new PropertyPath(IsGlowTransitionEnabledProperty), Source = this
            });
            BindingOperations.SetBinding(behavior, GlowWindowBehavior.PreferDWMBorderColorProperty, new Binding {
                Path = new PropertyPath(PreferDWMBorderColorProperty), Source = this
            });

            this.SetBinding(DWMSupportsBorderColorProperty, new Binding {
                Path = new PropertyPath(GlowWindowBehavior.DWMSupportsBorderColorProperty), Source = behavior
            });

            Interaction.GetBehaviors(this).Add(behavior);
        }
Пример #2
0
        /// <summary>
        /// Initializes the WindowChromeBehavior which is needed to render the custom WindowChrome.
        /// </summary>
        private void InitializeGlowWindowBehavior()
        {
            var behavior = new GlowWindowBehavior();

            BindingOperations.SetBinding(behavior, GlowWindowBehavior.ResizeBorderThicknessProperty, new Binding {
                Path = new PropertyPath(ResizeBorderThicknessProperty), Source = this
            });
            BindingOperations.SetBinding(behavior, GlowWindowBehavior.GlowBrushProperty, new Binding {
                Path = new PropertyPath(GlowBrushProperty), Source = this
            });
            BindingOperations.SetBinding(behavior, GlowWindowBehavior.NonActiveGlowBrushProperty, new Binding {
                Path = new PropertyPath(NonActiveGlowBrushProperty), Source = this
            });

            Interaction.GetBehaviors(this).Add(behavior);
        }
Пример #3
0
        private static Window SetupExternalDialogWindow(BaseMetroDialog dialog)
        {
            var win = new MetroWindow
            {
                ShowInTaskbar            = false,
                ShowActivated            = true,
                Topmost                  = true,
                ResizeMode               = ResizeMode.NoResize,
                WindowStyle              = WindowStyle.None,
                WindowStartupLocation    = WindowStartupLocation.CenterScreen,
                ShowTitleBar             = false,
                ShowCloseButton          = false,
                WindowTransitionsEnabled = false,
                Background               = dialog.Background
            };

            try
            {
                win.GlowBrush = win.TryFindResource("AccentColorBrush") as SolidColorBrush;
            }
            catch (Exception) { }

            win.Width         = SystemParameters.PrimaryScreenWidth;
            win.MinHeight     = SystemParameters.PrimaryScreenHeight / 4.0;
            win.SizeToContent = SizeToContent.Height;

            var glowWindow = new GlowWindowBehavior();

            glowWindow.Attach(win);

            dialog.ParentDialogWindow = win; //THIS IS ONLY, I REPEAT, ONLY SET FOR EXTERNAL DIALOGS!

            win.Content = dialog;

            EventHandler closedHandler = null;

            closedHandler = (sender, args) =>
            {
                win.Closed -= closedHandler;
                dialog.ParentDialogWindow = null;
                win.Content = null;
            };
            win.Closed += closedHandler;

            return(win);
        }
Пример #4
0
        public GlowWindow(Window owner, GlowWindowBehavior behavior, GlowDirection direction)
        {
            InitializeComponent();

            Title = $"GlowWindow_{direction}";
            Name  = Title;

            // We have to set the owner to fix #92
            Owner      = owner ?? throw new ArgumentNullException(nameof(owner));
            this.owner = owner;

            IsGlowing = true;
            Closing  += (sender, e) => e.Cancel = !closing;

            glow.Direction = direction;

            {
                var b = new Binding
                {
                    Path   = new PropertyPath(nameof(ActualWidth)),
                    Source = this,
                    Mode   = BindingMode.OneWay
                };
                glow.SetBinding(WidthProperty, b);
            }

            {
                var b = new Binding
                {
                    Path   = new PropertyPath(nameof(ActualHeight)),
                    Source = this,
                    Mode   = BindingMode.OneWay
                };
                glow.SetBinding(HeightProperty, b);
            }

            {
                var b = new Binding
                {
                    Path   = new PropertyPath(GlowWindowBehavior.GlowBrushProperty),
                    Source = behavior,
                    Mode   = BindingMode.OneWay
                };
                glow.SetBinding(Glow.GlowBrushProperty, b);
            }

            {
                var b = new Binding
                {
                    Path   = new PropertyPath(GlowWindowBehavior.NonActiveGlowBrushProperty),
                    Source = behavior,
                    Mode   = BindingMode.OneWay
                };
                glow.SetBinding(Glow.NonActiveGlowBrushProperty, b);
            }

            {
                var b = new Binding
                {
                    Path   = new PropertyPath(BorderThicknessProperty),
                    Source = owner,
                    Mode   = BindingMode.OneWay
                };
                glow.SetBinding(BorderThicknessProperty, b);
            }

            {
                var b = new Binding
                {
                    Path   = new PropertyPath(GlowWindowBehavior.ResizeBorderThicknessProperty),
                    Source = behavior
                };
                SetBinding(ResizeBorderThicknessProperty, b);
            }

            switch (direction)
            {
            case GlowDirection.Left:
                glow.HorizontalAlignment = HorizontalAlignment.Right;
                getLeft         = rect => rect.Left - ResizeBorderThickness.Left + 1;
                getTop          = rect => rect.Top - (ResizeBorderThickness.Top / 2);
                getWidth        = rect => ResizeBorderThickness.Left;
                getHeight       = rect => rect.Height + ResizeBorderThickness.Top;
                getHitTestValue = (p, rect) => new Rect(0, 0, rect.Width, ResizeBorderThickness.Top * 2).Contains(p)
                        ? HT.TOPLEFT
                        : new Rect(0, rect.Height - ResizeBorderThickness.Bottom, rect.Width, ResizeBorderThickness.Bottom * 2).Contains(p)
                            ? HT.BOTTOMLEFT
                            : HT.LEFT;
                break;

            case GlowDirection.Right:
                glow.HorizontalAlignment = HorizontalAlignment.Left;
                getLeft         = rect => rect.Right - 1;
                getTop          = rect => rect.Top - (ResizeBorderThickness.Top / 2);
                getWidth        = rect => ResizeBorderThickness.Right;
                getHeight       = rect => rect.Height + ResizeBorderThickness.Top;
                getHitTestValue = (p, rect) => new Rect(0, 0, rect.Width, ResizeBorderThickness.Top * 2).Contains(p)
                        ? HT.TOPRIGHT
                        : new Rect(0, rect.Height - ResizeBorderThickness.Bottom, rect.Width, ResizeBorderThickness.Bottom * 2).Contains(p)
                            ? HT.BOTTOMRIGHT
                            : HT.RIGHT;
                break;

            case GlowDirection.Top:
                glow.VerticalAlignment = VerticalAlignment.Bottom;
                getLeft         = rect => rect.Left - (ResizeBorderThickness.Left / 2);
                getTop          = rect => rect.Top - ResizeBorderThickness.Top + 1;
                getWidth        = rect => rect.Width + ResizeBorderThickness.Left;
                getHeight       = rect => ResizeBorderThickness.Top;
                getHitTestValue = (p, rect) => new Rect(0, 0, ResizeBorderThickness.Left * 2, rect.Height).Contains(p)
                        ? HT.TOPLEFT
                        : new Rect(rect.Width - ResizeBorderThickness.Right, 0, ResizeBorderThickness.Right * 2, rect.Height).Contains(p)
                            ? HT.TOPRIGHT
                            : HT.TOP;
                break;

            case GlowDirection.Bottom:
                glow.VerticalAlignment = VerticalAlignment.Top;
                getLeft         = rect => rect.Left - (ResizeBorderThickness.Left / 2);
                getTop          = rect => rect.Bottom - 1;
                getWidth        = rect => rect.Width + ResizeBorderThickness.Left;
                getHeight       = rect => ResizeBorderThickness.Bottom;
                getHitTestValue = (p, rect) => new Rect(0, 0, ResizeBorderThickness.Left * 2, rect.Height).Contains(p)
                        ? HT.BOTTOMLEFT
                        : new Rect(rect.Width - ResizeBorderThickness.Right, 0, ResizeBorderThickness.Right * 2, rect.Height).Contains(p)
                            ? HT.BOTTOMRIGHT
                            : HT.BOTTOM;
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(direction), direction, "Invalid direction.");
            }

            owner.Activated        += OnOwnerActivated;
            owner.Deactivated      += OnOwnerDeactivated;
            owner.IsVisibleChanged += OnOwnerIsVisibleChanged;
            owner.Closed           += (sender, e) => InternalClose();
        }
Пример #5
0
        private static Window SetupExternalDialogWindow(BaseMetroDialog dialog)
        {
            MetroWindow win = new MetroWindow();
            win.ShowInTaskbar = false;
            win.ShowActivated = true;
            win.Topmost = true;
            win.ResizeMode = ResizeMode.NoResize;
            win.WindowStyle = WindowStyle.None;
            win.WindowStartupLocation = WindowStartupLocation.CenterScreen;
            win.ShowTitleBar = false;
            win.ShowCloseButton = false;
            win.WindowTransitionsEnabled = false;
            win.Background = dialog.Background;

            try
            {
                win.GlowBrush = win.TryFindResource("AccentColorBrush") as SolidColorBrush;
            }
            catch (Exception) { }

            win.Width = SystemParameters.PrimaryScreenWidth;
            win.MinHeight = SystemParameters.PrimaryScreenHeight / 4.0;
            win.SizeToContent = SizeToContent.Height;

            GlowWindowBehavior glowWindow = new GlowWindowBehavior();
            glowWindow.Attach(win);

            dialog.ParentDialogWindow = win; //THIS IS ONLY, I REPEAT, ONLY SET FOR EXTERNAL DIALOGS!

            win.Content = dialog;

            EventHandler closedHandler = null;
            closedHandler = (sender, args) => 
            {
                win.Closed -= closedHandler;
                dialog.ParentDialogWindow = null;
                win.Content = null;
            };
            win.Closed += closedHandler;

            return win;
        }
Пример #6
0
        public GlowWindow(Window owner, GlowWindowBehavior behavior, GlowDirection direction)
        {
            this.InitializeComponent();

            this.Title = $"GlowWindow_{direction}";
            this.Name  = this.Title;

            this.Owner = owner;
            this.owner = owner;

            this.IsGlowing = true;
            this.Closing  += (sender, e) => e.Cancel = !this.closing;


            this.glow.Direction = direction;

            {
                var b = new Binding
                {
                    Path   = new PropertyPath(nameof(this.ActualWidth)),
                    Source = this,
                    Mode   = BindingMode.OneWay
                };
                this.glow.SetBinding(WidthProperty, b);
            }

            {
                var b = new Binding
                {
                    Path   = new PropertyPath(nameof(this.ActualHeight)),
                    Source = this,
                    Mode   = BindingMode.OneWay
                };
                this.glow.SetBinding(HeightProperty, b);
            }

            {
                var b = new Binding
                {
                    Path   = new PropertyPath(GlowWindowBehavior.GlowBrushProperty),
                    Source = behavior,
                    Mode   = BindingMode.OneWay
                };
                this.glow.SetBinding(Glow.GlowBrushProperty, b);
            }

            {
                var b = new Binding
                {
                    Path   = new PropertyPath(GlowWindowBehavior.NonActiveGlowBrushProperty),
                    Source = behavior,
                    Mode   = BindingMode.OneWay
                };
                this.glow.SetBinding(Glow.NonActiveGlowBrushProperty, b);
            }

            {
                var b = new Binding
                {
                    Path   = new PropertyPath(BorderThicknessProperty),
                    Source = owner,
                    Mode   = BindingMode.OneWay
                };
                this.glow.SetBinding(BorderThicknessProperty, b);
            }

            {
                var b = new Binding
                {
                    Path   = new PropertyPath(GlowWindowBehavior.ResizeBorderThicknessProperty),
                    Source = behavior
                };
                this.SetBinding(ResizeBorderThicknessProperty, b);
            }

            switch (direction)
            {
            case GlowDirection.Left:
                this.glow.Orientation         = Orientation.Vertical;
                this.glow.HorizontalAlignment = HorizontalAlignment.Right;
                this.getLeft         = rect => rect.Left - this.ResizeBorderThickness.Left + 1;
                this.getTop          = rect => rect.Top - this.ResizeBorderThickness.Top / 2;
                this.getWidth        = rect => this.ResizeBorderThickness.Left;
                this.getHeight       = rect => rect.Height + this.ResizeBorderThickness.Top;
                this.getHitTestValue = (p, rect) => new Rect(0, 0, rect.Width, this.ResizeBorderThickness.Top * 2).Contains(p)
                        ? HT.TOPLEFT
                        : new Rect(0, rect.Height - this.ResizeBorderThickness.Bottom, rect.Width, this.ResizeBorderThickness.Bottom * 2).Contains(p)
                            ? HT.BOTTOMLEFT
                            : HT.LEFT;
                break;

            case GlowDirection.Right:
                this.glow.Orientation         = Orientation.Vertical;
                this.glow.HorizontalAlignment = HorizontalAlignment.Left;
                this.getLeft         = rect => rect.Right - 1;
                this.getTop          = rect => rect.Top - this.ResizeBorderThickness.Top / 2;
                this.getWidth        = rect => this.ResizeBorderThickness.Right;
                this.getHeight       = rect => rect.Height + this.ResizeBorderThickness.Top;
                this.getHitTestValue = (p, rect) => new Rect(0, 0, rect.Width, this.ResizeBorderThickness.Top * 2).Contains(p)
                        ? HT.TOPRIGHT
                        : new Rect(0, rect.Height - this.ResizeBorderThickness.Bottom, rect.Width, this.ResizeBorderThickness.Bottom * 2).Contains(p)
                            ? HT.BOTTOMRIGHT
                            : HT.RIGHT;
                break;

            case GlowDirection.Top:
                this.PreviewMouseDoubleClick += (sender, e) =>
                {
                    if (this.IsOwnerHandleValid())
                    {
                        NativeMethods.SendMessage(this.ownerWindowHandle, WM.NCLBUTTONDBLCLK, (IntPtr)HT.TOP, IntPtr.Zero);
                    }
                };
                this.glow.Orientation       = Orientation.Horizontal;
                this.glow.VerticalAlignment = VerticalAlignment.Bottom;
                this.getLeft         = rect => rect.Left - this.ResizeBorderThickness.Left / 2;
                this.getTop          = rect => rect.Top - this.ResizeBorderThickness.Top + 1;
                this.getWidth        = rect => rect.Width + this.ResizeBorderThickness.Left;
                this.getHeight       = rect => this.ResizeBorderThickness.Top;
                this.getHitTestValue = (p, rect) => new Rect(0, 0, this.ResizeBorderThickness.Left * 2, rect.Height).Contains(p)
                        ? HT.TOPLEFT
                        : new Rect(rect.Width - this.ResizeBorderThickness.Right, 0, this.ResizeBorderThickness.Right * 2, rect.Height).Contains(p)
                            ? HT.TOPRIGHT
                            : HT.TOP;
                break;

            case GlowDirection.Bottom:
                this.PreviewMouseDoubleClick += (sender, e) =>
                {
                    if (this.IsOwnerHandleValid())
                    {
                        NativeMethods.SendMessage(this.ownerWindowHandle, WM.NCLBUTTONDBLCLK, (IntPtr)HT.BOTTOM, IntPtr.Zero);
                    }
                };
                this.glow.Orientation       = Orientation.Horizontal;
                this.glow.VerticalAlignment = VerticalAlignment.Top;
                this.getLeft         = rect => rect.Left - this.ResizeBorderThickness.Left / 2;
                this.getTop          = rect => rect.Bottom - 1;
                this.getWidth        = rect => rect.Width + this.ResizeBorderThickness.Left;
                this.getHeight       = rect => this.ResizeBorderThickness.Bottom;
                this.getHitTestValue = (p, rect) => new Rect(0, 0, this.ResizeBorderThickness.Left * 2, rect.Height).Contains(p)
                        ? HT.BOTTOMLEFT
                        : new Rect(rect.Width - this.ResizeBorderThickness.Right, 0, this.ResizeBorderThickness.Right * 2, rect.Height).Contains(p)
                            ? HT.BOTTOMRIGHT
                            : HT.BOTTOM;
                break;
            }

            owner.Activated += (sender, e) =>
            {
                this.Update();

                this.glow.IsGlow = true;
            };
            owner.Deactivated += (sender, e) =>
            {
                this.glow.IsGlow = false;
            };
            owner.IsVisibleChanged += (sender, e) => this.Update();
            owner.Closed           += (sender, e) => this.InternalClose();
        }
Пример #7
0
        public GlowWindow(Window owner, GlowWindowBehavior behavior, GlowDirection direction)
        {
            this.InitializeComponent();

            this.Title = $"GlowWindow_{direction}";
            this.Name  = this.Title;

            // We have to set the owner to fix #92
            this.Owner = owner;
            this.owner = owner;

            this.IsGlowing = true;
            this.Closing  += (sender, e) => e.Cancel = !this.closing;

            this.glow.Direction = direction;

            {
                var b = new Binding
                {
                    Path   = new PropertyPath(nameof(this.ActualWidth)),
                    Source = this,
                    Mode   = BindingMode.OneWay
                };
                this.glow.SetBinding(WidthProperty, b);
            }

            {
                var b = new Binding
                {
                    Path   = new PropertyPath(nameof(this.ActualHeight)),
                    Source = this,
                    Mode   = BindingMode.OneWay
                };
                this.glow.SetBinding(HeightProperty, b);
            }

            {
                var b = new Binding
                {
                    Path   = new PropertyPath(GlowWindowBehavior.GlowBrushProperty),
                    Source = behavior,
                    Mode   = BindingMode.OneWay
                };
                this.glow.SetBinding(Glow.GlowBrushProperty, b);
            }

            {
                var b = new Binding
                {
                    Path   = new PropertyPath(GlowWindowBehavior.NonActiveGlowBrushProperty),
                    Source = behavior,
                    Mode   = BindingMode.OneWay
                };
                this.glow.SetBinding(Glow.NonActiveGlowBrushProperty, b);
            }

            {
                var b = new Binding
                {
                    Path   = new PropertyPath(BorderThicknessProperty),
                    Source = owner,
                    Mode   = BindingMode.OneWay
                };
                this.glow.SetBinding(BorderThicknessProperty, b);
            }

            {
                var b = new Binding
                {
                    Path   = new PropertyPath(GlowWindowBehavior.ResizeBorderThicknessProperty),
                    Source = behavior
                };
                this.SetBinding(ResizeBorderThicknessProperty, b);
            }

            switch (direction)
            {
            case GlowDirection.Left:
                this.glow.HorizontalAlignment = HorizontalAlignment.Right;
                this.getLeft         = rect => rect.Left - this.ResizeBorderThickness.Left + 1;
                this.getTop          = rect => rect.Top - this.ResizeBorderThickness.Top / 2;
                this.getWidth        = rect => this.ResizeBorderThickness.Left;
                this.getHeight       = rect => rect.Height + this.ResizeBorderThickness.Top;
                this.getHitTestValue = (p, rect) => new Rect(0, 0, rect.Width, this.ResizeBorderThickness.Top * 2).Contains(p)
                        ? HT.TOPLEFT
                        : new Rect(0, rect.Height - this.ResizeBorderThickness.Bottom, rect.Width, this.ResizeBorderThickness.Bottom * 2).Contains(p)
                            ? HT.BOTTOMLEFT
                            : HT.LEFT;
                break;

            case GlowDirection.Right:
                this.glow.HorizontalAlignment = HorizontalAlignment.Left;
                this.getLeft         = rect => rect.Right - 1;
                this.getTop          = rect => rect.Top - this.ResizeBorderThickness.Top / 2;
                this.getWidth        = rect => this.ResizeBorderThickness.Right;
                this.getHeight       = rect => rect.Height + this.ResizeBorderThickness.Top;
                this.getHitTestValue = (p, rect) => new Rect(0, 0, rect.Width, this.ResizeBorderThickness.Top * 2).Contains(p)
                        ? HT.TOPRIGHT
                        : new Rect(0, rect.Height - this.ResizeBorderThickness.Bottom, rect.Width, this.ResizeBorderThickness.Bottom * 2).Contains(p)
                            ? HT.BOTTOMRIGHT
                            : HT.RIGHT;
                break;

            case GlowDirection.Top:
                this.glow.VerticalAlignment = VerticalAlignment.Bottom;
                this.getLeft         = rect => rect.Left - this.ResizeBorderThickness.Left / 2;
                this.getTop          = rect => rect.Top - this.ResizeBorderThickness.Top + 1;
                this.getWidth        = rect => rect.Width + this.ResizeBorderThickness.Left;
                this.getHeight       = rect => this.ResizeBorderThickness.Top;
                this.getHitTestValue = (p, rect) => new Rect(0, 0, this.ResizeBorderThickness.Left * 2, rect.Height).Contains(p)
                        ? HT.TOPLEFT
                        : new Rect(rect.Width - this.ResizeBorderThickness.Right, 0, this.ResizeBorderThickness.Right * 2, rect.Height).Contains(p)
                            ? HT.TOPRIGHT
                            : HT.TOP;
                break;

            case GlowDirection.Bottom:
                this.glow.VerticalAlignment = VerticalAlignment.Top;
                this.getLeft         = rect => rect.Left - this.ResizeBorderThickness.Left / 2;
                this.getTop          = rect => rect.Bottom - 1;
                this.getWidth        = rect => rect.Width + this.ResizeBorderThickness.Left;
                this.getHeight       = rect => this.ResizeBorderThickness.Bottom;
                this.getHitTestValue = (p, rect) => new Rect(0, 0, this.ResizeBorderThickness.Left * 2, rect.Height).Contains(p)
                        ? HT.BOTTOMLEFT
                        : new Rect(rect.Width - this.ResizeBorderThickness.Right, 0, this.ResizeBorderThickness.Right * 2, rect.Height).Contains(p)
                            ? HT.BOTTOMRIGHT
                            : HT.BOTTOM;
                break;
            }

            owner.Activated        += OnOwnerActivated;
            owner.Deactivated      += OnOwnerDeactivated;
            owner.IsVisibleChanged += OnOwnerIsVisibleChanged;
            owner.Closed           += (sender, e) => this.InternalClose();
        }