Ejemplo n.º 1
0
        /// <summary>
        /// Detaches the currently associated instance
        /// </summary>
        public void Detach()
        {
            if (this.AssociatedObject != null)
            {
                EventWrapper eventHooker = new EventWrapper(this);
                eventHooker.AssociatedObject = this.AssociatedObject;
                EventInfo eventInfo = GetEventInfo(this.AssociatedObject.GetType(), this.EventName);
                Delegate  handler   = eventHooker.GetEventHandler(eventInfo);

                WindowsRuntimeMarshal.RemoveEventHandler <Delegate>(
                    etr => eventInfo.RemoveMethod.Invoke(this.AssociatedObject, new object[] { etr }), handler);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Attaches an instance of a DependencyObject to this instance
        /// </summary>
        /// <param name="dependencyObject">The instance to attach</param>
        public void Attach(DependencyObject dependencyObject)
        {
            this.AssociatedObject = dependencyObject;

            if (!string.IsNullOrEmpty(this.EventName))
            {
                EventWrapper eventHooker = new EventWrapper(this);
                eventHooker.AssociatedObject = dependencyObject;
                EventInfo eventInfo = GetEventInfo(dependencyObject.GetType(), this.EventName);

                if (eventInfo != null)
                {
                    Delegate handler = eventHooker.GetEventHandler(eventInfo);

                    WindowsRuntimeMarshal.AddEventHandler <Delegate>(
                        dlg => (EventRegistrationToken)eventInfo.AddMethod.Invoke(dependencyObject, new object[] { dlg }),
                        etr => eventInfo.RemoveMethod.Invoke(dependencyObject, new object[] { etr }), handler);
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Detaches the currently associated instance
        /// </summary>
        public void Detach()
        {
            if (AssociatedObject != null)
            {
                EventWrapper eventHooker = new EventWrapper(this);
                eventHooker.AssociatedObject = AssociatedObject;
                EventInfo eventInfo = GetEventInfo(AssociatedObject.GetType(), EventName);
                Delegate handler = eventHooker.GetEventHandler(eventInfo);

                WindowsRuntimeMarshal.RemoveEventHandler<Delegate>(
                    etr => eventInfo.RemoveMethod.Invoke(AssociatedObject, new object[] { etr }), handler);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Attaches an instance of a DependencyObject to this instance
        /// </summary>
        /// <param name="dependencyObject">The instance to attach</param>
        public void Attach(DependencyObject dependencyObject)
        {
            AssociatedObject = dependencyObject;

            if (!string.IsNullOrEmpty(EventName))
            {
                EventWrapper eventHooker = new EventWrapper(this);
                eventHooker.AssociatedObject = dependencyObject;
                EventInfo eventInfo = GetEventInfo(dependencyObject.GetType(), EventName);

                if (eventInfo != null)
                {
                    Delegate handler = eventHooker.GetEventHandler(eventInfo);

                    WindowsRuntimeMarshal.AddEventHandler<Delegate>(
                        dlg => (EventRegistrationToken)eventInfo.AddMethod.Invoke(dependencyObject, new object[] { dlg }),
                        etr => eventInfo.RemoveMethod.Invoke(dependencyObject, new object[] { etr }), handler);
                }
            }
        }