How to programmatically access ToolTipService of a Silverlight FrameworkElement?

10,888

Use the attached property accessor:-

 ToolTip tt = ToolTipService.GetToolTip(myFrameworkElement) As ToolTip;
Share:
10,888

Related videos on Youtube

Steve Crane
Author by

Steve Crane

Software developer for MiX Telematics.

Updated on April 17, 2022

Comments

  • Steve Crane
    Steve Crane about 2 years

    We have a languaging mechanism that recurses through our XAML pages when they load, examines each element for a Tag property and uses its value to retrieve a string resource to apply to the element. It doesn't currently support tooltips and we have to have specific code on each page to apply the languaged resources to them. I'm trying to add this functionality to our recursive mechanism.

    So I am recursing through the tree and for each element that is a FrameworkElement, I want to know whether it has a ToolTipService and if so whether that ToolTipService has a ToolTip element. If it does I want to retrieve the Tag property if any, and set the Content property with the value I look up using the tag. My problem is that I can't figure out how to determine if there is a tooltip and getaccess to it.

    Here is a sample showing an element, in this case an Image. If I'm recursing through the tree and the current element is the image, how do I get to the ToolTip?

    <Image x:Name="DateRangeSelectorButton" Grid.Column="0" Source="Images/OvalClock.png" Margin="2,0,2,0" Cursor="Hand">
      <ToolTipService.ToolTip>
        <ToolTip Tag="dttlDateRangeSelectorButtonTooltip"/>
      </ToolTipService.ToolTip>
    </Image>
    
  • Steve Crane
    Steve Crane over 14 years
    Excellent. Just what I needed. Didn't think of looking for static methods/properties; was just looking at properties of the element I was working with. Something to remember for the future.
  • George Birbilis
    George Birbilis over 10 years
    they're not static, they're Attached Dependency Properties (that is they're defined by other class, not the UIElement and they are attached to it)