やりたいことは、
WPFのRichTextBoxで、Insertモードで日本語を文字入力して、
確定した時の文字を取得したいです。
新規でWPFプロジェクトを作り、以下コードをコピペすれば再現できます。
(Visual Studio2017でやりました)
C#
1//MainWindow.xaml.cs 2 3public partial class MainWindow : Window 4 { 5 public MainWindow() 6 { 7 InitializeComponent(); 8 9 TextCompositionManager.AddPreviewTextInputStartHandler(this.richTxtBox, OnPreviewTextnInputStart); 10 TextCompositionManager.AddPreviewTextInputUpdateHandler(this.richTxtBox, OnPreviewTextInputUpdate); 11 TextCompositionManager.AddPreviewTextInputHandler(this.richTxtBox, OnPreviewTextInput); 12 } 13 14 protected void OnPreviewTextnInputStart(object sender, TextCompositionEventArgs e) 15 { 16 int a = 0; // ブレークポイント用 17 } 18 19 protected void OnPreviewTextInputUpdate(object sender, TextCompositionEventArgs e) 20 { 21 int a = 0; // ブレークポイント用 22 } 23 24 protected void OnPreviewTextInput(object sender, TextCompositionEventArgs e) 25 { 26 int a = 0; // ブレークポイント用 27 } 28 }
C#
1//MainWindow.xaml 2 3<Window x:Class="WpfTest.MainWindow" 4 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 5 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 6 xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 7 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 8 xmlns:local="clr-namespace:WpfTest" 9 mc:Ignorable="d" 10 Title="MainWindow" Height="350" Width="525"> 11 <Grid> 12 <RichTextBox Name="richTxtBox"> 13 </RichTextBox> 14 </Grid> 15</Window>
上記コードを実行し、
RichTextBoxで、IMEをONにして日本語を入力すると、
各イベントのブレークポイントがひっかかります。
しかし、Insertモードにすると、ひっかからなくなります。
Insertモードでも上記イベント、
もしくは代替えとなるイベントを取得する方法はないでしょうか?
もしわかる方がいれば、教えていただけると大変助かります。
よろしくおねがいします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2018/04/11 00:40
2018/11/27 08:07
2018/11/27 09:57