Browse Source
Merge pull request #4574 from AvaloniaUI/fixes/update-tooltip-content-when-already-opened
Fixes/update tooltip content when already opened
pull/4583/head
danwalmsley
6 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with
37 additions and
1 deletions
-
src/Avalonia.Controls/ToolTip.cs
-
src/Avalonia.Controls/ToolTipService.cs
-
tests/Avalonia.Controls.UnitTests/ToolTipTests.cs
|
|
|
@ -55,7 +55,7 @@ namespace Avalonia.Controls |
|
|
|
/// <summary>
|
|
|
|
/// Stores the current <see cref="ToolTip"/> instance in the control.
|
|
|
|
/// </summary>
|
|
|
|
private static readonly AttachedProperty<ToolTip> ToolTipProperty = |
|
|
|
internal static readonly AttachedProperty<ToolTip> ToolTipProperty = |
|
|
|
AvaloniaProperty.RegisterAttached<ToolTip, Control, ToolTip>("ToolTip"); |
|
|
|
|
|
|
|
private IPopupHost _popup; |
|
|
|
|
|
|
|
@ -35,6 +35,13 @@ namespace Avalonia.Controls |
|
|
|
control.PointerEnter += ControlPointerEnter; |
|
|
|
control.PointerLeave += ControlPointerLeave; |
|
|
|
} |
|
|
|
|
|
|
|
if (ToolTip.GetIsOpen(control) && e.NewValue != e.OldValue && !(e.NewValue is ToolTip)) |
|
|
|
{ |
|
|
|
var tip = control.GetValue(ToolTip.ToolTipProperty); |
|
|
|
|
|
|
|
tip.Content = e.NewValue; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
internal void TipOpenChanged(AvaloniaPropertyChangedEventArgs e) |
|
|
|
|
|
|
|
@ -124,6 +124,35 @@ namespace Avalonia.Controls.UnitTests |
|
|
|
Assert.True(ToolTip.GetIsOpen(target)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Content_Should_Update_When_Tip_Property_Changes_And_Already_Open() |
|
|
|
{ |
|
|
|
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)); |
|
|
|
Assert.Equal("Tip", target.GetValue(ToolTip.ToolTipProperty).Content); |
|
|
|
|
|
|
|
|
|
|
|
ToolTip.SetTip(target, "Tip1"); |
|
|
|
Assert.Equal("Tip1", target.GetValue(ToolTip.ToolTipProperty).Content); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Should_Open_On_Pointer_Enter_With_Delay() |
|
|
|
|