Esempio n. 1
0
        public IReactiveBinding <TView, TViewModel, TProp> BindCommand <TView, TViewModel, TProp, TControl, TParam>(
            TViewModel viewModel,
            TView view,
            Expression <Func <TViewModel, TProp> > propertyName,
            Expression <Func <TView, TControl> > controlName,
            Func <TParam> withParameter,
            string toEvent = null)
            where TViewModel : class
            where TView : class, IViewFor <TViewModel>
            where TProp : ICommand
        {
            var ctlName        = Reflection.SimpleExpressionToPropertyName(controlName);
            var viewPropGetter = Reflection.GetValueFetcherForProperty(typeof(TView), ctlName);

            IObservable <TProp> changed;
            IDisposable         bindingDisposable = bindCommandInternal(viewModel, view, propertyName, viewPropGetter, Observable.Empty <object>(), toEvent, out changed, cmd => {
                var rc = cmd as IReactiveCommand;
                if (rc == null)
                {
                    return(Legacy.ReactiveCommand.Create(x => cmd.CanExecute(x), _ => cmd.Execute(withParameter())));
                }

                var ret = new ReactiveCommand(rc.CanExecuteObservable);
                ret.Subscribe(_ => rc.Execute(withParameter()));
                return(ret);
            });

            return(new ReactiveBinding <TView, TViewModel, TProp>(view, viewModel, new string[] { ctlName }, new string[] { Reflection.SimpleExpressionToPropertyName(propertyName) },
                                                                  changed, BindingDirection.OneWay, bindingDisposable));
        }
Esempio n. 2
0
        /// <summary>
        /// This creates a ReactiveCommand that calls several child
        /// ReactiveCommands when invoked. Its CanExecute will match the
        /// combined result of the child CanExecutes (i.e. if any child
        /// commands cannot execute, neither can the parent)
        /// </summary>
        /// <param name="canExecute">An Observable that determines whether the
        /// parent command can execute</param>
        /// <param name="commands">The commands to combine.</param>
        public static ReactiveCommand CreateCombined(IObservable <bool> canExecute, params ReactiveCommand[] commands)
        {
            var childrenCanExecute = commands
                                     .Select(x => x.CanExecuteObservable)
                                     .CombineLatest(latestCanExecute => latestCanExecute.All(x => x != false));

            var canExecuteSum = Observable.CombineLatest(
                canExecute.StartWith(true),
                childrenCanExecute,
                (parent, child) => parent && child);

            var ret = new ReactiveCommand(canExecuteSum);

            ret.Subscribe(x => commands.ForEach(cmd => cmd.Execute(x)));
            return(ret);
        }
 /// <inheritdoc/>
 public override IDisposable Subscribe(IObserver <IList <TResult> > observer) => _innerCommand.Subscribe(observer);