如何以编程方式访问 Silverlight FrameworkElement 的 ToolTipService? [英] How to programmatically access ToolTipService of a Silverlight FrameworkElement?

查看:20
本文介绍了如何以编程方式访问 Silverlight FrameworkElement 的 ToolTipService?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个语言机制,它会在加载 XAML 页面时递归它们,检查每个元素的 Tag 属性并使用其值来检索要应用于该元素的字符串资源.它目前不支持工具提示,我们必须在每个页面上都有特定的代码才能将语言资源应用于它们.我正在尝试将此功能添加到我们的递归机制中.

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.

所以我在树中递归,对于每个属于 FrameworkElement 的元素,我想知道它是否有 ToolTipService,如果有,ToolTipService 是否有 ToolTip 元素.如果确实如此,我想检索 Tag 属性(如果有),并使用我使用标记查找的值设置 Content 属性.我的问题是我不知道如何确定是否有工具提示并访问它.

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>

推荐答案

使用附加属性访问器:-

Use the attached property accessor:-

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

这篇关于如何以编程方式访问 Silverlight FrameworkElement 的 ToolTipService?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆