Browse Source
Merge pull request #5297 from AvaloniaUI/fix-tooltip-null-values
Close tooltip on null Tip value
pull/5414/head
Steven Kirk
6 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with
38 additions and
3 deletions
-
src/Avalonia.Controls/ToolTipService.cs
-
tests/Avalonia.Controls.UnitTests/ToolTipTests.cs
|
|
|
@ -38,9 +38,16 @@ namespace Avalonia.Controls |
|
|
|
|
|
|
|
if (ToolTip.GetIsOpen(control) && e.NewValue != e.OldValue && !(e.NewValue is ToolTip)) |
|
|
|
{ |
|
|
|
var tip = control.GetValue(ToolTip.ToolTipProperty); |
|
|
|
|
|
|
|
tip.Content = e.NewValue; |
|
|
|
if (e.NewValue is null) |
|
|
|
{ |
|
|
|
Close(control); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
var tip = control.GetValue(ToolTip.ToolTipProperty); |
|
|
|
|
|
|
|
tip.Content = e.NewValue; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -270,6 +270,34 @@ namespace Avalonia.Controls.UnitTests |
|
|
|
Assert.Empty(toolTip.Classes); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Should_Close_On_Null_Tip() |
|
|
|
{ |
|
|
|
using (UnitTestApplication.Start(TestServices.StyledWindow)) |
|
|
|
{ |
|
|
|
var window = new Window(); |
|
|
|
|
|
|
|
var target = new Decorator() |
|
|
|
{ |
|
|
|
[ToolTip.TipProperty] = "Tip", |
|
|
|
[ToolTip.ShowDelayProperty] = 0 |
|
|
|
}; |
|
|
|
|
|
|
|
window.Content = target; |
|
|
|
|
|
|
|
window.ApplyTemplate(); |
|
|
|
window.Presenter.ApplyTemplate(); |
|
|
|
|
|
|
|
_mouseHelper.Enter(target); |
|
|
|
|
|
|
|
Assert.True(ToolTip.GetIsOpen(target)); |
|
|
|
|
|
|
|
target[ToolTip.TipProperty] = null; |
|
|
|
|
|
|
|
Assert.False(ToolTip.GetIsOpen(target)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
internal class ToolTipViewModel |
|
|
|
|