Binding to indexer #17832
-
Hello, I would like to create a view model, that implements 'string this[string key] { get; set; }' indexing or provides property <TextBox Text="{Binding [Text1]}"/> or <TextBox Text="{Binding Values[Text1]}"/> That works fine and correct values are shown. But now I need to change the value for [Text1] or Values[Text1] and trigger NotifyPropertyChanged event by calling What name should I use as |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
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 In avalonia code in |
Beta Was this translation helpful? Give feedback.
This could work:
In xaml:
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.