コード例 #1
0
        protected void Unbind(DataSourceReference dataSourceReference)
        {
            var idx = bindings.FindIndex(x => x.DataSourceReference == dataSourceReference);

            if (idx == -1)
            {
                return;
            }

            Unbind(idx, true);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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++));
            }
        }