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 开发者_JS百科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!
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);
}
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.
精彩评论