Пример #1
0
        ////////////////////////////////////////////////////////////////////////
        // ProcessOneTrigger
        //
        // Find the target element for this trigger, and set a listener for
        // the event into (pointing back to the trigger).

        internal static void ProcessOneTrigger(FrameworkElement triggersHost, TriggerBase triggerBase)
        {
            // This code path is used in the element trigger case.  We don't actually
            //  need these guys to be usable cross-thread, so we don't really need
            //  to freeze/seal these objects.  The only one expected to cause problems
            //  is a change to the RoutedEvent.  At the same time we remove this
            //  Seal(), the RoutedEvent setter will check to see if the handler has
            //  already been created and refuse an update if so.
            // triggerBase.Seal();

            EventTrigger eventTrigger = triggerBase as EventTrigger;

            if (eventTrigger != null)
            {
                Debug.Assert(eventTrigger._routedEventHandler == null && eventTrigger._source == null);

                // PERF: Cache this result if it turns out we're doing a lot of lookups on the same name.
                eventTrigger._source = FrameworkElement.FindNamedFrameworkElement(triggersHost, eventTrigger.SourceName);

                // Create a statefull event delegate (which keeps a ref to the FE).
                EventTriggerSourceListener listener = new EventTriggerSourceListener(eventTrigger, triggersHost);


                // Store the RoutedEventHandler & target for use in DisconnectOneTrigger
                eventTrigger._routedEventHandler = new RoutedEventHandler(listener.Handler);
                eventTrigger._source.AddHandler(eventTrigger.RoutedEvent, eventTrigger._routedEventHandler,
                                                false /* HandledEventsToo */);
            }
            else
            {
                throw new InvalidOperationException(SR.Get(SRID.TriggersSupportsEventTriggersOnly));
            }
        }
Пример #2
0
        ////////////////////////////////////////////////////////////////////////
        // ProcessOneTrigger
        // 
        // Find the target element for this trigger, and set a listener for
        // the event into (pointing back to the trigger). 
 
        internal static void ProcessOneTrigger( FrameworkElement triggersHost, TriggerBase triggerBase )
        { 
            // This code path is used in the element trigger case.  We don't actually
            //  need these guys to be usable cross-thread, so we don't really need
            //  to freeze/seal these objects.  The only one expected to cause problems
            //  is a change to the RoutedEvent.  At the same time we remove this 
            //  Seal(), the RoutedEvent setter will check to see if the handler has
            //  already been created and refuse an update if so. 
            // triggerBase.Seal(); 

            EventTrigger eventTrigger = triggerBase as EventTrigger; 
            if( eventTrigger != null )
            {
                Debug.Assert( eventTrigger._routedEventHandler == null && eventTrigger._source == null);
 
                // PERF: Cache this result if it turns out we're doing a lot of lookups on the same name.
                eventTrigger._source = FrameworkElement.FindNamedFrameworkElement( triggersHost, eventTrigger.SourceName ); 
 
                // Create a statefull event delegate (which keeps a ref to the FE).
                EventTriggerSourceListener listener = new EventTriggerSourceListener( eventTrigger, triggersHost ); 


                // Store the RoutedEventHandler & target for use in DisconnectOneTrigger
                eventTrigger._routedEventHandler = new RoutedEventHandler(listener.Handler); 
                eventTrigger._source.AddHandler( eventTrigger.RoutedEvent, eventTrigger._routedEventHandler,
                                                 false /* HandledEventsToo */ ); 
            } 
            else
            { 
                throw new InvalidOperationException(SR.Get(SRID.TriggersSupportsEventTriggersOnly));
            }
        }