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

PropertyChanged triggered on empty string #872

Open
1 of 4 tasks
karmeye opened this issue Apr 27, 2024 · 3 comments
Open
1 of 4 tasks

PropertyChanged triggered on empty string #872

karmeye opened this issue Apr 27, 2024 · 3 comments
Labels
bug 🐛 An unexpected issue that highlights incorrect behavior

Comments

@karmeye
Copy link

karmeye commented Apr 27, 2024

Describe the bug

The following returns false even though both are empty strings

if (!global::System.Collections.Generic.EqualityComparer<string?>.Default.Equals(myString, value))

Regression

No response

Steps to reproduce

1. <TextBox Text="{x:Bind MyString, Mode=TwoWay}" />
2. Leave empty and tab in and out.
3. `OnPropertyChanged` (and the other methods) is called

Expected behavior

PropertyChanged should not be triggered when the new value is an empty string for a current empty string value.

Screenshots

No response

IDE and version

VS 2022

IDE version

No response

Nuget packages

  • CommunityToolkit.Common
  • CommunityToolkit.Diagnostics
  • CommunityToolkit.HighPerformance
  • CommunityToolkit.Mvvm (aka MVVM Toolkit)

Nuget package version(s)

8.2.2

Additional context

No response

Help us help you

No, just wanted to report this

@karmeye karmeye added the bug 🐛 An unexpected issue that highlights incorrect behavior label Apr 27, 2024
@jhm-ciberman
Copy link

I copypasted the line you mentioned in a REPL console, and it works as expected. Are you sure you are not triggering something else that is causing the OnPropertyChanged to being called?

image

@karmeye
Copy link
Author

karmeye commented May 3, 2024

Ok, what happens is that the first time I tab out of the text box, Text (i.e. the binding) is null and this triggers PropertyChanged, as null and empty string is not considered equal. Just by tabbing in and out of the text box, the textbox changes the binding value from null to empty string. After that OnPropertyChanged is not called any more.

I guess we can remove the bug label.

@karmeye
Copy link
Author

karmeye commented May 3, 2024

I don't really want the TextBox to change the value, as it is represented as null rather than empty string in the database.

Is there a way to conditionally prevent a control from updating the binding?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 An unexpected issue that highlights incorrect behavior
Projects
None yet
Development

No branches or pull requests

2 participants