diff --git a/src/Avalonia.Controls/ToolTip.cs b/src/Avalonia.Controls/ToolTip.cs
index 2f11746891..b458b15c64 100644
--- a/src/Avalonia.Controls/ToolTip.cs
+++ b/src/Avalonia.Controls/ToolTip.cs
@@ -204,13 +204,15 @@ namespace Avalonia.Controls
private static void IsOpenChanged(AvaloniaPropertyChangedEventArgs e)
{
var control = (Control)e.Sender;
+ var newValue = (bool)e.NewValue;
+ ToolTip toolTip;
- if ((bool)e.NewValue)
+ if (newValue)
{
var tip = GetTip(control);
if (tip == null) return;
- var toolTip = control.GetValue(ToolTipProperty);
+ toolTip = control.GetValue(ToolTipProperty);
if (toolTip == null || (tip != toolTip && tip != toolTip.Content))
{
toolTip?.Close();
@@ -223,9 +225,11 @@ namespace Avalonia.Controls
}
else
{
- var toolTip = control.GetValue(ToolTipProperty);
+ toolTip = control.GetValue(ToolTipProperty);
toolTip?.Close();
}
+
+ toolTip?.UpdatePseudoClasses(newValue);
}
private void Open(Control control)
@@ -238,6 +242,9 @@ namespace Avalonia.Controls
_popup.ConfigurePosition(control, GetPlacement(control),
new Point(GetHorizontalOffset(control), GetVerticalOffset(control)));
+
+ WindowManagerAddShadowHintChanged(_popup, false);
+
_popup.Show();
}
@@ -250,5 +257,18 @@ namespace Avalonia.Controls
_popup = null;
}
}
+
+ private void WindowManagerAddShadowHintChanged(IPopupHost host, bool hint)
+ {
+ if (host is PopupRoot pr)
+ {
+ pr.PlatformImpl.SetWindowManagerAddShadowHint(hint);
+ }
+ }
+
+ private void UpdatePseudoClasses(bool newValue)
+ {
+ PseudoClasses.Set(":open", newValue);
+ }
}
}
diff --git a/src/Avalonia.Themes.Fluent/Accents/FluentBaseDark.xaml b/src/Avalonia.Themes.Fluent/Accents/FluentBaseDark.xaml
index 7a715bbde7..a9369c569f 100644
--- a/src/Avalonia.Themes.Fluent/Accents/FluentBaseDark.xaml
+++ b/src/Avalonia.Themes.Fluent/Accents/FluentBaseDark.xaml
@@ -312,5 +312,15 @@
+
+
+ 12
+ 1
+
+
+
+
+
+
diff --git a/src/Avalonia.Themes.Fluent/Accents/FluentBaseLight.xaml b/src/Avalonia.Themes.Fluent/Accents/FluentBaseLight.xaml
index 5c6286a0bc..731ac1d0c7 100644
--- a/src/Avalonia.Themes.Fluent/Accents/FluentBaseLight.xaml
+++ b/src/Avalonia.Themes.Fluent/Accents/FluentBaseLight.xaml
@@ -313,5 +313,15 @@
+
+
+ 12
+ 1
+
+
+
+
+
+
diff --git a/src/Avalonia.Themes.Fluent/Accents/FluentControlResourcesDark.xaml b/src/Avalonia.Themes.Fluent/Accents/FluentControlResourcesDark.xaml
index 7364c339f1..d076df4cc9 100644
--- a/src/Avalonia.Themes.Fluent/Accents/FluentControlResourcesDark.xaml
+++ b/src/Avalonia.Themes.Fluent/Accents/FluentControlResourcesDark.xaml
@@ -343,5 +343,16 @@
+
+
+ 12
+ 1
+
+
+
+
+
+
+ 8,5,8,7
diff --git a/src/Avalonia.Themes.Fluent/Accents/FluentControlResourcesLight.xaml b/src/Avalonia.Themes.Fluent/Accents/FluentControlResourcesLight.xaml
index 15e157f573..430e9f61cf 100644
--- a/src/Avalonia.Themes.Fluent/Accents/FluentControlResourcesLight.xaml
+++ b/src/Avalonia.Themes.Fluent/Accents/FluentControlResourcesLight.xaml
@@ -343,5 +343,16 @@
+
+
+ 12
+ 1
+
+
+
+
+
+
+ 8,5,8,7
diff --git a/src/Avalonia.Themes.Fluent/ToolTip.xaml b/src/Avalonia.Themes.Fluent/ToolTip.xaml
index 1fc0202dd3..cf6f32f9bc 100644
--- a/src/Avalonia.Themes.Fluent/ToolTip.xaml
+++ b/src/Avalonia.Themes.Fluent/ToolTip.xaml
@@ -1,17 +1,78 @@
-
\ No newline at end of file
+
+
+
+
+ Hover Here
+
+
+
+
+
+ ToolTip
+ A control which pops up a hint when a control is hovered
+
+
+ ToolTip bottom placement
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/tests/Avalonia.Controls.UnitTests/ToolTipTests.cs b/tests/Avalonia.Controls.UnitTests/ToolTipTests.cs
index dc5b574db7..34b37e7635 100644
--- a/tests/Avalonia.Controls.UnitTests/ToolTipTests.cs
+++ b/tests/Avalonia.Controls.UnitTests/ToolTipTests.cs
@@ -102,5 +102,76 @@ namespace Avalonia.Controls.UnitTests
Assert.True(ToolTip.GetIsOpen(target));
}
}
+
+ [Fact]
+ public void Open_Class_Should_Not_Initially_Be_Added()
+ {
+ using (UnitTestApplication.Start(TestServices.StyledWindow))
+ {
+ var toolTip = new ToolTip();
+ var window = new Window();
+
+ var decorator = new Decorator()
+ {
+ [ToolTip.TipProperty] = toolTip
+ };
+
+ window.Content = decorator;
+
+ window.ApplyTemplate();
+ window.Presenter.ApplyTemplate();
+
+ Assert.Empty(toolTip.Classes);
+ }
+ }
+
+ [Fact]
+ public void Setting_IsOpen_Should_Add_Open_Class()
+ {
+ using (UnitTestApplication.Start(TestServices.StyledWindow))
+ {
+ var toolTip = new ToolTip();
+ var window = new Window();
+
+ var decorator = new Decorator()
+ {
+ [ToolTip.TipProperty] = toolTip
+ };
+
+ window.Content = decorator;
+
+ window.ApplyTemplate();
+ window.Presenter.ApplyTemplate();
+
+ ToolTip.SetIsOpen(decorator, true);
+
+ Assert.Equal(new[] { ":open" }, toolTip.Classes);
+ }
+ }
+
+ [Fact]
+ public void Clearing_IsOpen_Should_Remove_Open_Class()
+ {
+ using (UnitTestApplication.Start(TestServices.StyledWindow))
+ {
+ var toolTip = new ToolTip();
+ var window = new Window();
+
+ var decorator = new Decorator()
+ {
+ [ToolTip.TipProperty] = toolTip
+ };
+
+ window.Content = decorator;
+
+ window.ApplyTemplate();
+ window.Presenter.ApplyTemplate();
+
+ ToolTip.SetIsOpen(decorator, true);
+ ToolTip.SetIsOpen(decorator, false);
+
+ Assert.Empty(toolTip.Classes);
+ }
+ }
}
}