From e1ed5ee76a6dcfb3c13d7c2f3110fa533475b151 Mon Sep 17 00:00:00 2001 From: Alex Maitland Date: Thu, 9 Feb 2023 11:59:41 +1000 Subject: [PATCH] WPF - Allow ToolTip timer configuration - Can set initial show delay in xaml via existing ToolTipService e.g. ToolTipService.InitialShowDelay="100" - If InitialShowDelay = 0 then no timer is used and ToolTip is immediately shown - Previous delay was 500ms, new delay is the .Net default (typically 1000ms) Related to issue #4048 --- CefSharp.Wpf/ChromiumWebBrowser.cs | 32 ++++++++++++++++++------------ 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/CefSharp.Wpf/ChromiumWebBrowser.cs b/CefSharp.Wpf/ChromiumWebBrowser.cs index b7a2f8cd00..32894cafc7 100644 --- a/CefSharp.Wpf/ChromiumWebBrowser.cs +++ b/CefSharp.Wpf/ChromiumWebBrowser.cs @@ -1603,16 +1603,18 @@ private static void OnTooltipTextChanged(DependencyObject d, DependencyPropertyC /// new value protected virtual void OnTooltipTextChanged(string oldValue, string newValue) { - var timer = tooltipTimer; - if (timer == null) + // There are cases where oldValue is null and newValue is string.Empty + // and vice versa, simply ignore when string.IsNullOrEmpty for both. + if (string.IsNullOrEmpty(oldValue) && string.IsNullOrEmpty(newValue)) { return; } - // There are cases where oldValue is null and newValue is string.Empty - // and vice versa, simply ignore when string.IsNullOrEmpty for both. - if (string.IsNullOrEmpty(oldValue) && string.IsNullOrEmpty(newValue)) + var timer = tooltipTimer; + if (timer == null) { + OpenOrCloseToolTip(newValue); + return; } @@ -2056,14 +2058,18 @@ private void OnIsVisibleChanged(object sender, DependencyPropertyChangedEventArg /// The instance containing the event data. private void OnLoaded(object sender, RoutedEventArgs routedEventArgs) { - // TODO: Consider making the delay here configurable. - tooltipTimer = new DispatcherTimer( - TimeSpan.FromSeconds(0.5), - DispatcherPriority.Render, - OnTooltipTimerTick, - Dispatcher - ); - tooltipTimer.IsEnabled = false; + var initialShowDelay = ToolTipService.GetInitialShowDelay(this); + + if (initialShowDelay > 0) + { + tooltipTimer = new DispatcherTimer( + TimeSpan.FromMilliseconds(initialShowDelay), + DispatcherPriority.Render, + OnTooltipTimerTick, + Dispatcher + ); + tooltipTimer.IsEnabled = false; + } //Initial value for screen location browserScreenLocation = GetBrowserScreenLocation();