Detecting a control's focus in Silverlight

后端 未结 2 1107
傲寒
傲寒 2021-02-05 12:05

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

2条回答
  •  温柔的废话
    2021-02-05 12:30

    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;
    }
    

提交回复
热议问题