コード例 #1
0
 /// <inheritdoc />
 public override void Detach()
 {
     if (this.AssociatedObject != null)
     {
         var eventHooker = new EventHooker(this);
         eventHooker.UnhookEvent(this.AssociatedObject, this.EventName);
     }
 }
コード例 #2
0
        /// <inheritdoc />
        public override void Attach(FrameworkElement obj)
        {
            base.Attach(obj);

            if (!string.IsNullOrEmpty(this.EventName))
            {
                var eventHooker = new EventHooker(this);
                eventHooker.HookEvent(obj, this.EventName);
            }
        }
コード例 #3
0
        /// <summary>
        /// Hooks an event on the target object.
        /// </summary>
        /// <param name="eventName">
        /// The event name.
        /// </param>
        /// <param name="targetObj">
        /// The source object.
        /// </param>
        protected void HookEvent(string eventName, object targetObj)
        {
            if (!string.IsNullOrEmpty(eventName))
            {
                var target = this.GetEventTarget(targetObj);

                if (target != null)
                {
                    var eventHooker = new EventHooker(this);
                    eventHooker.HookEvent(target, eventName);

                    this.hookedEvent = new WeakReference<EventHooker>(eventHooker);
                }
            }
        }
コード例 #4
0
        /// <summary>
        /// Hooks an event on the target object.
        /// </summary>
        /// <param name="eventName">
        /// The event name.
        /// </param>
        /// <param name="targetObj">
        /// The source object.
        /// </param>
        protected void HookEvent(string eventName, object targetObj)
        {
            if (!string.IsNullOrEmpty(eventName))
            {
                var target = this.GetEventTarget(targetObj);

                if (target != null)
                {
                    var eventHooker = new EventHooker(this);
                    eventHooker.HookEvent(target, eventName);

                    this.hookedEvent = new WeakReference <EventHooker>(eventHooker);
                }
            }
        }