Положение всплывающей подсказки в редакторе avalon - PullRequest
0 голосов
/ 19 февраля 2019

У меня проблема в редакторе avalon wpf, положение всплывающей подсказки не установлено.

В редакторе avalon я должен установить подсказку рядом со словом, когда после ввода пробела введено.
Но я не получаю никакого решения, чтобы всплывающая подсказка отображалась рядом со словом при вводе пробела.

toolTip.Placement = PlacementMode.Relative;
toolTip.Content = "aa";
toolTip.IsOpen = true;

1 Ответ

0 голосов
/ 19 февраля 2019

Вот пример для выполнения того, что вы просили:

XAML

<Window x:Class="WpfApp1.Window1"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:avalonedit="http://icsharpcode.net/sharpdevelop/avalonedit"
        mc:Ignorable="d"
        Title="Window1" Height="450" Width="800">
     <avalonedit:TextEditor Name="TextEditor" KeyDown="TextEditor_KeyDown" />
</Window>

Код:

using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;

namespace WpfApp1
{
    using System.Windows.Controls.Primitives;

    public partial class Window1 : Window
    {
        private ToolTip toolTip;
        public Window1()
        {
            InitializeComponent();
            toolTip = new ToolTip { Placement = PlacementMode.Relative, PlacementTarget = TextEditor};
            TextEditor.ToolTip = toolTip;
        }

        private void TextEditor_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Space)
            {
                var caret = this.TextEditor.TextArea.Caret.CalculateCaretRectangle();
                toolTip.HorizontalOffset = caret.Right;
                toolTip.VerticalOffset = caret.Bottom;
                toolTip.Content = "aa";
                toolTip.IsOpen = true;
            }
            else
            {
                toolTip.IsOpen = false;
            }
        }
    }
}

Результат:

WPF tooltip positioning at caret

...