protected override void OnSourceInitialized(EventArgs e)
        {
            base.OnSourceInitialized(e);
            if (!PerMonitorDpiService.IsSupported) return;

            this.systemDpi = this.GetSystemDpi();

            this.source = PresentationSource.FromVisual(this) as HwndSource;
            if (this.source != null)
            {
                this.currentDpi = this.source.GetDpi();
                this.ChangeDpi(this.currentDpi);
                this.source.AddHook(this.WndProc);
            }
        }
Example #2
0
 public bool Equals(Dpi other)
 {
     return this.X == other.X && this.Y == other.Y;
 }
        private void ChangeDpi(Dpi dpi)
        {
            if (!PerMonitorDpiService.IsSupported) return;

            this.DpiScaleTransform = (dpi == this.systemDpi)
                ? Transform.Identity
                : new ScaleTransform((double)dpi.X / this.systemDpi.X, (double)dpi.Y / this.systemDpi.Y);

            this.Width = this.Width * dpi.X / this.currentDpi.X;
            this.Height = this.Height * dpi.Y / this.currentDpi.Y;

            this.currentDpi = dpi;
        }