假设我有一节课:
class Foo
{
  public string Bar
  {
    get { ... }
  }
  public string this[int index]
  {
    get { ... }
  }
}
我可以使用"{Binding Path = Bar}"和"{Binding Path = [x]}"绑定到这两个属性.精细.
现在让我们说我想实现INotifyPropertyChanged:
class Foo : INotifyPropertyChanged
{
  public string Bar
  {
    get { ... }
    set
    {
      ...
      if( PropertyChanged != null )
      {
        PropertyChanged( this, new PropertyChangedEventArgs( "Bar" ) );
      }
    }
  }
  public string this[int index]
  {
    get { ... }
    set
    {
      ...
      if( PropertyChanged != null )
      {
        PropertyChanged( this, new PropertyChangedEventArgs( "????" ) );
      }
    }
  }
  public event PropertyChangedEventHandler PropertyChanged;
}
标记为?????的部分是什么?(我已经尝试过string.Format("[{0}]",索引)并且它不起作用).这是WPF中的一个错误,是否有替代语法,或者仅仅是INotifyPropertyChanged没有普通绑定那么强大?
stu*_*ith 13
感谢Cameron的建议,我找到了正确的语法,即:
Item[]
这会更新绑定到该索引属性的所有内容(所有索引值).
避免代码中的字符串,可以使用常量Binding.IndexerName,实际上是常量"Item[]"
new PropertyChangedEventArgs(Binding.IndexerName)
小智 5
PropertyChanged( this, new PropertyChangedEventArgs( "Item[]" ) )
对于所有索引和
PropertyChanged( this, new PropertyChangedEventArgs( "Item[" + index + "]" ) )
对于单个项目
问候,jerod
| 归档时间: | 
 | 
| 查看次数: | 6876 次 | 
| 最近记录: |