Search code examples
wpftooltipcontentcontrol

When Tooltip.Content gets populated?


I need to use the Tooltip.Content information of any given control.

Lets say there is a a control TextBlock and it is bound to a Tooltip. I access the Tooltip of the TextBlock by var toolTip=(ToolTip)TextBlock.ToolTip. The value of toolTip.Content remains null, but if I do a mouse hover over the control it is populated with the desired value.

How do I get the tooltip to populate its content before triggering a mouse over the control? Does the Tooltip loads its content lazily or is there something I am missing?

Edit:

To clarify the question above:

I was trying to show tooltip but its content was not populated with the binding value although its bound to a valid property.


Solution

  • I just found answer to my own question, Tooltip control doesn't get created until it is necessary. And when it gets created it sets is PlacementTarget to the parent control and sets its IsOpen property to true. When 'PlacementTargetis set it populates theToolTip.Content` property.

    In my case I was just trying to set IsOpen property without setting the PlacementTarget. Now after setting it the content is bound and the tooltip is shown as expected.