代码之家  ›  专栏  ›  技术社区  ›  Sekhat

双向数据绑定、Silverlight和自定义控件/依赖属性

  •  2
  • Sekhat  · 技术社区  · 14 年前

    IEnumerable<T> .

    例如,使用 IEnumerable<string> :

    public static readonly DependencyProperty MyCollectionProperty =
        DependencyProperty.Register("MyCollection", typeof(IEnumerable<string>), typeof(MyControl), new PropertyMetadata(new List<string>()));
    
    public IEnumerable<string> MyCollection
    {
         get { return (IEnumerable<string>)GetValue(MyCollectionProperty); }
         set { SetValue(MyCollectionProperty, value); }
    }
    

    ObservableCollection<T> <string>

    1 回复  |  直到 14 年前
        1
  •  0
  •   jsmith    14 年前

    MSDN

    ObservableCollection<T> 为您实现INotifyPropertyChanged。 IEnumerable<T> 没有。如果您想要简单的双向绑定,只需绑定到 可观测集合<T> UpdateSourceTrigger PropertyChanged

    <ItemSource = "{Binding Path=MyCollection, UpdateSourceTrigger=PropertyChanged}">