1

RichEditBox で選択したテキストの視覚的な選択状態を維持する方法を知っている人はいますか? Windows 8.1 アプリに基本的なテキスト編集を追加したいのですが、テキストを選択してアプリ内の別の UI 要素をクリックするたびに、RichEditBox によって選択が非表示になります。

unfocus イベントを登録して選択範囲を再度設定しようとしましたが、残念ながらこれは効果がありません。

私はまた、テキストの上に自分の四角形を描画しようとしました

richEdit.Document.Selection.GetRect(PointOptions.ClientCoordinates,out selectionRect, out hitCount );

これは、1 行内の一部のテキストのみが選択されている限り機能します。選択範囲が複数行の場合、選択したテキストの左上と右下の位置のみを取得します。これらは、選択が開始された場所と終了した場所のマウス位置のようです。

RichEditBox がフォーカスされていないときに、選択したテキストを表示し続ける他の方法はありますか。

4

2 に答える 2

2

別の回避策を見つけました。RichEditBox がフォーカスされていない場合は、選択の背景を設定するだけです。しかし、Jerry's Post は、このソリューションへのインスピレーションを与えてくれました。この方法は、最初の場所を見つけるのが簡単だったようです:

private void RichEditOnGotFocus(object sender, RoutedEventArgs routedEventArgs)
{
    ITextSelection selectedText = richEdit.Document.Selection;
    if (selectedText != null)
    {
        richEdit.Document.Selection.SetRange(_selectionStart, _selectionEnd);
        selectedText.CharacterFormat.BackgroundColor = Colors.White;
    }
}

private void RichEditOnLostFocus(object sender, RoutedEventArgs routedEventArgs)
{
    _selectionEnd = richEdit.Document.Selection.EndPosition;
    _selectionStart = richEdit.Document.Selection.StartPosition;

    ITextSelection selectedText = richEdit.Document.Selection;
    if (selectedText != null)
    {
        selectedText.CharacterFormat.BackgroundColor = Colors.Gray;
    }
}
于 2014-08-06T10:36:14.847 に答える