protected override void OnSourceInitialized(EventArgs e) { base.OnSourceInitialized(e); this._source = PresentationSource.FromVisual(this) as HwndSource; if (this._source == null) return; this._systemDpi = this._source.GetSystemDpi(); this._isPerMonitorDpiSupported = PerMonitorDpiHelper.IsSupported; if (this._isPerMonitorDpiSupported) { this._currentDpi = this._source.GetMonitorDpi(); this.OnDpiChanged(this._currentDpi, new NativeRect()); this._source.AddHook(this.WindowProcedure); this._hooked = true; } else { this._currentDpi = this._systemDpi; } }
protected virtual void OnDpiChanged(Dpi suggestedDpi, NativeRect suggested) { this.DpiScaleTransform = (suggestedDpi == this._systemDpi) ? Transform.Identity : new ScaleTransform((double)suggestedDpi.X / this._systemDpi.X, (double)suggestedDpi.Y / this._systemDpi.Y); if (!this._borderClicked) { this.Width = this.Width * suggestedDpi.X / this._currentDpi.X; this.Height = this.Height * suggestedDpi.Y / this._currentDpi.Y; } this._currentDpi = suggestedDpi; }
public bool Equals(Dpi other) { return this.X == other.X && this.Y == other.Y; }