コード例 #1
0
ファイル: NEventAggregator.cs プロジェクト: xstos/nreact
        public NEventAdapter this[NProperty key]
        {
            get
            {
                for (var i = _first; i != null; i = i.Next)
                {
                    if (ReferenceEquals(i.Property, key))
                    {
                        return(i);
                    }
                }

                return(null);
            }
            set
            {
                if (_first == null)
                {
                    _first = _last = value;
                }
                else
                {
                    _last.Next = value;
                    _last      = value;
                }
            }
        }
コード例 #2
0
ファイル: NEventAggregator.cs プロジェクト: xstos/nreact
        public static void AssignEvent(NProperty prop, object action, DependencyObject target, RoutedEvent routedEvent, Func <NEventAdapter, Delegate> extractor)
        {
            var handled = NEventAdapter.UnpackHandler(ref action);

            var agg = (NEventAggregator)target.GetValue(AggregatorProperty);

            if (agg == null)
            {
                target.SetValue(AggregatorProperty, agg = new NEventAggregator());
            }

            var adapter = agg[prop];

            if (adapter == null)
            {
                agg[prop] = adapter = new NEventAdapter(prop)
                {
                    Action = action
                };

                var handler = extractor(adapter);

                var e = target as UIElement;
                if (e != null)
                {
                    e.AddHandler(routedEvent, handler, handled);
                }
#if WPF
                else
                {
                    var ce = target as ContentElement;
                    if (ce != null)
                    {
                        ce.AddHandler(routedEvent, handler, true);
                    }
                }
#endif
            }
            else
            {
                adapter.Action = action;
            }
        }
コード例 #3
0
 public static NElement MouseLeftButtonDown(this NElement self, MouseEventHandler value, bool includeHandled = false)
 {
     return(self.Set(Properties.MouseLeftButtonDown, NEventAdapter.PackHandler(value, includeHandled)));
 }
コード例 #4
0
 public static NElement MouseLeftButtonUp(this NElement self, Action <object> value, bool includeHandled = false)
 {
     return(self.Set(Properties.MouseLeftButtonUp, NEventAdapter.PackHandler(value, includeHandled)));
 }
コード例 #5
0
 public static NElement PointerPressed(this NElement self, PointerEventHandler value, bool includeHandled = false)
 {
     return(self.Set(Properties.PointerPressed, NEventAdapter.PackHandler(value, includeHandled)));
 }
コード例 #6
0
ファイル: NEventAggregator.cs プロジェクト: xstos/nreact
        public static void AssignEvent <T>(NProperty prop, object action, T target, Action <T, NEventAdapter> subscribe) where T : class
        {
            var handled = NEventAdapter.UnpackHandler(ref action);

            if (handled)
            {
                throw new InvalidOperationException($"No support for handled events of {prop.Name}");
            }

#if XAML
            var dep = target as DependencyObject;
            if (dep != null)
            {
                var agg = (NEventAggregator)dep.GetValue(AggregatorProperty);
                if (agg == null)
                {
                    dep.SetValue(AggregatorProperty, agg = new NEventAggregator());
                }

                var adapter = agg[prop];
                if (adapter == null)
                {
                    agg[prop] = adapter = new NEventAdapter(prop)
                    {
                        Action = action
                    };
                    subscribe(target, adapter);
                }
                else
                {
                    adapter.Action = action;
                }
            }
            else
#elif XFORMS
            var dep = target as BindableObject;
            if (dep != null)
            {
                var agg = (NEventAggregator)dep.GetValue(AggregatorProperty);
                if (agg == null)
                {
                    dep.SetValue(AggregatorProperty, agg = new NEventAggregator());
                }

                var adapter = agg[prop];
                if (adapter == null)
                {
                    agg[prop] = adapter = new NEventAdapter(prop)
                    {
                        Action = action
                    };
                    subscribe(target, adapter);
                }
                else
                {
                    adapter.Action = action;
                }
            }
            else
#endif
            {
                subscribe(target, new NEventAdapter(prop)
                {
                    Action = action
                });
            }
        }