New to Telerik UI for WPF? Download free 30-day trial

Change ToolTip ShowDuration

Environment

Product Version 2022.1.117
Product RadSyntaxEditor for WPF

Description

How to create a custom UILayer to customize the way that tooltips are shown such as extending their ShowDuration.

Solution

1. Implement a custom tooltip tagger as explained in the Custom Tagger article.

2. Implement a custom UILayer that derives from TextToolTipUILayer. In the GetLinePartUIElement method, you can get the Rectangle created by default and set the ToolTipService.ShowDuration attached property.

Creating a custom TextToolTipUILayer

public class CustomTextToolTipUILayer : TextToolTipUILayer 
{ 
    protected override FrameworkElement GetLinePartUIElement(ToolTipTag tag, Span span, UIUpdateContext updateContext) 
    { 
        var rectangle = (Rectangle)base.GetLinePartUIElement(tag, span, updateContext); 
        ToolTipService.SetShowDuration(rectangle, int.MaxValue); 
        return rectangle; 
    } 
} 
3. To apply the custom UILayer, create a custom UILayersBuilder and override its BuildUILayers method. In the method, you can replace the default TextToolTipUILayer with the custom one using the Remove and AddAfter methods of the UILayerStack.

Creating a custom UILayersBuilder

public class CustomUILayersBuilder : UILayersBuilder 
{ 
    public override void BuildUILayers(UILayerStack uiLayers) 
    { 
        base.BuildUILayers(uiLayers); 
        uiLayers.Remove(PredefinedUILayers.TextToolTip); 
        uiLayers.AddAfter(PredefinedUILayers.Text, new CustomTextToolTipUILayer()); 
    } 
} 
4. Apply the custom UILayersBuilder using the syntax editor's property with the same name.

Creating a custom UILayersBuilder

this.syntaxEditor.UILayersBuilder = new CustomUILayersBuilder(); 

See Also

In this article