更改工具提示InitialShowDelay全球物业 [英] Change the ToolTip InitialShowDelay Property Globally

查看:317
本文介绍了更改工具提示InitialShowDelay全球物业的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有了向上的色带控制设置了上百种不同的工具提示的应用。所有的工具提示弹出,而迅速(约半秒),我想加弹出延迟。经过一番研究,它会出现在WPF做到这一点的唯一方法是通过ToolTipService.InitialShowDelay属性。



我的问题是,我必须去通过XAML和明确说

  ToolTipService.InitialShowDelay =2000

对于具有工具提示每一个控制?或者是有一些方法在全球范围,设置该属性使用类似样式?



感谢您的任何想法。


解决方案

不幸的是,有没有简单的方法来做到这一点。理想情况下,你会设置ToolTipService.InitialShowDelay在FrameworkElement的,让它从那里传播,但事实证明,这似乎并没有工作。



相反,你可以设置它在每个键入控制你想设置它,例如:

 <风格的TargetType =RibbonButton> 
< setter属性=ToolTipService.InitialShowDelayVALUE =2000/>
< /样式和GT;
<风格的TargetType =RibbonToggleButton>
< setter属性=ToolTipService.InitialShowDelayVALUE =2000/>
< /样式和GT;
<风格的TargetType =RibbonDropDownButton>
< setter属性=ToolTipService.InitialShowDelayVALUE =2000/>
< /样式和GT;



等。



尽管这是一个这样做的相当冗长的方式,至少你只需要每一个控件本身设置在每个类型的控制,而不是 - 如果你在​​功能区使用它,那么就只有控制开始与少数

要保存自己的一些麻烦你曾经想改变的价值,你可以利用的资源价值要建筑师上面的代码:

 < SYS:的Int32 X:键=ToolTipInitialShowDelay> 2000< / SYS:&的Int32 GT; 
<风格的TargetType =RibbonButton>
< setter属性=ToolTipService.InitialShowDelay
值={StaticResource的ToolTipInitialShowDelay}/>
< /样式和GT;
<风格的TargetType =RibbonToggleButton>
< setter属性=ToolTipService.InitialShowDelay
值={StaticResource的ToolTipInitialShowDelay}/>
< /样式和GT;
<风格的TargetType =RibbonDropDownButton>
< setter属性=ToolTipService.InitialShowDelay
值={StaticResource的ToolTipInitialShowDelay}/>
< /样式和GT;



另外,如果你是不是已经在使用支持算法FMP的风格,你可以把它缩短为:

 <风格X:键=ToolTipDefaults> 
< setter属性=ToolTipService.InitialShowDelayVALUE =2000/>
< /样式和GT;
<风格的TargetType =RibbonButton支持算法FMP ={StaticResource的ToolTipDefaults}/>
<风格的TargetType =RibbonToggleButton支持算法FMP ={StaticResource的ToolTipDefaults}/>
<风格的TargetType =RibbonDropDownButton支持算法FMP ={StaticResource的ToolTipDefaults}/>

的限制这种做法是一个样式只能基于一个父样式,因此,如果您'已经在使用这种模式,您将无法做到这一点。


I have an application that has upwards of a hundred different ToolTips set on a Ribbon control. All of the ToolTips pop up rather quickly (about half a second), and I would like to increase the pop up delay. After some research it appears the only way to do this in WPF is through the ToolTipService.InitialShowDelay property.

My question is, do I have to go through the XAML and explicitly say

ToolTipService.InitialShowDelay="2000"

For every single control that has a ToolTip? Or is there some way to set this property globally, using something like a Style?

Thanks for any ideas.

解决方案

Unfortunately, there's no easy way to do this. Ideally, you'd set ToolTipService.InitialShowDelay on FrameworkElement and let it propagate from there, but it turns out that doesn't seem to work.

Instead, you can set it on each type of control you want to set it on, for instance:

<Style TargetType="RibbonButton">
    <Setter Property="ToolTipService.InitialShowDelay" Value="2000"/>
</Style>
<Style TargetType="RibbonToggleButton">
    <Setter Property="ToolTipService.InitialShowDelay" Value="2000"/>
</Style>
<Style TargetType="RibbonDropDownButton">
    <Setter Property="ToolTipService.InitialShowDelay" Value="2000"/>
</Style>

etc.

Although this is a pretty verbose way of doing it, at least you only have to set it on each type of control and not every control itself - and if you're using it in the Ribbon, then there's only a handful of controls to begin with.

To save yourself some hassle should you ever want to change the value, you may want to architect the above code using a resource value:

<sys:Int32 x:Key="ToolTipInitialShowDelay">2000</sys:Int32>
<Style TargetType="RibbonButton">
    <Setter Property="ToolTipService.InitialShowDelay" 
            Value="{StaticResource ToolTipInitialShowDelay}"/>
</Style>
<Style TargetType="RibbonToggleButton">
    <Setter Property="ToolTipService.InitialShowDelay" 
            Value="{StaticResource ToolTipInitialShowDelay}"/>
</Style>
<Style TargetType="RibbonDropDownButton">
    <Setter Property="ToolTipService.InitialShowDelay" 
            Value="{StaticResource ToolTipInitialShowDelay}"/>
</Style>

Alternatively, if you are not already using BasedOn styles, you could shorten it to:

<Style x:Key="ToolTipDefaults">
    <Setter Property="ToolTipService.InitialShowDelay" Value="2000"/>
</Style>
<Style TargetType="RibbonButton" BasedOn="{StaticResource ToolTipDefaults}"/>
<Style TargetType="RibbonToggleButton" BasedOn="{StaticResource ToolTipDefaults}"/>
<Style TargetType="RibbonDropDownButton" BasedOn="{StaticResource ToolTipDefaults}"/>

The limitation to this approach being that a style can only be based on one parent style, so if you're already using this pattern, you won't be able to do this.

这篇关于更改工具提示InitialShowDelay全球物业的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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