private void ChangeDpi(Dpi dpi) { this.window.DpiScaleTransform = (dpi == this.systemDpi) ? Transform.Identity : new ScaleTransform((double)dpi.X / this.systemDpi.X, (double)dpi.Y / this.systemDpi.Y); this.window.Width = this.window.Width * dpi.X / this.currentDpi.X; this.window.Height = this.window.Height * dpi.Y / this.currentDpi.Y; this.currentDpi = dpi; }
/// <summary> /// Called when <see cref="window"/> has been initialize /// </summary> public void WindowInitialized() { var hwndSource = PresentationSource.FromVisual(this.window) as HwndSource; if (hwndSource == null) return; this.windowSource = hwndSource; hwndSource.AddHook(this.HwndHook); this.systemDpi = this.GetSystemDpi(); this.isPerMonitorDpiSupported = PerMonitorDpi.IsSupported; if (this.isPerMonitorDpiSupported) { this.currentDpi = this.windowSource.GetMonitorDpi(); this.ChangeDpi(this.currentDpi); } else { this.currentDpi = this.systemDpi; } }
public bool Equals(Dpi other) { return this.X == other.X && this.Y == other.Y; }