Exemplo n.º 1
0
        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);
            }
        }
Exemplo n.º 2
0
 public bool Equals(Dpi other)
 {
     return this.X == other.X && this.Y == other.Y;
 }
Exemplo n.º 3
0
        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;
        }