protected void RefreshMonitorDpi() {
RescaleIfNeeded();
if (!_isPerMonitorDpiAware) {
return;
}
// get the current DPI of the monitor of the window
var monitor = NativeMethods.MonitorFromWindow(_source.Handle, NativeMethods.MONITOR_DEFAULTTONEAREST);
uint xDpi = 96;
uint yDpi = 96;
if (NativeMethods.GetDpiForMonitor(monitor, (int)MonitorDpiType.EffectiveDpi, ref xDpi, ref yDpi) != NativeMethods.S_OK) {
xDpi = 96;
yDpi = 96;
}
// vector contains the change of the old to new DPI
var dpiVector = DpiInformation.UpdateMonitorDpi(xDpi, yDpi);
// update Width and Height based on the current DPI of the monitor
UpdateWindowSize(Width * dpiVector.X, Height * dpiVector.Y);
// update graphics and text based on the current DPI of the monitor
UpdateLayoutTransform();
}