Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detecting a control's focus in Silverlight

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 would see in a regular .Net application):

textBox.Focused

This seems like something simple and trivial to leave out from a control, and yet I can't find an answer anywhere.

Update

A slightly more elegant solution, incorporating Rob's answer, is to create an extension method like so:

public static bool IsFocused( this Control control )
{
    return FocusManager.GetFocusedElement() == control;
}
like image 801
Dov Avatar asked Dec 23 '09 16:12

Dov


1 Answers

You have to use FocusManager

bool b = FocusManager.GetFocusedElement() == textBox;
like image 180
Rob Fonseca-Ensor Avatar answered Oct 08 '22 14:10

Rob Fonseca-Ensor