Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TextBoxMask: binding problem #1228

Closed
gpbicego opened this issue Jun 20, 2017 · 6 comments
Closed

TextBoxMask: binding problem #1228

gpbicego opened this issue Jun 20, 2017 · 6 comments
Assignees
Labels
bug 🐛 An unexpected issue that highlights incorrect behavior controls 🎛️
Milestone

Comments

@gpbicego
Copy link

gpbicego commented Jun 20, 2017

Repro

<StackPanel>
    <TextBox x:Name="TextBox1" Text="{x:Bind SomeInt, Mode=TwoWay}"
             mtuuc:TextBoxMask.Mask="9999" mtuuc:TextBoxMask.PlaceHolder=" " />
    <TextBox x:Name="TextBox2" Text="{x:Bind SomeInt, Mode=TwoWay}"/>
</StackPanel>
public sealed partial class MainPage : INotifyPropertyChanged
{
    private int _someInt = 333;
    public MainPage()
    {
        this.InitializeComponent();
        ((FrameworkElement)Content).DataContext = this;
    }
    public int SomeInt
    {
        get => _someInt;
        set
        {
            if (_someInt == value) return;
            _someInt = value;
            OnPropertyChanged();
        }
    }
    public event PropertyChangedEventHandler PropertyChanged;
    private void OnPropertyChanged([CallerMemberName] string propertyName = null)
    {
        PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
    }
}
  • Change a digit on 'TextBox1'
  • Select 'TextBox2'
  • Select 'TextBox1' and digit disappears.
@nmetulev
Copy link
Contributor

ping @IbraheemOsama

looks like, from my quick test, that the two way binding does not reflect the content of the textbox once the mask is applied

@nmetulev nmetulev added bug 🐛 An unexpected issue that highlights incorrect behavior controls 🎛️ labels Jun 20, 2017
@nmetulev nmetulev added this to the v1.5 milestone Jun 20, 2017
@IbraheemOsama IbraheemOsama self-assigned this Jun 20, 2017
@IbraheemOsama
Copy link
Member

@nmetulev this PR should solve this issue #1216

@nmetulev
Copy link
Contributor

That's great, just tested it with the fix and it seems to work as expected

@gpbicego
Copy link
Author

There are still some problems, I resolved by this way:

  • Move the block ‘Case change due to Text property is assigned a value (Ex Textbox.Text="value")’ before ‘Delete or backspace is triggered’ block.
  • Move the return outside the else block.
            // Case change due to Text property is assigned a value (Ex Textbox.Text="value")
            if (textbox.SelectionStart == 0 && textbox.FocusState == FocusState.Unfocused)
            {
                var displayText = textbox.GetValue(DefaultDisplayTextProperty) as string ?? string.Empty;
                if (string.IsNullOrEmpty(textbox.Text))
                {
                    textbox.Text = displayText;
                }
                else
                {
                    var textboxInitialValue = textbox.Text;
                    textbox.Text = displayText;
                    SetTextBoxValue(textboxInitialValue, textbox, mask, representationDictionary, placeHolderValue[0], 0);
                    textbox.SetValue(OldTextProperty, textbox.Text);
                }
                return;
            }

            // Delete or backspace is triggered

@nmetulev
Copy link
Contributor

ping @IbraheemOsama

@IbraheemOsama
Copy link
Member

@gpbicego what is the problems ? can you please elaborate. I you see that your code works please submit a Pull Request with your fix but describe the problem first :)

@ghost ghost locked as resolved and limited conversation to collaborators Nov 26, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug 🐛 An unexpected issue that highlights incorrect behavior controls 🎛️
Projects
None yet
Development

No branches or pull requests

4 participants