Skip to content

Binding to indexer #17832

Answered by msneijders
asmirnov82 asked this question in Q&A
Dec 26, 2024 · 1 comments · 1 reply
Discussion options

You must be logged in to vote

This could work:

class ViewModel: INotifyPropertyChanged
{
    Dictionary<string, string> _items = new Dictionary<string, string>()
    {
        { "key1", "value1" },
        { "key2", "value2" },
        { "key3", "value3" },
    };

    public string this[string key]
    {
        get
        {
            return _items[key];
        }

        set
        {
            _items[key] = value;
            base.OnPropertyChanged("Item");
        }
    }
}

In xaml:

<TextBox Text="{Binding [key1]}" />

So using Item as property name.

In avalonia code in AvaloniaDictionary, I also see the use of "Item[key1]", but I could not get it to work using that.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@asmirnov82
Comment options

Answer selected by asmirnov82
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants