Exemplo n.º 1
0
        private static bool Compare(object leftOperand, ComparisonConditionType operatorType, object rightOperand)
        {
            if (leftOperand != null && rightOperand != null)
            {
                rightOperand = TypeConverterHelper.Convert(rightOperand.ToString(), leftOperand.GetType().FullName);
            }
            IComparable comparable  = leftOperand as IComparable;
            IComparable comparable2 = rightOperand as IComparable;

            if (comparable != null && comparable2 != null)
            {
                return(DataTriggerBehavior.EvaluateComparable(comparable, operatorType, comparable2));
            }
            switch (operatorType)
            {
            case ComparisonConditionType.Equal:
                return(object.Equals(leftOperand, rightOperand));

            case ComparisonConditionType.NotEqual:
                return(!object.Equals(leftOperand, rightOperand));

            case ComparisonConditionType.LessThan:
            case ComparisonConditionType.LessThanOrEqual:
            case ComparisonConditionType.GreaterThan:
            case ComparisonConditionType.GreaterThanOrEqual:
                if (comparable == null && comparable2 == null)
                {
                    throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, "InvalidOperands", new object[]
                    {
                        (leftOperand != null) ? leftOperand.GetType().Name : "null",
                        (rightOperand != null) ? rightOperand.GetType().Name : "null",
                        operatorType.ToString()
                    }));
                }
                if (comparable == null)
                {
                    throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, "InvalidLeftOperand", new object[]
                    {
                        (leftOperand != null) ? leftOperand.GetType().Name : "null",
                        operatorType.ToString()
                    }));
                }
                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, "InvalidRightOperand", new object[]
                {
                    (rightOperand != null) ? rightOperand.GetType().Name : "null",
                    operatorType.ToString()
                }));

            default:
                return(false);
            }
        }
Exemplo n.º 2
0
        private static void OnValueChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs args)
        {
            DataTriggerBehavior dataTriggerBehavior = (DataTriggerBehavior)dependencyObject;

            if (dataTriggerBehavior.AssociatedObject == null)
            {
                return;
            }
            DataBindingHelper.RefreshDataBindingsOnActions(dataTriggerBehavior.Actions);
            if (DataTriggerBehavior.Compare(dataTriggerBehavior.Binding, dataTriggerBehavior.ComparisonCondition, dataTriggerBehavior.Value))
            {
                Interaction.ExecuteActions(dataTriggerBehavior.AssociatedObject, dataTriggerBehavior.Actions, args);
            }
        }