Ejemplo n.º 1
0
        private static void OnStateTriggersPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            CompositeStateTrigger trigger = (CompositeStateTrigger)d;

            if (e.OldValue is INotifyCollectionChanged)
            {
                (e.OldValue as INotifyCollectionChanged).CollectionChanged -= trigger.CompositeTrigger_CollectionChanged;
            }
            else if (e.OldValue is Windows.Foundation.Collections.IObservableVector <DependencyObject> )
            {
                (e.OldValue as Windows.Foundation.Collections.IObservableVector <DependencyObject>).VectorChanged += trigger.CompositeStateTrigger_VectorChanged;
                trigger.OnTriggerCollectionChanged((e.NewValue as Windows.Foundation.Collections.IObservableVector <DependencyObject>).OfType <StateTriggerBase>(),
                                                   null);
            }

            if (e.NewValue is INotifyCollectionChanged)
            {
                //TODO: Should be weak reference just in case
                (e.NewValue as INotifyCollectionChanged).CollectionChanged += trigger.CompositeTrigger_CollectionChanged;
            }
            else if (e.NewValue is Windows.Foundation.Collections.IObservableVector <DependencyObject> )
            {
                (e.NewValue as Windows.Foundation.Collections.IObservableVector <DependencyObject>).VectorChanged += trigger.CompositeStateTrigger_VectorChanged;
                trigger.OnTriggerCollectionChanged(null,
                                                   (e.NewValue as Windows.Foundation.Collections.IObservableVector <DependencyObject>).OfType <StateTriggerBase>());
            }
            if (e.NewValue is IEnumerable <StateTriggerBase> )
            {
                foreach (var item in e.NewValue as IEnumerable <StateTriggerBase> )
                {
                    if (!(item is StateTrigger || !(item is ITriggerValue)))
                    {
                        try
                        {
                            throw new NotSupportedException("Only StateTrigger or triggers implementing ITriggerValue are supported in a Composite trigger");
                        }
                        finally
                        {
                            trigger.SetValue(StateTriggersProperty, e.OldValue);                             //Undo change
                        }
                    }
                }
                trigger.CompositeTrigger_CollectionChanged(e.NewValue,
                                                           new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, (e.NewValue as IEnumerable <StateTriggerBase>).ToList()));
            }
            trigger.EvaluateTriggers();
        }
Ejemplo n.º 2
0
        private static void OnEvaluatePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            CompositeStateTrigger trigger = (CompositeStateTrigger)d;

            trigger.EvaluateTriggers();
        }