Пример #1
0
        public static double ConvertSizeRectDpiToSystemDpi(Rect rect, double size)
        {
            Dpi systemDpi = GetSystemDpi();
            Dpi rectDpi   = DpiChecker.GetDpiFromRect(rect);

            return(size * systemDpi.X / rectDpi.X);
        }
Пример #2
0
        /// <summary>
        /// Gets a ScaleTransform used to manually scale elements to be the correct size on monitors with non-system DPI. The Rect passed in is used to find the monitor DPI that the rect is on. The Rect should be the WPF System-DPI coordinates.
        /// </summary>
        /// <param name="rect">WPF System-DPI coordinates</param>
        /// <returns>ScaleTransform with a scale factor that is Monitor DPI / System DPI</returns>
        public static ScaleTransform GetScaleTransformForRect(Rect rect)
        {
            double         monitorScaleFactorX = (double)DpiChecker.GetDpiFromRect(rect).X / (double)DpiUtil.GetSystemDpi().X;
            double         monitorScaleFactorY = (double)DpiChecker.GetDpiFromRect(rect).Y / (double)DpiUtil.GetSystemDpi().Y;
            ScaleTransform scaleTransform      = new ScaleTransform(monitorScaleFactorX, monitorScaleFactorY);

            return(scaleTransform);
        }
        protected override void OnSourceInitialized(EventArgs e)
        {
            base.OnSourceInitialized(e);

            new WindowPlacement().Load(this);

            var notificationAreaDpi = DpiChecker.GetNotificationAreaDpi();

            _component = new NotifyIconComponent(this);
            _component.ShowIcon("pack://application:,,,/Resources/ring.ico", ProductTitle, notificationAreaDpi.X);
        }
Пример #4
0
        protected override void OnSourceInitialized(EventArgs e)
        {
            base.OnSourceInitialized(e);

            _onContentMouseLeftDown          = (_sender, _e) => _e.Handled = true;
            ContentRoot.MouseLeftButtonDown += _onContentMouseLeftDown;

            _onDpiChanged             = (_sender, _e) => SystemSounds.Hand.Play();
            WindowHandler.DpiChanged += _onDpiChanged;

            _onColorProfileChanged = (_sender, _e) =>
            {
                ColorProfilePath = _e.NewPath;
                SystemSounds.Exclamation.Play();
            };
            WindowHandler.ColorProfileChanged += _onColorProfileChanged;

            PrepareAnimation();

            Debug.WriteLine($"Notification Area DPI: {DpiChecker.GetNotificationAreaDpi()}");
        }
Пример #5
0
        public static double GetAbsoluteScaleFactorFromRect(Rect rect)
        {
            double scaleFactor = (double)DpiChecker.GetDpiFromRect(rect).X / (double)Dpi.Default.X;

            return(scaleFactor);
        }