public TransformingListBinding(IReadOnlyObservableListBinding <TSource> parent, Func <TSource, TTarget> mappingFunction) { this.parent = parent ?? throw new ArgumentNullException(nameof(parent)); this.mappingFunction = mappingFunction ?? throw new ArgumentNullException(nameof(mappingFunction)); this.parent.PropertyChanged += OnParentPropertyChanged; this.parent.CollectionChanged += OnParentCollectionChanged; }
public static IReadOnlyObservableListBinding <T> RangeBinding <T>(this IReadOnlyObservableListBinding <T> source, int index, int count) { if (count < 0) { throw new ArgumentOutOfRangeException(nameof(count), count, "cannot be negative"); } if (index < 0) { throw new ArgumentOutOfRangeException(nameof(count), count, "cannot be negative"); } var data = new List <T>(); return(new BulkChangeListBinding <T>(source, (l) => { data.Clear(); if (index < l.Count) { var max = Math.Min(l.Count - index, count); for (var i = 0; i < max; i += 1) { data.Add(l[i + index]); } } return data; })); }
public BulkChangeListBinding(IReadOnlyObservableListBinding <T> parent, Func <IReadOnlyList <T>, IReadOnlyList <T> > onChange) { this.parent = parent ?? throw new ArgumentNullException(nameof(parent)); this.onChange = onChange ?? throw new ArgumentNullException(nameof(onChange)); this.parent.PropertyChanged += OnParentPropertyChanged; this.data = onChange(parent) ?? empty; }
public WidgetSink(IReadOnlyObservableListBinding <WidgetAndConstraint <TConstraint> > sourceList, WidgetContainer <TConstraint> target) : base(sourceList, target) { if (target.Count != 0) { throw new InvalidOperationException("Cannot bind to a widget that already contains other content."); } target.ChildrenChanged += OnValidateChildrenChanged; SourceList.CollectionChanged += CheckedChangeHandler; }
public static IReadOnlyObservableValue <T> Last <T>(this IReadOnlyObservableListBinding <T> source, T defaultValue = default(T)) { T ConditionalGet(IReadOnlyObservableListBinding <T> l) { if (l.Count > 0) { return(l[l.Count - 1]); } return(defaultValue); } var constBinding = new ConstBinding <IReadOnlyObservableListBinding <T> >(source); return(new TypeSafePropertyBinding <IReadOnlyObservableListBinding <T>, T>(constBinding, IndexerName, ConditionalGet)); }
public static IReadOnlyObservableListBinding <T> OrderByBinding <T>(this IReadOnlyObservableListBinding <T> source, IComparer <T> c = null) { if (c == null) { c = Comparer <T> .Default; } var data = new List <T>(); return(new BulkChangeListBinding <T>(source, (l) => { if (!ReferenceEquals(data, l)) { data.Clear(); data.AddRange(l); } data.Sort(c); return data; })); }
public static IBindingSubscription BindTo <TConstraint>( this IReadOnlyObservableListBinding <WidgetAndConstraint <TConstraint> > self, WidgetContainer <TConstraint> widget) { return(new WidgetSink <TConstraint>(self, widget)); }
public static IBindingSubscription BindTo <T>(this IReadOnlyObservableListBinding <T> source, ObservableCollection <T> target) { return(source.BindTo(target.ToBinding())); }
public static IBindingSubscription BindTo <T>(this IReadOnlyObservableListBinding <T> source, IObservableListBinding <T> target) { return(new OneWayObservableListBinding <T>(target, source)); }
public WidgetContainerSynchronizer(IReadOnlyObservableListBinding <WidgetAndConstraint <TConstraint> > sourceList, WidgetContainer <TConstraint> target) { SourceList = sourceList ?? throw new ArgumentNullException(nameof(sourceList)); Target = target ?? throw new ArgumentNullException(nameof(target)); }
public static IReadOnlyObservableValue <T> First <T>(this IReadOnlyObservableListBinding <T> source, T defaultValue = default(T)) { return(source.ItemAt(0, defaultValue)); }
public ListSynchronizer(IReadOnlyObservableListBinding <T> sourceList, IObservableListBinding <T> target) { SourceList = sourceList ?? throw new ArgumentNullException(nameof(sourceList)); Target = target ?? throw new ArgumentNullException(nameof(target)); }
public static IReadOnlyObservableListBinding <T> MapAll <T>(this IReadOnlyObservableListBinding <T> source, Func <IReadOnlyList <T>, IReadOnlyList <T> > transform) { return(new BulkChangeListBinding <T>(source, transform)); }
public static IReadOnlyObservableListBinding <TTarget> Map <TSource, TTarget>( this IReadOnlyObservableListBinding <TSource> source, Func <TSource, TTarget> mapper) { return(new TransformingListBinding <TSource, TTarget>(source, mapper)); }
public static IReadOnlyObservableValue <IReadOnlyList <T> > ItemsBinding <T>( this IReadOnlyObservableListBinding <T> self) { return(self.BindingFor(IndexerName, s => s.ToArray())); }
public static IReadOnlyObservableValue <int> CountBinding <T>(this IReadOnlyObservableListBinding <T> self) { return(self.BindingFor(s => s.Count)); }
internal ListEnumerator(IReadOnlyObservableListBinding <T> widget) : this() { this.widget = widget; index = -1; current = default(T); }
public OneWayObservableListBinding(IObservableListBinding <T> target, IReadOnlyObservableListBinding <T> sourceList) { this.Target = target ?? throw new ArgumentNullException(nameof(target)); this.SourceList = sourceList ?? throw new ArgumentNullException(nameof(sourceList)); this.SourceList.CollectionChanged += OnSourceCollectionChanged; }