WPF equivalent to ActiveControl?

2019-07-05 03:09发布

In Forms, I can simple use ActiveControl.name to get the name of the active control. However in WPF this doesn't work. What is the WPF command equivalent to Activecontrol.name? I'll take C# or VB, either way. Thank you!

1条回答
霸刀☆藐视天下
2楼-- · 2019-07-05 04:07

There are a couple of possibilities though I'm not sure either is an exact match for ActiveControl:

  • Keyboard.FocusedElement: this static member tells you which element has the keyboard focus in the current application
  • FocusManager.GetFocusedElement(): this allows you to get the focused element within a given focus scope. Note that this cannot be used on arbitrary controls, only on controls which are focus scopes (i.e. have FocusManager.IsFocusScope set to true).

Do either of these sound like what you want?

查看更多
登录 后发表回答