protected void Unbind(DataSourceReference dataSourceReference) { var idx = bindings.FindIndex(x => x.DataSourceReference == dataSourceReference); if (idx == -1) { return; } Unbind(idx, true); }
protected void Bind(DataSourceReference dataSourceReference, EventHandler handler, Action unbindCallback = null) { if (dataSourceReference?.Source == null) { return; } bindings.Add(new Entry { DataSourceReference = dataSourceReference, Handler = handler, UnbindCallback = unbindCallback }); dataSourceReference.Source.Changed += handler; handler?.Invoke(this, EventArgs.Empty); }
protected void BindCollection(DataSourceReference dataSourceReference, EventHandler <CollectionChangedEventArgs> handler, Action unbindCallback = null) { if (!(dataSourceReference?.Source is IDataSourceList dataSourceList)) { return; } bindings.Add(new Entry { DataSourceReference = dataSourceReference, CollectionHandler = handler, UnbindCallback = unbindCallback }); dataSourceList.CollectionChanged += handler; var i = 0; foreach (var item in dataSourceList) { handler.Invoke(dataSourceList, CollectionChangedEventArgs.ItemAdded(item, i++)); } }