【问题标题】:Tooltip position in avalon editoravalon 编辑器中的工具提示位置
【发布时间】:2019-02-19 10:18:29
【问题描述】:

wpf avalon 编辑器有问题,工具提示的位置没有设置。

在 avalon 编辑器中,在键入单词空间后,我必须在单词附近设置工具提示。
但是我没有得到任何解决方案,因此在键入空格时工具提示会显示在单词附近。

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

【问题讨论】:

  • 我不明白你的意思:在输入单词空间后靠近单词

标签: c# wpf avalonedit


【解决方案1】:

这是一个按照您的要求做的示例:

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

结果:

【讨论】:

  • 感谢这个工作,但是当有滚动条时,工具提示位置再次不起作用
  • 当没有滚动条时,它是否完全按照您的意愿工作?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2023-03-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-02-10
  • 1970-01-01
  • 2020-12-31
相关资源
最近更新 更多