Exemplo n.º 1
0
        private static void OnTemplateChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            DependencyObject target = d;

            if (e.OldValue != null)
            {
                InteractivityTemplate interactivityTemplate = (InteractivityTemplate)e.OldValue;
                InteractivityItems    interactivityItems    = (InteractivityItems)interactivityTemplate.LoadContent();
                BehaviorCollection    behaviorCollection    = Interaction.GetBehaviors(target);
                TriggerCollection     triggerCollection     = Interaction.GetTriggers(target);

                interactivityItems.Behaviors.ForEach(x => behaviorCollection.Remove(x));
                interactivityItems.Triggers.ForEach(x => triggerCollection.Remove(x));
            }

            if (e.NewValue != null)
            {
                InteractivityTemplate interactivityTemplate = (InteractivityTemplate)e.NewValue;
                interactivityTemplate.Seal();
                InteractivityItems interactivityItems = (InteractivityItems)interactivityTemplate.LoadContent();
                BehaviorCollection behaviorCollection = Interaction.GetBehaviors(target);
                TriggerCollection  triggerCollection  = Interaction.GetTriggers(target);

                interactivityItems.Behaviors.ForEach(behaviorCollection.Add);
                interactivityItems.Triggers.ForEach(triggerCollection.Add);
            }
        }
Exemplo n.º 2
0
        private static void OnTemplateChanged(
            DependencyObject d,
            DependencyPropertyChangedEventArgs e)
        {
            InteractivityTemplate dt = (InteractivityTemplate)e.NewValue;

#if (!SILVERLIGHT)
            dt.Seal();
#endif
            InteractivityItems ih = (InteractivityItems)dt.LoadContent();
            BehaviorCollection bc = Interaction.GetBehaviors(d);
            TriggerCollection  tc = Interaction.GetTriggers(d);

            foreach (Behavior behavior in ih.Behaviors)
            {
                bc.Add(behavior);
            }

            foreach (TriggerBase trigger in ih.Triggers)
            {
                tc.Add(trigger);
            }
        }