问题
I have an AvalonEdit
WPF based application.
I want to define a specific behaviour when the user hovers with the mouse over a specific text in the editor, similar to tag_binding
with python tkinter
.
I googled around, and couldn't find any way to do this.
How can this be done?
回答1:
I found something similar here http://community.sharpdevelop.net/forums/p/9113/25353.aspx
The gist seems to be that at this time (2010!) there where no direct way to do it, but the following hint was given.
There's no built-in tooltip support, but long ago I've added the TextEditor.MouseHover event which can be used to show tool tips.
Example code:
ToolTip toolTip = new ToolTip();
void TextEditorMouseHover(object sender, MouseEventArgs e)
{
var pos = textEditor.GetPositionFromPoint(e.GetPosition(textEditor));
if (pos != null) {
toolTip.PlacementTarget = this; // required for property inheritance
toolTip.Content = pos.ToString();
toolTip.IsOpen = true;
e.Handled = true;
}
}
void TextEditorMouseHoverStopped(object sender, MouseEventArgs e)
{
toolTip.IsOpen = false;
}
来源:https://stackoverflow.com/questions/51711692/how-to-fire-an-event-when-mouse-hover-over-a-specific-text-in-avalonedit