如何在WPF中获得重点控制? [英] How to get the focused control in WPF?

查看:158
本文介绍了如何在WPF中获得重点控制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎样才能得到WPF的当前集中控制?我发现一些WinForms的解决方案,但调用WIN32的API函数,在WPF中无法工作?

/ p>

有没有什么办法可以在WPF中做到这一点?

解决方案

我做了什么

 保护覆盖无效OnPreviewLostKeyboardFocus(KeyboardFocusChangedEventArgs e)
{
lostFocusControl = e.OldFocus;

$ b private void PauseButton_PreviewKeyDown(object sender,KeyEventArgs e)
{
//调用OnPreviewLostKeyboardFocus处理函数
}


How can I get a current focused control in WPF?

I found some solution for WinForms, but invoking WIN32 API function, didn't work in WPF?

Is there any way for doing it in WPF?

解决方案

Here's what I did

protected override void OnPreviewLostKeyboardFocus(KeyboardFocusChangedEventArgs e)
{
    lostFocusControl = e.OldFocus;
}

private void PauseButton_PreviewKeyDown(object sender, KeyEventArgs e)
{
    // invoke OnPreviewLostKeyboardFocus handler
}

这篇关于如何在WPF中获得重点控制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆