Browse Source
Closing tooltips on control click (#12831 )
* Stop tooltip timer on pointer pressed to avoid hanging tooltips in some cases (i.e. when modal window is opened)
* Hiding tooltip on click
---------
Co-authored-by: Herman Kirshin <herman.kirshin@jetbrains.com>
pull/13006/head
Herman K
2 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with
10 additions and
0 deletions
src/Avalonia.Controls/ToolTipService.cs
@ -1,5 +1,6 @@
using System ;
using Avalonia.Input ;
using Avalonia.Interactivity ;
using Avalonia.Threading ;
using Avalonia.VisualTree ;
@ -28,12 +29,15 @@ namespace Avalonia.Controls
{
control . PointerEntered - = ControlPointerEntered ;
control . PointerExited - = ControlPointerExited ;
control . RemoveHandler ( InputElement . PointerPressedEvent , ControlPointerPressed ) ;
}
if ( e . NewValue ! = null )
{
control . PointerEntered + = ControlPointerEntered ;
control . PointerExited + = ControlPointerExited ;
control . AddHandler ( InputElement . PointerPressedEvent , ControlPointerPressed ,
RoutingStrategies . Bubble | RoutingStrategies . Tunnel | RoutingStrategies . Direct , true ) ;
}
if ( ToolTip . GetIsOpen ( control ) & & e . NewValue ! = e . OldValue & & ! ( e . NewValue is ToolTip ) )
@ -108,6 +112,12 @@ namespace Avalonia.Controls
Close ( control ) ;
}
private void ControlPointerPressed ( object? sender , PointerPressedEventArgs e )
{
StopTimer ( ) ;
( sender as AvaloniaObject ) ? . ClearValue ( ToolTip . IsOpenProperty ) ;
}
private void ControlEffectiveViewportChanged ( object? sender , Layout . EffectiveViewportChangedEventArgs e )
{
var control = ( Control ) sender ! ;