How to Programmatically show a WPF/C# Windows.Control.ToolTip?

后端 未结 7 2048
温柔的废话
温柔的废话 2020-12-25 12:01

There doesn\'t seem to be a .Show() kind of method for the Windows.Control.ToolTip, incl in ToolTipService.

7条回答
  •  不知归路
    2020-12-25 12:44

    If you would like to control how long the tooltip remains open, you can subscribe to the Opened event and set a time delay before closing the tooltip.

    Subscription has to be done before IsOpen = true and it has to be an async method to avoid hanging up the UI.

    var tooltip = new ToolTip { Content = "New tooltip text" };
    MyControln.ToolTip = tooltip;
    tooltip.Opened += async delegate (object o, RoutedEventArgs args)
    {
        var s = o as ToolTip;
        // let the tooltip display for 1 second
        await Task.Delay(1000);
        s.IsOpen = false;
        // wait till the close tooltip animation finishes before changing to old tooltip text
        await Task.Delay(1000);
        s.Content = "Old tooltip text";
    };
    tooltip.IsOpen = true;
    

提交回复
热议问题