我想要“按下”键的那一刻在 WPF 中的 PreviewKeyDown 事件中
当我跳到 PreviewKeyDown 时,我的 RichTextBox 中插入符右侧的字符尚未移动。我想说的是,对于这个事件,你的东西将字符移到右侧,然后让我做我的事情。我怎样才能做到这一点?
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
}
}
更新:你知道我在说什么... =>
插入符号位于单词“Harold...”之前,然后我按了几次空格键来移动“哈罗德……”在右边。但是黑色下划线的格式似乎被卡住了...我怎样才能使下划线保持附加到包含名称“Harold...”的 Run 对象?
我想在 KeyDown 事件中捕获空格键的原因是为了获取新的隐式创建的 Run-object 并删除黑色下划线。
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... =>
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
“预览”事件在事件发生之前触发。处理事件后将触发一个等效的
KeyDown
事件。相反,连接到该事件,您的代码将在 WPF 完成处理按键后运行。"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.这就是为什么它被称为 PreviewKeyDown...您想要的事件可能是 KeyDown 或 TextChanged
That is why its called PreviewKeyDown... the event you want is probably KeyDown or TextChanged