Beispiel #1
0
        /// <summary>
        /// Removes the <see cref="FrameworkElement"/> with the given <see cref="EventDefinition"/> from Tracking.
        /// </summary>
        /// <param name="element"></param>
        /// <param name="event"></param>
        private void RemoveEventHandler(FrameworkElement element, EventDefinition @event)
        {
            IEnumerable <KeyValuePair <FrameworkElementEvent, Delegate> > registerd = null;

            if (@event.AssignRecursively || [email protected](element))
            {
                registerd = EventDelegates.Where(i => i.Key.Event.Equals(@event)).ToList();
            }
            else
            {
                var key = new FrameworkElementEvent(element, @event, Element);
                registerd = EventDelegates.Where(i => i.Key.Equals(key)).ToList();
            }

            if (registerd.Count() > 0)
            {
                foreach (var item in registerd)
                {
                    var info = @event.GetEventInfo(item.Key.Element.GetType());
                    info.RemoveEventHandler(item.Key.Element, item.Value);
                    EventDelegates.Remove(item.Key);
                    Config.Instance.WriteLog(this, $"Removed {item.Key?.Element?.ToString()} with EventType {item.Key?.Event?.EventType.ToString()} to Tracked Events of {Element?.ToString()}.", Enums.LogType.Info);
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Method for registering the delegate. Based on the field type of the events,
        /// its switches the event registration between standard CLR and WPF registration for RoutedEvents to also keep track on Handled events.
        /// </summary>
        /// <param name="target"></param>
        /// <param name="delegate"></param>
        /// <param name="definition"></param>
        private void RegisterDelegate(FrameworkElement target, Delegate @delegate, EventDefinition definition)
        {
            //Testing if its an routed Event
            var field = definition.GetFieldInfo(target.GetType());

            if (field == null || !field.FieldType.Equals(typeof(RoutedEvent)) || !typeof(RoutedEvent).IsAssignableFrom(field.FieldType))
            {
                definition.GetEventInfo(target.GetType()).AddEventHandler(target, @delegate);
            }
            else
            {
                target.AddHandler((RoutedEvent)field.GetValue(target), @delegate, definition.HandledEventsToo);
            }
        }