views:

14

answers:

2

Hello,

when I jump into the PreviewKeyDown the char righthand to the Caret in my RichTextBox is not moved YET. I would like to say to this event do your stuff move the char to the rightside and THEN let me do MY stuff. How can I do that?

private void RTB_PreviewKeyDown(object sender, KeyEventArgs e)
 {
    if (e.Key == Key.Space)
    {
       // event do your stuff

       // Char righthanded from the Caret position is moved to the right side

       // do MY stuff
    }

}

UPDATE: that you know what I talk about... =>

alt text

The Caret was directly before the Word "Harold..." then I pressed the spacebar key several times to move the "Harold..." to the right. But the formatting a black Underline seem to be stuck... how can I make the Underline stay attached to the Run object containing the name "Harold..." ?

The reason why I wanted to catch the spacebar key in the KeyDown event is to get the new implicit created Run-object and remove the black Underline.

+1  A: 

"Preview" events are fired before the event happens. There will be an equivalent KeyDown event that is fired after the event is processed. Wire up to that event instead and your code will run after WPF has completed handling the keypress.

Martin Harris
It is more difficult... The problem is when I subscribe to the KeyDown event the spacebar key is not recognized, but I want to do special stuff only for the spacebar...
Lisa
I have updated my question with a concrete sample!
Lisa
A: 

That is why its called PreviewKeyDown... the event you want is probably KeyDown or TextChanged

m0s