Пример #1
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 OnBehaviorListChanged(DependencyObject dpo, DependencyPropertyChangedEventArgs e)
        {
            BehaviorCollection list = e.OldValue as BehaviorCollection;

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

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

            if (list != null && fe != null)
            {
                list.Attach(fe);
            }
        }
Пример #2
0
        private static void OnBehaviorsChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args)
        {
            BehaviorCollection oldValue = (BehaviorCollection)args.OldValue;
            BehaviorCollection newValue = (BehaviorCollection)args.NewValue;

            if (oldValue != newValue)
            {
                if (oldValue != null && ((IAttachedObject)oldValue).AssociatedObject != null)
                {
                    oldValue.Detach();
                }
                if (newValue != null && obj != null)
                {
                    if (((IAttachedObject)newValue).AssociatedObject != null)
                    {
                        throw new InvalidOperationException(ExceptionStringTable.CannotHostBehaviorCollectionMultipleTimesExceptionMessage);
                    }
                    newValue.Attach(obj);
                }
            }
        }