Skip to content

Commit

Permalink
fix: ButtonBase should not lose focus when Command.CanExecuteChanged …
Browse files Browse the repository at this point in the history
…becomes false
  • Loading branch information
MartinZikmund committed Jan 21, 2022
1 parent 9f6ec94 commit e7cbc8b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/Uno.UI/UI/Xaml/Controls/Control/Control.cs
Original file line number Diff line number Diff line change
Expand Up @@ -795,8 +795,11 @@ private protected override void OnIsEnabledChanged(IsEnabledChangedEventArgs e)
}
}

// TODO Uno specific: Adding check for IsEnabledSuppressed here
// as we need to make sure that when a Command is executing, the control
// should not lose focus
bool shouldReevaluateFocus =
!IsEnabled && //!pControl->ParserOwnsParent()
!(IsEnabled || IsEnabledSuppressed) && //!pControl->ParserOwnsParent()
!AllowFocusWhenDisabled &&
// We just disabled this control, find if this control
//or one of its children had focus.
Expand Down
9 changes: 7 additions & 2 deletions src/Uno.UI/UI/Xaml/FrameworkElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -720,14 +720,19 @@ private protected virtual void OnIsEnabledChanged(IsEnabledChangedEventArgs pArg
}
#endregion

internal bool IsEnabledSuppressed => _suppressIsEnabled;

/// <summary>
/// Provides the ability to disable <see cref="IsEnabled"/> value changes, e.g. in the context of ICommand CanExecute.
/// </summary>
/// <param name="suppress">If true, <see cref="IsEnabled"/> will always be false</param>
private protected void SuppressIsEnabled(bool suppress)
{
_suppressIsEnabled = suppress;
this.CoerceValue(IsEnabledProperty);
if (_suppressIsEnabled != suppress)
{
_suppressIsEnabled = suppress;
this.CoerceValue(IsEnabledProperty);
}
}

private object CoerceIsEnabled(object baseValue)
Expand Down

0 comments on commit e7cbc8b

Please sign in to comment.