Ejemplo n.º 1
0
        internal static ControlProperty <T> Value <T, C>(C control, Func <C, T> getter, Action <C, T> setter) where C : UIControl
        {
            var source = Observable.Create <T>(observer =>
            {
                if (control == null)
                {
                    observer.OnCompleted();
                    return(Disposable.Empty);
                }
                observer.OnNext(getter(control));

                var controlTarget = new ControlTarget(control, (UIControlEvent.AllEditingEvents | UIControlEvent.ValueChanged),
                                                      c =>
                {
                    if (control == null)
                    {
                        return;
                    }
                    observer.OnNext(getter(control));
                });
                return(Disposable.Create(() => controlTarget.Dispose()));
            });
            var bindingObserver = new UIBindingObserver <C, T>(control, setter);

            return(new ControlProperty <T>(source, bindingObserver));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Returns An <c>IOBservable<T></c> instance for T when the <c>UIControlEvent is generated</c>
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="rx"></param>
        /// <param name="controlEvent"></param>
        /// <returns>An <c>IOBservable</c> instance for <c>T</c> when the <c>UIControlEvent</c> is generated</returns>
        public static ControlEvent <T> ControlEvent <T>(this Reactive <T> rx, UIControlEvent controlEvent) where T : UIControl
        {
            var source = Observable.Create <T>(observer =>
            {
                if (rx.Parent == null)
                {
                    observer.OnCompleted();
                    return(Disposable.Empty);
                }
                var controltarget = new ControlTarget(rx.Parent, controlEvent, uiControl => observer.OnNext(rx.Parent));
                return(Disposable.Create(() => controltarget.Dispose()));
            }); //.TakeUntil(self.deallocated?);

            return(new ControlEvent <T>(source));
        }