在Silverlight中检测控件的焦点

有没有办法判断控件(特别是System.Windows.Controls.TextBox)是否集中在Silverlight中? 我正在寻找类似以下内容(您将在常规.Net应用程序中看到的内容):

textBox.Focused 

从控件中省略这似乎是一件简单而微不足道的事情,但我无法在任何地方找到答案。

更新

结合Rob的答案,稍微优雅的解决方案是创建一个类似的扩展方法:

 public static bool IsFocused( this Control control ) { return FocusManager.GetFocusedElement() == control; } 

您必须使用FocusManager

 bool b = FocusManager.GetFocusedElement() == textBox; 

只要你有一个由多个输入元素组成的控件(需要有焦点来处理用户输入),请求FocusManager不再使用该技巧。 试试这个:

 private bool HasFocus { get; set; } protected override void OnGotFocus( RoutedEventArgs e ) { base.OnGotFocus( e ); HasFocus = true; } protected override void OnLostFocus( RoutedEventArgs e ) { base.OnLostFocus( e ); HasFocus = false; }