From 9236f157129cfe84a5c88b6f404d67c65f7dcdcd Mon Sep 17 00:00:00 2001 From: TopProgrammer77 Date: Thu, 5 Oct 2023 15:22:40 -0400 Subject: [PATCH] fix(ColorPicker): tooltip of ColorPickerSlider doesn't work properly --- .../UI/Xaml/Controls/ColorPicker/ColorPickerSlider.cs | 10 ++++------ src/Uno.UI/UI/Xaml/Controls/Slider/Slider.mux.cs | 2 ++ src/Uno.UI/UI/Xaml/Controls/Slider/Slider.mux.h.cs | 3 +++ src/Uno.UI/UI/Xaml/Controls/ToolTip/ToolTip.cs | 2 +- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/Uno.UI/Microsoft/UI/Xaml/Controls/ColorPicker/ColorPickerSlider.cs b/src/Uno.UI/Microsoft/UI/Xaml/Controls/ColorPicker/ColorPickerSlider.cs index 5131e7642bf8..0c630f95969f 100644 --- a/src/Uno.UI/Microsoft/UI/Xaml/Controls/ColorPicker/ColorPickerSlider.cs +++ b/src/Uno.UI/Microsoft/UI/Xaml/Controls/ColorPicker/ColorPickerSlider.cs @@ -17,7 +17,7 @@ public partial class ColorPickerSlider : Slider { private ToolTip m_toolTip; - public ColorPickerSlider() + public ColorPickerSlider() : base() { // We want the ColorPickerSlider to pick up everything for its default style from the Slider's default style, // since its purpose is just to turn off keyboarding. So we'll give it Slider's control name as its default style key @@ -42,6 +42,7 @@ protected override void OnApplyTemplate() if (m_toolTip is ToolTip toolTip) { + _isCustomThumbToolTipEnabled = true; toolTip.Content = GetToolTipString(); } } @@ -172,11 +173,8 @@ private void OnValueChangedEvent(object sender, RangeBaseValueChangedEventArgs a if (m_toolTip is ToolTip toolTip) { toolTip.Content = GetToolTipString(); - - // ToolTip doesn't currently provide any way to re-run its placement logic if its placement target moves, - // so toggling IsEnabled induces it to do that without incurring any visual glitches. - toolTip.IsEnabled = false; - toolTip.IsEnabled = true; + if (Thumb.IsDragging) + UpdateThumbToolTipVisibility(true); } DependencyObject currentObject = this; diff --git a/src/Uno.UI/UI/Xaml/Controls/Slider/Slider.mux.cs b/src/Uno.UI/UI/Xaml/Controls/Slider/Slider.mux.cs index 52a89b178801..567a585b4474 100644 --- a/src/Uno.UI/UI/Xaml/Controls/Slider/Slider.mux.cs +++ b/src/Uno.UI/UI/Xaml/Controls/Slider/Slider.mux.cs @@ -41,6 +41,7 @@ public Slider() _usingDefaultToolTipForHorizontalThumb = false; _usingDefaultToolTipForVerticalThumb = false; _capturedPointerId = 0; + _isCustomThumbToolTipEnabled = false; // TODO Uno specific: This is called by DirectUI automatically, // we have to do it manually here. @@ -1073,6 +1074,7 @@ private void UpdateTrackLayout( actualHeight = Math.Max(actualHeight - padding.Top - padding.Bottom, 0.0); isThumbToolTipEnabled = IsThumbToolTipEnabled; + isThumbToolTipEnabled |= _isCustomThumbToolTipEnabled; #if HAS_UNO isThumbToolTipEnabled &= FeatureConfiguration.ToolTip.UseToolTips; #endif diff --git a/src/Uno.UI/UI/Xaml/Controls/Slider/Slider.mux.h.cs b/src/Uno.UI/UI/Xaml/Controls/Slider/Slider.mux.h.cs index ace39d830a34..f5f1ffa937fe 100644 --- a/src/Uno.UI/UI/Xaml/Controls/Slider/Slider.mux.h.cs +++ b/src/Uno.UI/UI/Xaml/Controls/Slider/Slider.mux.h.cs @@ -114,4 +114,7 @@ public partial class Slider private bool _disengagedWithA; + // This flag is used for the Thumb ToolTip of ColorPickerSlider + protected bool _isCustomThumbToolTipEnabled; + } diff --git a/src/Uno.UI/UI/Xaml/Controls/ToolTip/ToolTip.cs b/src/Uno.UI/UI/Xaml/Controls/ToolTip/ToolTip.cs index 82f84a332c49..6e212368a642 100644 --- a/src/Uno.UI/UI/Xaml/Controls/ToolTip/ToolTip.cs +++ b/src/Uno.UI/UI/Xaml/Controls/ToolTip/ToolTip.cs @@ -123,7 +123,7 @@ private Size GetTooltipSize() private void OnOpenChanged(bool isOpen) { PerformPlacementInternal(); - if (_owner is not null) + if (_owner is not null && Popup.XamlRoot is null) { XamlRoot = XamlRoot.GetForElement(_owner); Popup.XamlRoot = XamlRoot.GetForElement(_owner);