Skip to content

Commit

Permalink
fix(ColorPicker): tooltip of ColorPickerSlider doesn't work properly
Browse files Browse the repository at this point in the history
  • Loading branch information
TopProgrammer77 committed Oct 12, 2023
1 parent 26b9e38 commit 9236f15
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -42,6 +42,7 @@ protected override void OnApplyTemplate()

if (m_toolTip is ToolTip toolTip)
{
_isCustomThumbToolTipEnabled = true;
toolTip.Content = GetToolTipString();
}
}
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/Uno.UI/UI/Xaml/Controls/Slider/Slider.mux.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/Uno.UI/UI/Xaml/Controls/Slider/Slider.mux.h.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,7 @@ public partial class Slider

private bool _disengagedWithA;

// This flag is used for the Thumb ToolTip of ColorPickerSlider
protected bool _isCustomThumbToolTipEnabled;

}
2 changes: 1 addition & 1 deletion src/Uno.UI/UI/Xaml/Controls/ToolTip/ToolTip.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 9236f15

Please sign in to comment.