سؤال

How to know whether a control such as TextBox has the input focus in a Windows Phone Silverlight app?

هل كانت مفيدة؟

المحلول

You have to use FocusManager

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

نصائح أخرى

There are events like GotFocus and LostFocus for controls.

If you subscribe to these events they automatically get called when your input receives or looses focus

you can use those events for your purpose.

XAML Declaration

<TextBox Name="myTextbox" GotFocus="myTextbox_GotFocus" />

and inside the cs

  private void myTextbox_GotFocus(object sender, RoutedEventArgs e)
  {

  }

  private void ContentPanel_LostFocus(object sender, RoutedEventArgs e)
  {

  }
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top