System.Windows.Controls.InteractionHelper.AllowLostFocus C# (CSharp) Method

AllowLostFocus() public method

Check if the control's LostFocus event should be handled.
public AllowLostFocus ( RoutedEventArgs e ) : bool
e System.Windows.RoutedEventArgs Event arguments.
return bool
        public bool AllowLostFocus(RoutedEventArgs e)
        {
            if(e == null)
            {
                throw new ArgumentNullException("e");
            }

            bool enabled = Control.IsEnabled;
            if(enabled)
            {
                IsFocused = false;
            }
            return enabled;
        }

Usage Example

 /// <summary>
 /// Provides handling for the LostFocus event.
 /// </summary>
 /// <param name="e">The data for the event.</param>
 protected override void OnLostFocus(RoutedEventArgs e)
 {
     if (_interaction.AllowLostFocus(e))
     {
         _interaction.OnLostFocusBase();
         base.OnLostFocus(e);
     }
 }