开发者

I want the moment when a Key is "Down" in the PreviewKeyDown Event in WPF

开发者 https://www.devze.com 2023-01-19 16:18 出处:网络
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 d

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_PreviewKey开发者_JAVA技巧Down(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... =>

I want the moment when a Key is "Down" in the PreviewKeyDown Event in WPF

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.


"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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消