1

誰かがWPFRichTextBoxの挿入モードを制御する方法を知っていますか。RichTextBoxを挿入ではなく常に上書きモードにしたい。

4

1 に答える 1

0

残念ながら、これを行うための文書化された方法はないようです。私が知っている唯一の方法は、以下のようにリフレクションを使用することですが、この手法はRichTextBoxの内部動作にアクセスします。これは現在のバージョンのWPFで機能しますが、今後も機能するという保証はありません。自己責任で使用してください。

PropertyInfo textEditorPropertyInfo = typeof(RichTextBox).GetProperty("TextEditor", BindingFlags.NonPublic | BindingFlags.Instance);

        if (textEditorPropertyInfo == null)
            throw new NotSupportedException("SetOverwriteable not support on this platform");

        object textEditor = textEditorPropertyInfo.GetValue(this, null);
        PropertyInfo overtypeModePropertyInfo = textEditor.GetType().GetProperty("_OvertypeMode", BindingFlags.NonPublic | BindingFlags.Instance);

        if (overtypeModePropertyInfo == null)
            throw new NotSupportedException("SetOverwriteable not support on this platform");

        overtypeModePropertyInfo.SetValue(textEditor, true, null);

上記はコンストラクターの後で発生する必要があります。

于 2009-05-23T17:15:32.960 に答える