似乎GetCharIndexFromPosition在UWP的richeditbox中缺失了。当某个范围在RichEditBox中悬停时,我想显示工具提示。这和UWP有可能吗?
发布于 2017-03-29 13:13:25
在UWP中,我们可以使用GetRangeFromPoint(点,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);
}https://stackoverflow.com/questions/43053161
复制相似问题