Exemple #1
0
 private static void OnBehaviorsChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
 {
     System.Windows.Interactivity.BehaviorCollection behaviors = System.Windows.Interactivity.Interaction.GetBehaviors(d);
     foreach (System.Windows.Interactivity.Behavior behavior in e.NewValue as StyleBehaviorCollection)
     {
         behaviors.Add((System.Windows.Interactivity.Behavior)behavior.Clone());
     }
 }
Exemple #2
0
        private static void OnBehaviorCollectionChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var uie = d as UIElement;

            if (uie == null)
            {
                return;
            }

            System.Windows.Interactivity.BehaviorCollection itemBehaviors = Interaction.GetBehaviors(uie);

            var newBehaviors = e.NewValue as BehaviorCollection;
            var oldBehaviors = e.OldValue as BehaviorCollection;

            if (newBehaviors == oldBehaviors)
            {
                return;
            }

            if (oldBehaviors != null)
            {
                foreach (var behavior in oldBehaviors)
                {
                    int index = GetIndexOf(itemBehaviors, behavior);

                    if (index >= 0)
                    {
                        itemBehaviors.RemoveAt(index);
                    }
                }
            }

            if (newBehaviors != null)
            {
                foreach (var behavior in newBehaviors)
                {
                    int index = GetIndexOf(itemBehaviors, behavior);

                    if (index < 0)
                    {
                        var clone = (Behavior)behavior.Clone();
                        SetOriginalBehavior(clone, behavior);
                        itemBehaviors.Add(clone);
                    }
                }
            }
        }
Exemple #3
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);
            }
        }