private static void OnTemplateChanged( DependencyObject d, DependencyPropertyChangedEventArgs e) { InteractivityTemplate dt = (InteractivityTemplate)e.NewValue; if (dt == null) { return; } #if (!SILVERLIGHT) dt.Seal(); #endif InteractivityItems ih = (InteractivityItems)dt.LoadContent(); BehaviorCollection bc = Interaction.GetBehaviors(d); Microsoft.Xaml.Behaviors.TriggerCollection tc = Interaction.GetTriggers(d); foreach (Behavior behavior in ih.Behaviors) { bc.Add(behavior); } foreach (TriggerBase trigger in ih.Triggers) { tc.Add(trigger); } }
/// <summary> /// Gets the TriggerCollection containing the triggers associated with the specified object. /// </summary> /// <param name="obj">The object from which to retrieve the triggers.</param> /// <returns>A TriggerCollection containing the triggers associated with the specified object.</returns> public static TriggerCollection GetTriggers(DependencyObject obj) { TriggerCollection triggerCollection = (TriggerCollection)obj.GetValue(Interaction.TriggersProperty); if (triggerCollection == null) { triggerCollection = new TriggerCollection(); obj.SetValue(Interaction.TriggersProperty, triggerCollection); } return(triggerCollection); }
private static void OnTemplateChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { if (LicenseManager.UsageMode == LicenseUsageMode.Designtime) { return; } InteractivityTemplate dt = (InteractivityTemplate)e.NewValue; dt.Seal(); 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); } }
/// <exception cref="InvalidOperationException">Cannot host the same TriggerCollection on more than one object at a time.</exception> private static void OnTriggersChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args) { TriggerCollection oldCollection = args.OldValue as TriggerCollection; TriggerCollection newCollection = args.NewValue as TriggerCollection; if (oldCollection != newCollection) { if (oldCollection != null && ((IAttachedObject)oldCollection).AssociatedObject != null) { oldCollection.Detach(); } if (newCollection != null && obj != null) { if (((IAttachedObject)newCollection).AssociatedObject != null) { throw new InvalidOperationException(ExceptionStringTable.CannotHostTriggerCollectionMultipleTimesExceptionMessage); } newCollection.Attach(obj); } } }