如何关闭整个应用程序的工具提示
是否可以关闭所有控件的工具提示(始终或基于某些规则),而无需在每个控件上设置 TooltipService.IsEnabled?我的意思是,检查所有逻辑项目需要太多时间。
Is it possible to turn-off toooltips for all controls (always or based on some rule) without setting TooltipService.IsEnabled on each control? I mean, going through all logical items takes too much time.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
试试这个。它隐藏所有工具提示。
Try this. It hides all tooltips.
您应该能够使用多种方法来完成此任务。 Marco Zhou 在 此发布。,这两种方法都依赖于将父控件(例如 窗户。显然它会继承给所有子项,因此您可以将其设置在那里以禁用所有工具提示。
您还可以将所有工具提示设置为一种样式,该样式绑定到一个属性,以便在您需要时使它们不可见或禁用。
编辑
添加代码以使其更易于理解:
创建 ToolTipEnabled 附加属性,该属性设置
FrameworkPropertyMetadataOptions.Inherits
以便子级继承它。您可以在 XAML 或代码隐藏中使用此属性,如下所示:
或者
There are several ways you should be able to use to accomplish this. Marco Zhou outlines two of them in this posting., both of these methods relying on setting TooltipService.IsEnabled to False for a parent control such as a Window. Apparently it inherits to all children, so you can set it just there to disable all tooltips.
You could also set all of your Tooltips to a style which had bindings to a property that would make them invisible or disabled when you wanted.
EDIT
Adding the Code to make it easier to understand:
Create the ToolTipEnabled Attached Property which sets the
FrameworkPropertyMetadataOptions.Inherits
so that it will be inherited by the children.You can either use this property in the XAML or codebehind as below:
Or
将此样式放在整个应用程序中可访问的位置(资源字典或 App.xaml),这样您就不需要在任何文本框中引用此样式。
注意
这是由 Expression Blend 生成的默认文本框样式,我添加了以下触发器,该触发器在文本框不为空时启用工具提示,否则禁用它们
Put this style where it is accessible throughout the application(a resourcedictionary or App.xaml) so you won't need to reference this style in any textbox.
NOTE
This is the default textbox style generated by Expression blend to which I have added the following trigger which enables tooltips when textbox is not empty and disables them otherwise
我不知道任何全局设置,但有一种简单的方法可以使用 Linq-to-VisualTree,我不久前编写的实用程序,为可视化树提供 Linq-to-XML 风格的 API 。
以下应该可以解决问题:
I don't know of any global setting, but there is an easy way to 'visit' all of the elements of your visual tree using Linq-to-VisualTree, I utility I wrote a while back that providers a Linq-to-XML style API for the visual tree.
The following should do the trick:
您可以尝试使用
You can try to use
我没有在一个语句中处理整个应用程序的答案,但我已经能够将许多特定于 UI 的参数集中在一个通用基类中,然后创建从该基类派生的应用程序并继承集中设置。我应该提到,您必须添加一些额外的管道到基类中以支持 MVVM,如下所示:
XAML 代码如下所示:
重要的绑定是与 相关的绑定>ToolTipService.IsEnabled 和 ToolTipService.ShowDuration。
您可以看到,如果 MyToolTipDuration 设置为零,MyToolTipEnabled 将返回 false,这会禁用工具提示。在我的第一次尝试中,我尝试简单地将 MyToolTipDuration 设置为零,而不将 ToolTipService.IsEnabled= 与 MyToolTipEnabled 属性结合使用,但所有这些都完成了闪烁的、几乎难以阅读的工具提示时隐时现。
总的来说,这对我来说效果很好(ymmv),尽管不如单个设置或单个调用来处理整个应用程序,并避免使用我希望支持的功能的工具提示将这些绑定分发到每个项目中的需要禁用。哦,好吧,在罗马的时候……
无论如何,希望有人发现这个有用。
I don't have an answer for handling the entire app in one statement, but I've been able to centralize a number of UI-specific parameters in a general base class, then create applications which are derived off this base class and inherit the centralized settings. I should mention there's some extra plumbing you have to add to the base class to support MVVM as in the following:
The XAML code looks like this:
With the important bindings being those related to ToolTipService.IsEnabled and ToolTipService.ShowDuration.
You can see that if MyToolTipDuration is set to zero, MyToolTipEnabled will return false and this disables the tooltip. In my first attempt I tried simply setting MyToolTipDuration to zero without using the ToolTipService.IsEnabled= in conjunction with the MyToolTipEnabled property, but all that accomplished was flashing, barely-readable tooltips which appear and disappear.
Overall this worked pretty well for me (ymmv), though not as well as a single setting or single call that would have handled the entire app and circumvented the need for distributing these bindings into every item with a tooltip I wanted to be support the ability to disable. Oh well, when in Rome....
In any event, hopefully someone finds this of use.