2017-03-27 4 views

答えて

0

UWPではGetCharIndexFromPositionと同等の方法としてGetRangeFromPoint(Point, PointOptions)メソッドを使用できます。このメソッドは、縮退した(空の)テキスト範囲を、画面上の特定の点で、またはその点に最も近い点で取得します。 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); 
} 
+0

こんにちはジェイ、ちょっと

次は、簡単なサンプルです!返信が遅れてしまい、ありがとうございます。 –

関連する問題