本文介绍了当鼠标悬停在AvalonEdit中的特定文本上时,如何触发事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个基于AvalonEdit WPF的应用程序.

I have an AvalonEdit WPF based application.

当用户将鼠标悬停在编辑器中的特定文本上时,我想定义一种特定的行为,类似于使用python tkintertag_binding.

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.

我在Google周围搜索,找不到任何方法.

I googled around, and couldn't find any way to do this.

这怎么办?

推荐答案

我在这里找到了类似的内容 http://community.sharpdevelop.net/forums/p/9113/25353.aspx

I found something similar here http://community.sharpdevelop.net/forums/p/9113/25353.aspx

要点似乎是在此时(2010年!),尚无直接方法可以做到,但是给出了以下提示.

The gist seems to be that at this time (2010!) there where no direct way to do it, but the following hint was given.

示例代码:

    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;
    }

这篇关于当鼠标悬停在AvalonEdit中的特定文本上时,如何触发事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-30 10:19