コード例 #1
0
        /// <summary>
        /// <para>Extension method that binds an observable of a list of table
        /// sections as the source of a <see cref="UITableView"/>.</para>
        /// <para>If your <see cref="IReadOnlyList{T}"/> is also an instance of
        /// <see cref="INotifyCollectionChanged"/>, then this method
        /// will silently update the bindings whenever it changes as well.
        /// Otherwise, it will just log a message.</para>
        /// </summary>
        /// <returns>The <see cref="IDisposable"/> used to dispose this binding.</returns>
        /// <param name="sectionsObservable">Sections observable.</param>
        /// <param name="tableView">Table view.</param>
        /// <param name="initSource">Optionally initializes some property of
        /// the <see cref="ReactiveTableViewSource{TSource}"/>.</param>
        /// <typeparam name="TSource">The source type.</typeparam>
        /// <typeparam name="TCell">Type of the <see cref="UITableViewCell"/>.</typeparam>
        public static IDisposable BindTo <TSource, TCell>(
            this IObservable <IReadOnlyList <TableSectionInformation <TSource, TCell> > > sectionsObservable,
            UITableView tableView,
            Func <ReactiveTableViewSource <TSource>, IDisposable>?initSource = null)
            where TCell : UITableViewCell
        {
            if (sectionsObservable is null)
            {
                throw new ArgumentNullException(nameof(sectionsObservable));
            }

            if (tableView is null)
            {
                throw new ArgumentNullException(nameof(tableView));
            }

            var source = new ReactiveTableViewSource <TSource>(tableView);

            if (initSource is not null)
            {
                initSource(source);
            }

            var bind = sectionsObservable.BindTo(source, x => x.Data);

            tableView.Source = source;

            return(new CompositeDisposable(bind, source));
        }
コード例 #2
0
 public static void Bind <T>(this IBinder This, IObservable <T> source, IPresenter target)
 {
     if (target != null)
     {
         source.BindTo(target).AddTo(This);
     }
 }
コード例 #3
0
ファイル: IViewForExt.cs プロジェクト: Jeremy-Laier/wabbajack
 public static IDisposable BindToStrict <TValue, TTarget>(
     this IObservable <TValue> @this,
     TTarget target,
     Expression <Func <TTarget, TValue> > property)
     where TTarget : class
 {
     return(@this.BindTo <TValue, TTarget, TValue>(target, property));
 }
コード例 #4
0
        /// <summary>
        /// Extension method that binds an observable of a collection
        /// as the source of a <see cref="UICollectionView"/>.  Also registers
        /// the given class with an unspecified cellKey (you should probably
        /// not specify any other cellKeys).
        /// </summary>
        /// <returns>The <see cref="IDisposable"/> used to dispose this binding.</returns>
        /// <param name="sourceObservable">Source collection observable.</param>
        /// <param name="collectionView">Collection view.</param>
        /// <param name="initializeCellAction">Initialize cell action.</param>
        /// <param name="initSource">Optionally initializes some property of
        /// the <see cref="ReactiveCollectionViewSource"/>.</param>
        /// <typeparam name="TCell">Type of the <see cref="UICollectionViewCell"/>.</typeparam>
        public static IDisposable BindTo <TCell>(
            this IObservable <IReactiveNotifyCollectionChanged> sourceObservable,
            UICollectionView collectionView,
            Action <TCell> initializeCellAction = null,
            Func <ReactiveCollectionViewSource, IDisposable> initSource = null)
            where TCell : UICollectionViewCell
        {
            var type    = typeof(TCell);
            var cellKey = new NSString(type.ToString());

            collectionView.RegisterClassForCell(type, new NSString(cellKey));
            return(sourceObservable
                   .BindTo(collectionView, cellKey, initializeCellAction, initSource));
        }
コード例 #5
0
        /// <summary>
        /// <para>Extension method that binds an observable of a list of collection
        /// sections as the source of a <see cref="UICollectionView"/>.</para>
        /// <para>If your <see cref="IReadOnlyList{T}"/> is also an instance of
        /// <see cref="IReactiveNotifyCollectionChanged{T}"/>, then this method
        /// will silently update the bindings whenever it changes as well.
        /// Otherwise, it will just log a message.</para>
        /// </summary>
        /// <returns>The <see cref="IDisposable"/> used to dispose this binding.</returns>
        /// <param name="sectionsObservable">Sections observable.</param>
        /// <param name="collectionView">Collection view.</param>
        /// <param name="initSource">Optionally initializes some property of
        /// the <see cref="ReactiveCollectionViewSource{TSource}"/>.</param>
        /// <typeparam name="TSource">Type of the view source.</typeparam>
        /// <typeparam name="TCell">Type of the <see cref="UICollectionViewCell"/>.</typeparam>
        public static IDisposable BindTo <TSource, TCell>(
            this IObservable <IReadOnlyList <CollectionViewSectionInformation <TSource, TCell> > > sectionsObservable,
            UICollectionView collectionView,
            Func <ReactiveCollectionViewSource <TSource>, IDisposable> initSource = null)
            where TCell : UICollectionViewCell
        {
            var source = new ReactiveCollectionViewSource <TSource>(collectionView);

            initSource?.Invoke(source);

            var bind = sectionsObservable.BindTo(source, x => x.Data);

            collectionView.Source = source;
            return(new CompositeDisposable(bind, source));
        }
コード例 #6
0
        /// <summary>
        /// Extension method that binds an observable of a collection
        /// as the source of a <see cref="UITableView"/>.  Also registers
        /// the given class with an unspecified cellKey (you should probably
        /// not specify any other cellKeys).
        /// </summary>
        /// <returns>The <see cref="IDisposable"/> used to dispose this binding.</returns>
        /// <param name="sourceObservable">Source collection observable.</param>
        /// <param name="tableView">Table view.</param>
        /// <param name="sizeHint">Size hint.</param>
        /// <param name="initializeCellAction">Initialize cell action.</param>
        /// <param name="initSource">Optionally initializes some property of
        /// the <see cref="ReactiveTableViewSource{TSource}"/>.</param>
        /// <typeparam name="TSource">The source type.</typeparam>
        /// <typeparam name="TCell">Type of the <see cref="UITableViewCell"/>.</typeparam>
        public static IDisposable BindTo <TSource, TCell>(
            this IObservable <INotifyCollectionChanged> sourceObservable,
            UITableView tableView,
            float sizeHint,
            Action <TCell> initializeCellAction = null,
            Func <ReactiveTableViewSource <TSource>, IDisposable> initSource = null)
            where TCell : UITableViewCell
        {
            var type    = typeof(TCell);
            var cellKey = new NSString(type.ToString());

            tableView.RegisterClassForCellReuse(type, new NSString(cellKey));

            return(sourceObservable
                   .BindTo(tableView, cellKey, sizeHint, initializeCellAction, initSource));
        }
コード例 #7
0
        /// <summary>
        /// <para>Extension method that binds an observable of a list of table
        /// sections as the source of a <see cref="UITableView"/>.</para>
        /// <para>If your <see cref="IReadOnlyList"/> is also an instance of
        /// <see cref="IReactiveNotifyCollectionChanged"/>, then this method
        /// will silently update the bindings whenever it changes as well.
        /// Otherwise, it will just log a message.</para>
        /// </summary>
        /// <returns>The <see cref="IDisposable"/> used to dispose this binding.</returns>
        /// <param name="sectionsObservable">Sections observable.</param>
        /// <param name="tableView">Table view.</param>
        /// <param name="initSource">Optionally initializes some property of
        /// the <see cref="ReactiveTableViewSource"/>.</param>
        /// <typeparam name="TCell">Type of the <see cref="UITableViewCell"/>.</typeparam>
        public static IDisposable BindTo <TCell>(
            this IObservable <IReadOnlyList <TableSectionInformation <TCell> > > sectionsObservable,
            UITableView tableView,
            Func <ReactiveTableViewSource, IDisposable> initSource = null)
            where TCell : UITableViewCell
        {
            var source = new ReactiveTableViewSource(tableView);

            if (initSource != null)
            {
                initSource(source);
            }
            var bind = sectionsObservable.BindTo(source, x => x.Data);

            tableView.Source = source;
            return(new CompositeDisposable(bind, source));
        }
コード例 #8
0
        /// <summary>
        /// Extension method that binds an observable of a collection
        /// as the source of a <see cref="UICollectionView"/>.  Also registers
        /// the given class with an unspecified cellKey (you should probably
        /// not specify any other cellKeys).
        /// </summary>
        /// <returns>The <see cref="IDisposable"/> used to dispose this binding.</returns>
        /// <param name="sourceObservable">Source collection observable.</param>
        /// <param name="collectionView">Collection view.</param>
        /// <param name="initializeCellAction">Initialize cell action.</param>
        /// <param name="initSource">Optionally initializes some property of
        /// the <see cref="ReactiveCollectionViewSource{TSource}"/>.</param>
        /// <typeparam name="TSource">Type of the source.</typeparam>
        /// <typeparam name="TCell">Type of the <see cref="UICollectionViewCell"/>.</typeparam>
        public static IDisposable BindTo <TSource, TCell>(
            this IObservable <INotifyCollectionChanged> sourceObservable,
            UICollectionView collectionView,
            Action <TCell>?initializeCellAction = null,
            Func <ReactiveCollectionViewSource <TSource>, IDisposable>?initSource = null)
            where TCell : UICollectionViewCell
        {
            if (collectionView == null)
            {
                throw new ArgumentNullException(nameof(collectionView));
            }

            var type    = typeof(TCell);
            var cellKey = new NSString(type.ToString());

            collectionView.RegisterClassForCell(type, new NSString(cellKey));
            return(sourceObservable
                   .BindTo(collectionView, cellKey, initializeCellAction, initSource));
        }
コード例 #9
0
 public static void Bind <TSource, TTarget>(this IBinder This, IObservable <TSource> source, IReactiveProperty <TTarget> target)
     where TTarget : TSource =>
 source.BindTo(target).AddTo(This);