AvaloniaUI/Avalonia

PropertyChanged no longer works

mohdimas opened this issue · 1 comments

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