rem
rem

Reputation: 17055

Silverlight custom control ToolTip not showing up each time

In a Silverlight application I have a custom control with a number of custom properties. In the declaration class of the custom control additionally to defining its properties as dependency properties, I define showing a ToolTip:

public override void OnApplyTemplate()
    {
        base.OnApplyTemplate();
        Border bordercntr = base.GetTemplateChild("PART_SBorder") as Border;
        bordercntr.MouseEnter += new MouseEventHandler(bordercntr_MouseEnter);
        bordercntr.MouseLeave += new MouseEventHandler(bordercntr_MouseLeave);

    }

    private void bordercntr_MouseEnter(object sender, MouseEventArgs e)
    {
       string _sno = this.SomeProperty.ToString();

       ToolTipService.SetToolTip(this, "Some text " + _sno);
       VisualStateManager.GoToState(this, "Hovered",false);                            
    }

The problem is, that a ToolTip pops up not the first time mouse points to a custom control, but only after the second time. After I reload page this happens again: the first time I hover over a control nothing is shown up and then from the second time and further on the ToolTip pops up again. (not always in a stable way, I mean not 100% each time mouse hovers).

What could prevent the ToolTip from showing up in a stable manner each time a mouse hovers over control and starting showing up from the very first time of hovering it after reloading the page?

Upvotes: 1

Views: 1024

Answers (1)

Stephan
Stephan

Reputation: 5488

Set the ToolTip in the setter for SomeProperty The ToolTip you define in the ToolTipService will behave like a normal ToolTip and only appear when the mouse is over the control. You shouldn't need to handle the MouseEnter and MouseLeave events at all.

Upvotes: 3

Related Questions