diff --git a/src/Uno.UI/UI/Xaml/Controls/PasswordBox/PasswordBox.cs b/src/Uno.UI/UI/Xaml/Controls/PasswordBox/PasswordBox.cs index 33c00bbeedef..1cf002891958 100644 --- a/src/Uno.UI/UI/Xaml/Controls/PasswordBox/PasswordBox.cs +++ b/src/Uno.UI/UI/Xaml/Controls/PasswordBox/PasswordBox.cs @@ -16,13 +16,7 @@ public partial class PasswordBox : TextBox private Button _revealButton; private readonly SerialDisposable _revealButtonSubscription = new SerialDisposable(); - public PasswordBox() -#if __MACOS__ - : base(true) -#endif - { - - } + public PasswordBox() : base(true) { } protected override void OnLoaded() { @@ -134,13 +128,11 @@ public override string GetAccessibilityInnerText() return null; } + #region IsPasswordRevealButtonEnabled DependencyProperty public bool IsPasswordRevealButtonEnabled { get => (bool)this.GetValue(IsPasswordRevealButtonEnabledProperty); - set - { - this.SetValue(IsPasswordRevealButtonEnabledProperty, value); - } + set => this.SetValue(IsPasswordRevealButtonEnabledProperty, value); } public static readonly DependencyProperty IsPasswordRevealButtonEnabledProperty = @@ -157,19 +149,20 @@ public bool IsPasswordRevealButtonEnabled private void OnIsPasswordRevealButtonEnabledChanged(DependencyPropertyChangedEventArgs e) { _isButtonEnabled = IsPasswordRevealButtonEnabled; - UpdateButtonStates(); - } - private void UpdateButtonStates() - { - if(IsPasswordRevealButtonEnabled) + if (IsPasswordRevealButtonEnabled) { - VisualStateManager.GoToState(this, "ButtonVisible", true); + VisualStateManager.GoToState(this, TextBoxConstants.ButtonVisibleStateName, true); } else { - VisualStateManager.GoToState(this, "ButtonCollapsed", true); + VisualStateManager.GoToState(this, TextBoxConstants.ButtonCollapsedStateName, true); } + + OnIsPasswordRevealButtonEnabledChangedPartial(e); } + + partial void OnIsPasswordRevealButtonEnabledChangedPartial(DependencyPropertyChangedEventArgs e); + #endregion } } diff --git a/src/Uno.UI/UI/Xaml/Controls/TextBox/TextBox.cs b/src/Uno.UI/UI/Xaml/Controls/TextBox/TextBox.cs index b0839d4edd50..40d67dcc7ef8 100644 --- a/src/Uno.UI/UI/Xaml/Controls/TextBox/TextBox.cs +++ b/src/Uno.UI/UI/Xaml/Controls/TextBox/TextBox.cs @@ -29,13 +29,12 @@ public class TextBoxConstants public const string ContentElementPartName = "ContentElement"; public const string PlaceHolderPartName = "PlaceholderTextContentPresenter"; public const string DeleteButtonPartName = "DeleteButton"; + public const string ButtonVisibleStateName = "ButtonVisible"; + public const string ButtonCollapsedStateName = "ButtonCollapsed"; } public partial class TextBox : Control, IFrameworkTemplatePoolAware { - private const string ButtonVisibleStateName = "ButtonVisible"; - private const string ButtonCollapsedStateName = "ButtonCollapsed"; - #pragma warning disable CS0067, CS0649 private IFrameworkElement _placeHolder; private ContentControl _contentElement; @@ -43,8 +42,7 @@ public partial class TextBox : Control, IFrameworkTemplatePoolAware #pragma warning restore CS0067, CS0649 private ContentPresenter _header; - private bool _isPassword; - protected bool _isButtonEnabled = true; + protected private bool _isButtonEnabled = true; public event TextChangedEventHandler TextChanged; public event TypedEventHandler TextChanging; @@ -72,18 +70,12 @@ public partial class TextBox : Control, IFrameworkTemplatePoolAware public TextBox() { - _isPassword = false; InitializeVisualStates(); this.RegisterParentChangedCallback(this, OnParentChanged); } private void OnParentChanged(object instance, object key, DependencyObjectParentChangedEventArgs args) => UpdateFontPartial(); - protected TextBox(bool isPassword) - { - _isPassword = isPassword; - } - private void InitializeProperties() { UpdatePlaceholderVisibility(); @@ -666,11 +658,11 @@ private void UpdateButtonStates() // TODO (https://github.com/unoplatform/uno/issues/683): && ActualWidth >= TDB / Note: We also have to invoke this method on SizeChanged ) { - VisualStateManager.GoToState(this, ButtonVisibleStateName, true); + VisualStateManager.GoToState(this, TextBoxConstants.ButtonVisibleStateName, true); } else { - VisualStateManager.GoToState(this, ButtonCollapsedStateName, true); + VisualStateManager.GoToState(this, TextBoxConstants.ButtonCollapsedStateName, true); } } diff --git a/src/Uno.UI/UI/Xaml/Controls/TextBox/TextBox.macOS.cs b/src/Uno.UI/UI/Xaml/Controls/TextBox/TextBox.macOS.cs index 5cc297cef994..69a3698bb52a 100644 --- a/src/Uno.UI/UI/Xaml/Controls/TextBox/TextBox.macOS.cs +++ b/src/Uno.UI/UI/Xaml/Controls/TextBox/TextBox.macOS.cs @@ -10,8 +10,14 @@ namespace Windows.UI.Xaml.Controls { public partial class TextBox { + private bool _isPassword; private ITextBoxView _textBoxView; + protected TextBox(bool isPassword) + { + _isPassword = isPassword; + } + partial void InitializePropertiesPartial() { OnTextAlignmentChanged(CreateInitialValueChangerEventArgs(TextAlignmentProperty, null, TextAlignment));