From da0dfc46cb27ddffddfc175aab29f7d82815c231 Mon Sep 17 00:00:00 2001 From: amaitland Date: Wed, 30 Oct 2019 13:25:51 +1000 Subject: [PATCH] WPF - Change NotifyDpiChange to accept float instead of double - Double was being cast to float - If newDpi is same as old DPI do nothing, no extra floating point comparison is being used, so in some cases it's possible the DPI change will be triggered when the DPI's are actually the same --- CefSharp.Wpf/ChromiumWebBrowser.cs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/CefSharp.Wpf/ChromiumWebBrowser.cs b/CefSharp.Wpf/ChromiumWebBrowser.cs index f263a1da9..433a24892 100644 --- a/CefSharp.Wpf/ChromiumWebBrowser.cs +++ b/CefSharp.Wpf/ChromiumWebBrowser.cs @@ -1684,7 +1684,7 @@ namespace CefSharp.Wpf var matrix = source.CompositionTarget.TransformToDevice; - NotifyDpiChange(matrix.M11); + NotifyDpiChange((float)matrix.M11); var window = source.RootVisual as Window; if (window != null) @@ -2431,11 +2431,17 @@ namespace CefSharp.Wpf /// new DPI /// .Net 4.6.2 adds HwndSource.DpiChanged which could be used to automatically /// handle DPI change, unforunately we still target .Net 4.5.2 - public virtual void NotifyDpiChange(double newDpi) + public virtual void NotifyDpiChange(float newDpi) { + //Do nothing + if (DpiScaleFactor.Equals(newDpi)) + { + return; + } + var notifyDpiChanged = DpiScaleFactor > 0 && !DpiScaleFactor.Equals(newDpi); - DpiScaleFactor = (float)newDpi; + DpiScaleFactor = newDpi; if (notifyDpiChanged && browser != null) {