Skip to content

Dictionary index binding does not detect changes #20313

Description

@mgarstenauer

Describe the bug

When I bind an entry of an observable dictionary using "{Binding Dictionary[Key]}", it does not detect changes.

To Reproduce

  • Create a new Avalonia MVVM app.
  • Add a view model property with an AvaloniaDictionary (or other observable dictionary).
public partial class MainWindowViewModel : ViewModelBase
{
    ...
    public AvaloniaDictionary<string, string> Dictionary { get; } = new();
    ...
}
  • Bind a dictionary entry in the view.
<Window ...>
    ...
    <TextBlock Text="{Binding Dictionary[MyKey]}" />
    ...
</Window>
  • Now programmatically change the value of Dictionary["MyKey"].

Result: The UI does not detect the change. The TextBlock.Text is not updated.

Expected behavior

The AvaloniaDictionary implements INotifyPropertyChanged and INotifyCollectionChanged, therefore I expect the UI to detect changes and update the UI text.

Avalonia version

11.3.10

OS

Windows

Additional context

It works when the observable dictionary raises a PropertyChanged event with new PropertyChangedEventArgs("Item"). It does not work with new PropertyChangedEventArgs("Item[]").

Note that binding an ObservableCollection with {Binding List[0]}" is working fine. It is only a problem with dictionaries.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions