c# - avalon 编辑器中的工具提示位置
问题描述
我在 wpf avalon 编辑器中遇到问题,未设置工具提示的位置。
在 avalon 编辑器中,在键入单词空间后,我必须在单词附近设置工具提示。
但是我没有得到任何解决方案,因此在键入空格时工具提示会显示在单词附近。
toolTip.Placement = PlacementMode.Relative;
toolTip.Content = "aa";
toolTip.IsOpen = true;
解决方案
这是一个执行您要求的示例:
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;
}
}
}
}
结果:
推荐阅读
- python - 有没有办法通过 tkinter 的条目(忽略空白条目)在 sqlite 日期中搜索?
- powershell - Powershell如何从另一个变量中减去一个变量,两者都包含Exchange邮箱对象标识
- ios - Unable to change navigation bar color during runtime via code?
- css - 如何对待属性选择器:悬停
- python - 在 windows server 中使用 python/C# 读取邮箱电子邮件并保存附件
- c++ - 使用makefile抛出错误构建OpenCV?
- python - 熊猫如何根据冒号分割每列的值
- java - 反序列化包含 XML 字符串的 XML 属性
- java - 我该如何解决这个错误:java.lang.NumberFormatException
- javascript - 留言时间乱了