Пример #1
0
        protected override void OnMouseDown(MouseButtonEventArgs e)
        {
            if (e.ChangedButton == MouseButton.Left)
            {
                var window = Window.GetWindow(this);
                if (e.ClickCount == 1)
                {
                    if (!this._isSystemMenuOpened)
                    {
                        this._isSystemMenuOpened = true;

                        var point = this.PointToScreen(new Point(0, this.ActualHeight));
                        var dpi   = Dpi.FromVisual(window);
                        SystemCommands.ShowSystemMenu(window, dpi.PhysicalToLogical(point));
                    }
                    else
                    {
                        this._isSystemMenuOpened = false;
                    }
                }
                else if (e.ClickCount == 2)
                {
                    window.Close();
                }
            }
            else
            {
                base.OnMouseDown(e);
            }
        }
Пример #2
0
        protected override void OnMouseRightButtonUp(MouseButtonEventArgs e)
        {
            var window = Window.GetWindow(this);
            var point  = this.PointToScreen(e.GetPosition(this));
            var dpi    = Dpi.FromVisual(window);

            SystemCommands.ShowSystemMenu(window, dpi.PhysicalToLogical(point));
        }
Пример #3
0
        protected override void OnSourceInitialized(EventArgs e)
        {
            base.OnSourceInitialized(e);

            if (HasBuiltInScaling)
            {
                this.SystemDpi = Dpi.FromVisual(this);
            }
            else
            {
                this._source = (HwndSource)PresentationSource.FromVisual(this);
                if (this._source == null)
                {
                    return;
                }
                this._source.AddHook(this.WndProc);

                this.SystemDpi = Dpi.FromPresentationSource(this._source);
            }
            this.WindowDpi = this.SystemDpi;
        }