Related (but not a dupe!) to this question: http://stackoverflow.com/questions/1053210/help-with-the-wpf-textcompositionmanager-events
When using the TextCompositionManager I'm having an issue where, if an input control such as the TextBox has focus, the TextBox will "steal" the space character before I can get a chance to act on it.
For example, we have the following code:
public Window1()
{
TextCompositionManager.AddPreviewTextInputStartHandler
(this, PreviewTextInputStartHandler);
}
private void PreviewTextInputHandler(object sender, TextCompositionEventArgs e)
{
CaptureTextBlock.Text += e.Text;
e.Handled = true;
}
where Window1 looks like:
<!--standard window crap above here-->
<StackPanel>
<TextBlock Name="CaptureTextBlock" />
<TextBox Name="ThievingBastard" />
</StackPanel>
<!-- snip -->
Now, if I run this application and immediately type "I haet thieving bastards", the TextBlock will contain the text "I haet thieving bastards" and the textbox will be empty.
If, however, I focus the textbox (i.e., textbox has keyboard focus), after typing the above line the textblock will contain the text "Ihaetthievingbastards" and the textbox will contain the text " " (3 spaces).
I have two questions:
1) Can I prevent this from happening with just the facilities provided by the TextCompositionManager?
2) If not, where the hell do I plug into the text input stack so that I can fully control text input within my WPF application (negative points for even thinking about p/invoking) (you just thought about it, negative points added)?
Update
I'm using a hacky workaround where I handle the tunneling KeyDown event from the InputManager for spaces only. This method is very awkward, inefficient and basically stinks. Still looking for a better way.