示例#1
0
 public void AddTargetMakeDirty()
 {
     using (var ctrl = new UIControl()) {
         ctrl.AddTarget((a, b) => { }, UIControlEvent.EditingDidBegin);
         Assert.IsTrue((TestRuntime.GetFlags(ctrl) & 0x8) /* RegisteredToggleRef */ == 0x8, "RegisteredToggleRef");
     }
 }
        public static IDisposable BindToTarget(this ICommand This, UIControl control, UIControlEvent events)
        {
            var ev = new EventHandler((o, e) => {
                if (!This.CanExecute(null))
                {
                    return;
                }
                This.Execute(null);
            });

            var cech = new EventHandler((o, e) => {
                var canExecute  = This.CanExecute(null);
                control.Enabled = canExecute;
            });

            This.CanExecuteChanged += cech;
            control.AddTarget(ev, events);

            control.Enabled = This.CanExecute(null);

            return(Disposable.Create(() => {
                control.RemoveTarget(ev, events);
                This.CanExecuteChanged -= cech;
            }));
        }
示例#3
0
        public void AddTargetTable()
        {
            const int items   = 100;
            var       handles = new GCHandle [items];
            var       handler = new EventHandler(delegate(object sender, EventArgs e) {
            });

            for (int i = 0; i < items; i++)
            {
                var ctrl = new UIControl();
                ctrl.AddTarget(handler, UIControlEvent.EditingChanged);
                handles [i] = GCHandle.Alloc(ctrl, GCHandleType.Weak);
            }
            GC.Collect();

            // If at least one object was collected, then we know the static ConditionalWeakTable
            // of object -> event handlers doesn't keep strong references.
            var any_collected = false;

            for (int i = 0; i < items; i++)
            {
                if (handles [i].Target == null)
                {
                    any_collected = true;
                }
                handles [i].Free();
            }
            Assert.IsTrue(any_collected, "Nothing collected");
        }
示例#4
0
 internal ControlTarget(UIControl control, UIControlEvent controlEvent, Action <UIControl> callback)
 {
     _control      = control;
     _controlEvent = controlEvent;
     _callback     = callback;
     control.AddTarget(EventHandler, controlEvent);
 }
        public static IDisposable BindToTarget(this ICommand This, UIControl control, UIControlEvent events)
        {
            var ev = new EventHandler((o,e) => {
                if (!This.CanExecute(null)) return;
                This.Execute(null);
            });

            control.AddTarget(ev, events);
            return Disposable.Create(() => control.RemoveTarget(ev, events));
        }
        public static IDisposable BindToTarget(this ICommand This, UIControl control, UIControlEvent events)
        {
            var ev = new EventHandler((o, e) => {
                if (!This.CanExecute(null))
                {
                    return;
                }
                This.Execute(null);
            });

            control.AddTarget(ev, events);
            return(Disposable.Create(() => control.RemoveTarget(ev, events)));
        }
        public static IDisposable BindToTarget(this ICommand This, UIControl control, UIControlEvent events)
        {
            var ev = new EventHandler((o,e) => {
                if (!This.CanExecute(null)) return;
                This.Execute(null);
            });

            var cech = new EventHandler((o, e) => {
                var canExecute = This.CanExecute(null);
                control.Enabled = canExecute;
            });

            This.CanExecuteChanged += cech;
            control.AddTarget(ev, events);

            control.Enabled = This.CanExecute(null);

            return Disposable.Create(() => {
                control.RemoveTarget(ev, events);
                This.CanExecuteChanged -= cech;
            });
        }
示例#8
0
    /// <summary>
    /// Binds the <see cref="ICommand"/> to target <see cref="UIControl"/>.
    /// </summary>
    /// <param name="item">The command to bind to.</param>
    /// <param name="control">The control.</param>
    /// <param name="events">The events.</param>
    /// <returns>A disposable.</returns>
    public static IDisposable BindToTarget(this ICommand item, UIControl control, UIControlEvent events)
    {
        if (item is null)
        {
            throw new ArgumentNullException(nameof(item));
        }

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

        var ev = new EventHandler((o, e) =>
        {
            if (!item.CanExecute(null))
            {
                return;
            }

            item.Execute(null);
        });

        var cech = new EventHandler((o, e) =>
        {
            control.Enabled = item.CanExecute(null);
        });

        item.CanExecuteChanged += cech;
        control.AddTarget(ev, events);

        control.Enabled = item.CanExecute(null);

        return(Disposable.Create(() =>
        {
            control.RemoveTarget(ev, events);
            item.CanExecuteChanged -= cech;
        }));
    }