Пример #1
0
        /// <exception cref="T:System.InvalidOperationException">Cannot host the same TriggerCollection on more than one object at a time.</exception>
        private static void OnTriggersChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args)
        {
            TriggerCollection triggerCollection1 = args.OldValue as TriggerCollection;
            TriggerCollection triggerCollection2 = args.NewValue as TriggerCollection;

            if (triggerCollection1 == triggerCollection2)
            {
                return;
            }
            if (triggerCollection1 != null && triggerCollection1.AssociatedObject != null)
            {
                triggerCollection1.Detach();
            }
            if (triggerCollection2 == null || obj == null)
            {
                return;
            }
            if (triggerCollection2.AssociatedObject != null)
            {
                throw new InvalidOperationException("Cannot Host TriggerCollection Multiple Times");
            }
            FrameworkElement fElement = obj as FrameworkElement;

            if (fElement == null)
            {
                throw new InvalidOperationException("Can only host BehaviorCollection on FrameworkElement");
            }
            triggerCollection2.Attach(fElement);
        }
Пример #2
0
        /// <exception cref="T:System.InvalidOperationException">Cannot host the same TriggerCollection on more than one object at a time.</exception>
        private static void OnTriggersChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args)
        {
            TriggerCollection triggerCollection1 = args.OldValue as TriggerCollection;
            TriggerCollection triggerCollection2 = args.NewValue as TriggerCollection;

            if (triggerCollection1 == triggerCollection2)
            {
                return;
            }
            if (triggerCollection1 != null && triggerCollection1.AssociatedObject != null)
            {
                triggerCollection1.Detach();
            }
            if (triggerCollection2 == null || obj == null)
            {
                return;
            }
            if (triggerCollection2.AssociatedObject != null)
            {
                //todo: check why uncommenting the following line causes an issue with the Userware KanBan demo (CSHTML5 2.0.0-alpha67-087).
                //throw new InvalidOperationException("Cannot Host TriggerCollection Multiple Times");
            }
            FrameworkElement fElement = obj as FrameworkElement;

            if (fElement == null)
            {
                throw new InvalidOperationException("Can only host BehaviorCollection on FrameworkElement");
            }
            triggerCollection2.Attach(fElement);
        }
Пример #3
0
        /// <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();
                triggerCollection.Attach(obj); //CSHTML5 Added
                obj.SetValue(Interaction.TriggersProperty, triggerCollection);
            }
            return(triggerCollection);
        }
Пример #4
0
        /// <summary>
        /// This is called when the behavior collection is changed on an object.
        /// </summary>
        /// <param name="dpo">FrameworkElement owner</param>
        /// <param name="e"></param>
        private static void OnTriggerListChanged(DependencyObject dpo, DependencyPropertyChangedEventArgs e)
        {
            TriggerCollection list = e.OldValue as TriggerCollection;

            if (list != null)
            {
                list.Detach();
            }

            list = e.NewValue as TriggerCollection;
            FrameworkElement fe = dpo as FrameworkElement;

            if (list != null && fe != null)
            {
                list.Attach(fe);
            }
        }