wpf 工具提示 - 跨应用程序设置持续时间

问题描述:

我可以在单个控件工具提示上设置属性,例如持续时间.但我需要的是为整个应用程序中的所有工具提示设置更长的持续时间 - 所有窗口,所有用户控件等.有没有什么干净的方法来实现它?谢谢.

I can set properties on single control tooltip like duration. But what i need is to set longer duration for ALL tooltips in entire application - all windows, all user controls etc. Is there any clean way to achieve it? Thank you.

您可以像这样覆盖 ToolTipService.ShowDurationProperty 的元数据:

You can override the meta-data for the ToolTipService.ShowDurationProperty like so:

public partial class App : System.Windows.Application {

    static App() {
        ToolTipService.ShowDurationProperty.OverrideMetadata(typeof(UIElement),
            new FrameworkPropertyMetadata(1000));
    }

}

以上将使所有 UIElements 的 ToolTip 持续时间为 1 秒.

The above will make the ToolTip duration 1 second for all UIElements.