check "IsFocused" property...

TextBox tb = new TextBox();

if(tb.IsFocused)
{
   your code here
   .....
   .....
}