Пример #1
0
        public void FromRect_Vector_Snaps_To_Device_Pixels()
        {
            var rect   = new Rect(189, 189, 26, 164);
            var result = PixelRect.FromRect(rect, new Vector(1.5, 1.5));

            Assert.Equal(new PixelRect(283, 283, 40, 247), result);
        }
Пример #2
0
        /// <summary>
        /// Moves the Popups position so that it doesnt overlap screen edges.
        /// This method can be called immediately after Show has been called.
        /// </summary>
        public void SnapInsideScreenEdges()
        {
            var screen = Application.Current.MainWindow?.Screens.ScreenFromPoint(Position);

            if (screen != null)
            {
                var scaling = VisualRoot.RenderScaling;
                var bounds  = PixelRect.FromRect(Bounds, scaling);
                var screenX = Position.X + bounds.Width - screen.Bounds.X;
                var screenY = Position.Y + bounds.Height - screen.Bounds.Y;

                if (screenX > screen.Bounds.Width)
                {
                    Position = Position.WithX(Position.X - (screenX - screen.Bounds.Width));
                }

                if (screenY > screen.Bounds.Height)
                {
                    Position = Position.WithY(Position.Y - (screenY - screen.Bounds.Height));
                }
            }
        }