示例#1
0
 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;
 }
示例#2
0
        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;
            }));
        }
示例#3
0
 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;
 }
示例#4
0
        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;
        }
示例#5
0
        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));
        }
示例#6
0
        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;
            }));
        }
示例#7
0
 public static IBindingSubscription BindTo <TConstraint>(
     this IReadOnlyObservableListBinding <WidgetAndConstraint <TConstraint> > self,
     WidgetContainer <TConstraint> widget)
 {
     return(new WidgetSink <TConstraint>(self, widget));
 }
示例#8
0
 public static IBindingSubscription BindTo <T>(this IReadOnlyObservableListBinding <T> source,
                                               ObservableCollection <T> target)
 {
     return(source.BindTo(target.ToBinding()));
 }
示例#9
0
 public static IBindingSubscription BindTo <T>(this IReadOnlyObservableListBinding <T> source,
                                               IObservableListBinding <T> target)
 {
     return(new OneWayObservableListBinding <T>(target, source));
 }
示例#10
0
 public WidgetContainerSynchronizer(IReadOnlyObservableListBinding <WidgetAndConstraint <TConstraint> > sourceList,
                                    WidgetContainer <TConstraint> target)
 {
     SourceList = sourceList ?? throw new ArgumentNullException(nameof(sourceList));
     Target     = target ?? throw new ArgumentNullException(nameof(target));
 }
示例#11
0
 public static IReadOnlyObservableValue <T> First <T>(this IReadOnlyObservableListBinding <T> source, T defaultValue = default(T))
 {
     return(source.ItemAt(0, defaultValue));
 }
示例#12
0
 public ListSynchronizer(IReadOnlyObservableListBinding <T> sourceList, IObservableListBinding <T> target)
 {
     SourceList = sourceList ?? throw new ArgumentNullException(nameof(sourceList));
     Target     = target ?? throw new ArgumentNullException(nameof(target));
 }
示例#13
0
 public static IReadOnlyObservableListBinding <T> MapAll <T>(this IReadOnlyObservableListBinding <T> source,
                                                             Func <IReadOnlyList <T>, IReadOnlyList <T> > transform)
 {
     return(new BulkChangeListBinding <T>(source, transform));
 }
示例#14
0
 public static IReadOnlyObservableListBinding <TTarget> Map <TSource, TTarget>(
     this IReadOnlyObservableListBinding <TSource> source,
     Func <TSource, TTarget> mapper)
 {
     return(new TransformingListBinding <TSource, TTarget>(source, mapper));
 }
示例#15
0
 public static IReadOnlyObservableValue <IReadOnlyList <T> > ItemsBinding <T>(
     this IReadOnlyObservableListBinding <T> self)
 {
     return(self.BindingFor(IndexerName, s => s.ToArray()));
 }
示例#16
0
 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);
 }
示例#18
0
 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;
 }