[英]UWP RichEditBox equivalent of GetCharIndexFromPosition
UWP的richeditbox中似乎缺少GetCharIndexFromPosition。 我想在RichEditBox中將某個范圍懸停時顯示工具提示。 UWP有可能嗎?
在UWP中,我們可以使用GetRangeFromPoint(Point,PointOptions)方法等效於GetCharIndexFromPosition
。 此方法檢索屏幕上特定點處或最接近該點的退化(空)文本范圍。 它返回一個ITextRange對象和中StartPosition的屬性ITextRange
類似於由返回的字符索引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);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.