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 no longer works #17674

Open
mohdimas opened this issue Dec 3, 2024 · 1 comment
Open

PropertyChanged no longer works #17674

mohdimas opened this issue Dec 3, 2024 · 1 comment
Labels

Comments

@mohdimas
Copy link

mohdimas commented Dec 3, 2024

Describe the bug

Calling OnPropertyChanged to update the UI so it matches the underlying property no longer works.

Xaml:

<CheckBox Content="Bound to IsChecked"
        HorizontalAlignment="Center"
        VerticalAlignment="Center"
        IsChecked="{Binding IsChecked, Mode=OneWay}" />
<TextBlock Text="{Binding IsChecked, StringFormat='Actual IsChecked value: {0}'}" />
<Button Content="Raise property changed"
        Command="{Binding RaisePropertyChangedCommand}" />

VM:

private bool _isChecked;
public bool IsChecked
{
        get => _isChecked;
        set
        {
                _isChecked = value;
                OnPropertyChanged();
        }
}
public RelayCommand RaisePropertyChangedCommand { get; }

public MainWindowViewModel()
{
        RaisePropertyChangedCommand = new RelayCommand(ExecuteRaisePropertyChanged);
}

private void ExecuteRaisePropertyChanged()
{
        OnPropertyChanged(nameof(IsChecked));
}

To Reproduce

  1. Run the test repository
  2. Check the checkbox so the UI is checked. But as it's one-way binding, so the underlying property is not updated
  3. Click the button to call OnropertyChanged.
  4. The expected behavior should update the UI to match the underlying property but it doesnt work

Kapture 2024-12-03 at 11 19 34

Expected behavior

On Avalonia 11.0.13 it still works (TestRepo)

Kapture 2024-12-03 at 11 12 41

Avalonia version

11.1.0 and above including latest nightly build

OS

macOS

Additional context

No response

@mohdimas mohdimas added the bug label Dec 3, 2024
@stevemonaco
Copy link
Contributor

I can repro on nightly (11.3.999-cibuild0053693-alpha), so this seems to be a breaking change in the 11.1 binding refactor.

PropertyChanged seems to be squashed when the source value hasn't changed from the prior PropertyChanged event. Perhaps an optimization for most scenarios as OneWay is typically used for control properties that the control itself does not mutate?

Repro works as expected when you propagate hard changes. ie.

private void ExecuteRaisePropertyChanged()
{
    IsChecked ^= true;
    IsChecked ^= true;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants