似乎
UWP的richeditbox中缺少GetCharIndexFromPosition。我想在 RichEditBox 中将鼠标悬停在某个范围上时显示工具提示。UWP 可以做到这一点吗?
在UWP中,我们可以将GetRangeFromPoint(Point,PointOptions(方法等价于GetCharIndexFromPosition
。此方法检索屏幕上特定点处或最近点的退化(空(文本范围。它返回一个 ITextRange 对象,ITextRange
的 StartPosition 属性类似于GetCharIndexFromPosition
方法返回的字符索引。
下面是一个简单的示例:
XAML:
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<RichEditBox x:Name="editor" />
</Grid>
代码隐藏:
public MainPage()
{
this.InitializeComponent();
editor.Document.SetText(Windows.UI.Text.TextSetOptions.None, @"This is a text for testing.");
editor.AddHandler(PointerMovedEvent, new PointerEventHandler(editor_PointerMoved), true);
}
private void editor_PointerMoved(object sender, PointerRoutedEventArgs e)
{
var position = e.GetCurrentPoint(editor).Position;
var range = editor.Document.GetRangeFromPoint(position, Windows.UI.Text.PointOptions.ClientCoordinates);
System.Diagnostics.Debug.WriteLine(range.StartPosition);
}