Is there any way to tell whether a control (specifically a System.Windows.Controls.TextBox) is focused in Silverlight? I\'m looking for something like the following (what you wo
You have to use FocusManager
bool b = FocusManager.GetFocusedElement() == textBox;
As soon as you have a control consisting of more than one input element (which needs to have focus for handling user input) asking the FocusManager won't do the trick anymore. Try this:
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;
}