How do I use INotifyPropertyChanged to update an array binding?

前端 未结 4 1431
再見小時候
再見小時候 2021-02-04 08:04

Let\'s say I have a class:

class Foo
{
  public string Bar
  {
    get { ... }
  }

  public string this[int index]
  {
    get { ... }
  }
}

I

相关标签:
4条回答
  • 2021-02-04 08:13

    Don't know for sure if this'll work, but reflector shows that the get and set methods for an indexed property are called get_Item and set_Item. Perhaps you could try Item and see if that works.

    0 讨论(0)
  • 2021-02-04 08:23

    Avoiding strings in your code, you can use the constant Binding.IndexerName, which is actually "Item[]"

    new PropertyChangedEventArgs(Binding.IndexerName)
    
    0 讨论(0)
  • 2021-02-04 08:28
    PropertyChanged( this, new PropertyChangedEventArgs( "Item[]" ) )
    

    for all indexes and

    PropertyChanged( this, new PropertyChangedEventArgs( "Item[" + index + "]" ) )
    

    for a single item

    greetings, jerod

    0 讨论(0)
  • 2021-02-04 08:37

    Thanks to Cameron's suggestion, I've found the correct syntax, which is:

    Item[]
    

    Which updates everything (all index values) bound to that indexed property.

    0 讨论(0)
提交回复
热议问题