コード例 #1
0
        private IDisposable BindCommandInternal <TView, TProp, TParam>(
            IObservable <TProp> @this,
            TView view,
            Expression controlExpression,
            IObservable <TParam> withParameter,
            string toEvent,
            Func <ICommand, ICommand> commandFixuper = null)
            where TView : class, IViewFor
            where TProp : ICommand
        {
            IDisposable disp = Disposable.Empty;

            var bindInfo = Observable.CombineLatest(
                @this,
                view.SubscribeToExpressionChain <TView, object>(controlExpression, false, false, RxApp.SuppressViewCommandBindingMessage).Select(x => x.Value),
                (val, host) => new { val, host });

            var propSub = bindInfo
                          .Where(x => x.host != null)
                          .Subscribe(x =>
            {
                disp.Dispose();
                if (x == null)
                {
                    disp = Disposable.Empty;
                    return;
                }

                var cmd = commandFixuper != null ? commandFixuper(x.val) : x.val;
                if (toEvent != null)
                {
                    disp = CreatesCommandBinding.BindCommandToObject(cmd, x.host, withParameter.Select(y => (object)y), toEvent);
                }
                else
                {
                    disp = CreatesCommandBinding.BindCommandToObject(cmd, x.host, withParameter.Select(y => (object)y));
                }
            });

            return(Disposable.Create(() =>
            {
                propSub.Dispose();
                disp.Dispose();
            }));
        }