Exemplo n.º 1
0
        private static void OnEventNameChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs args)
        {
            EventTriggerBehavior eventTriggerBehavior = (EventTriggerBehavior)dependencyObject;

            if (eventTriggerBehavior.AssociatedObject == null || eventTriggerBehavior.resolvedSource == null)
            {
                return;
            }
            string eventName  = (string)args.OldValue;
            string eventName2 = (string)args.NewValue;

            eventTriggerBehavior.UnregisterEvent(eventName);
            eventTriggerBehavior.RegisterEvent(eventName2);
        }
Exemplo n.º 2
0
        private void RegisterEvent(string eventName)
        {
            if (string.IsNullOrEmpty(eventName))
            {
                return;
            }
            if (!(eventName != "Loaded"))
            {
                if (!this.isLoadedEventRegistered)
                {
                    FrameworkElement frameworkElement = this.resolvedSource as FrameworkElement;
                    if (frameworkElement != null && !EventTriggerBehavior.IsElementLoaded(frameworkElement))
                    {
                        this.isLoadedEventRegistered = true;
                        frameworkElement.Loaded     += this.OnEvent;
                    }
                }
                return;
            }
            Type      type = this.resolvedSource.GetType();
            EventInfo info = type.GetRuntimeEvent(this.EventName);

            if (info == null)
            {
                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, "CannotFindEventNameExceptionMessage", new object[]
                {
                    this.EventName,
                    type.Name
                }));
            }
            MethodInfo declaredMethod = typeof(EventTriggerBehavior).GetTypeInfo().GetDeclaredMethod("OnEvent");

            this.eventHandler          = declaredMethod.CreateDelegate(info.EventHandlerType, this);
            this.isWindowsRuntimeEvent = EventTriggerBehavior.IsWindowsRuntimeType(info.EventHandlerType);
            if (this.isWindowsRuntimeEvent)
            {
                WindowsRuntimeMarshal.AddEventHandler <Delegate>((Delegate add) => (EventRegistrationToken)info.AddMethod.Invoke(this.resolvedSource, new object[]
                {
                    add
                }), delegate(EventRegistrationToken token)
                {
                    info.RemoveMethod.Invoke(this.resolvedSource, new object[]
                    {
                        token
                    });
                }, this.eventHandler);
                return;
            }
            info.AddEventHandler(this.resolvedSource, this.eventHandler);
        }
Exemplo n.º 3
0
        private static void OnSourceObjectChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs args)
        {
            EventTriggerBehavior eventTriggerBehavior = (EventTriggerBehavior)dependencyObject;

            eventTriggerBehavior.SetResolvedSource(eventTriggerBehavior.ComputeResolvedSource());
        }