以编程方式设置工具提示持续时间的问题

发布于 2024-11-18 13:23:03 字数 556 浏览 1 评论 0原文

我遇到过一种情况,我需要创建一个工具提示对象并在用户将鼠标悬停在应用程序中的特定区域上时显示它。

我可以让工具提示正常显示。问题是我需要它在几秒钟后消失。我知道 ToolTipService.SetShowDuration 并尝试使用它,但我没有遇到太多运气。

这是我在 MouseMove 事件处理程序中得到的内容:

_toolTip.Placement = PlacementMode.Relative;
_toolTip.Horizontal = e.X;
_toolTip.VerticalOffset = e.Y;
_toolTip.Content = stuffs;
_toolTip.IsOpen = true;

我尝试设置以下内容:

someObject.ToolTip = _toolTip;
ToolTipService.SetShowDuration(someObject, 5);

最后两行没有任何变化。工具提示仍然可见并且保持可见。我使用该服务的方式有误吗?任何想法将不胜感激!

I've come across a situtation where I need to create a tooltip object and show it when the user hovers over specific areas in my application.

I can get the tooltip to show up just fine. The problem is I need it to go poof after a few seconds have passed. I'm aware of the ToolTipService.SetShowDuration and I've tried using it, but I have not been met with much luck.

Here's what I got in my MouseMove event handler:

_toolTip.Placement = PlacementMode.Relative;
_toolTip.Horizontal = e.X;
_toolTip.VerticalOffset = e.Y;
_toolTip.Content = stuffs;
_toolTip.IsOpen = true;

I've tried setting the following:

someObject.ToolTip = _toolTip;
ToolTipService.SetShowDuration(someObject, 5);

Nothing changes with the last two lines. The tooltip still is visible and stays visible. Am I using the service wrong or something? Any thoughts would be much appreciated!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

二智少女 2024-11-25 13:23:03

我为这个问题开发了一个解决方法。

为了提供更多背景信息,我在 WindowsFormsHost 对象内有一个飞机的 3D 模型。当用户将鼠标悬停在已识别的部分上时,我需要出现一个工具提示。

我创建了一个工具提示实例,并在 MouseMove 事件中执行了如下操作:

// selectedPart will be null if no part is selected
if(selectedPart != null && prevSelectedPart != selectedPart)
{
    toolTip.IsOpen = false;
    host.ToolTip = toolTip;
    toolTip.IsOpen = true;
}
else if (prevSelectedPart == selectedPart  && prevSelectedPart != null)
{
    toolTip.IsOpen = true;
}
else
    toolTip.IsOpen = false;

这对我来说很有效。

I developed a workaround for the issue.

To give a little more background, I have a 3D model of an aircraft inside of a WindowsFormsHost object. When the user hovers over a identified part, I needed a tooltip to appear.

I created an instance of tooltip and in my MouseMove event and I do something like this:

// selectedPart will be null if no part is selected
if(selectedPart != null && prevSelectedPart != selectedPart)
{
    toolTip.IsOpen = false;
    host.ToolTip = toolTip;
    toolTip.IsOpen = true;
}
else if (prevSelectedPart == selectedPart  && prevSelectedPart != null)
{
    toolTip.IsOpen = true;
}
else
    toolTip.IsOpen = false;

That does the trick for me.

转身泪倾城 2024-11-25 13:23:03

试试这个。

 <Border Name="border" ToolTip="some message" MouseEnter="border_MouseEnter" Background="red" Margin="50"/>

  ToolTip tool = new ToolTip();
        private void border_MouseEnter(object sender, MouseEventArgs e)
        {
        tool.Placement = PlacementMode.Relative;
        tool.HorizontalOffset = 100; 
        tool.VerticalOffset = 200;
        tool.Content = "stuffs";
        tool.IsOpen = true;
        border.ToolTip = tool;
        ToolTipService.SetShowDuration(border, 5000);
        }

Try this.

 <Border Name="border" ToolTip="some message" MouseEnter="border_MouseEnter" Background="red" Margin="50"/>

  ToolTip tool = new ToolTip();
        private void border_MouseEnter(object sender, MouseEventArgs e)
        {
        tool.Placement = PlacementMode.Relative;
        tool.HorizontalOffset = 100; 
        tool.VerticalOffset = 200;
        tool.Content = "stuffs";
        tool.IsOpen = true;
        border.ToolTip = tool;
        ToolTipService.SetShowDuration(border, 5000);
        }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文