How to programmatically access ToolTipService of a Silverlight FrameworkElement?

送分小仙女□ 提交于 2019-12-06 00:18:41

问题


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>

回答1:


Use the attached property accessor:-

 ToolTip tt = ToolTipService.GetToolTip(myFrameworkElement) As ToolTip;


来源:https://stackoverflow.com/questions/1571049/how-to-programmatically-access-tooltipservice-of-a-silverlight-frameworkelement

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!