How to fire an event when mouse hover over a specific text in AvalonEdit?

喜你入骨 提交于 2019-12-22 18:32:12

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!