Наследование: Windows.UI.Xaml.DependencyObject, IBehavior
Пример #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 leftComparableOperand  = leftOperand as IComparable;
            IComparable rightComparableOperand = rightOperand as IComparable;

            if ((leftComparableOperand != null) && (rightComparableOperand != null))
            {
                return(DataTriggerBehavior.EvaluateComparable(leftComparableOperand, operatorType, rightComparableOperand));
            }

            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 (leftComparableOperand == null && rightComparableOperand == null)
                {
                    throw new ArgumentException(string.Format(
                                                    CultureInfo.CurrentCulture,
                                                    ResourceHelper.InvalidOperands,
                                                    leftOperand != null ? leftOperand.GetType().Name : "null",
                                                    rightOperand != null ? rightOperand.GetType().Name : "null",
                                                    operatorType.ToString()));
                }
                else if (leftComparableOperand == null)
                {
                    throw new ArgumentException(string.Format(
                                                    CultureInfo.CurrentCulture,
                                                    ResourceHelper.InvalidLeftOperand,
                                                    leftOperand != null ? leftOperand.GetType().Name : "null",
                                                    operatorType.ToString()));
                }
                else
                {
                    throw new ArgumentException(string.Format(
                                                    CultureInfo.CurrentCulture,
                                                    ResourceHelper.InvalidRightOperand,
                                                    rightOperand != null ? rightOperand.GetType().Name : "null",
                                                    operatorType.ToString()));
                }
            }
            }

            return(false);
        }
Пример #2
0
        private static void OnValueChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs args)
        {
            DataTriggerBehavior dataTriggerBehavior = (DataTriggerBehavior)dependencyObject;

            if (dataTriggerBehavior.AssociatedObject == null)
            {
                return;
            }

            DataBindingHelper.RefreshDataBindingsOnActions(dataTriggerBehavior.Actions);

            // Some value has changed--either the binding value, reference value, or the comparison condition. Re-evaluate the equation.
            if (DataTriggerBehavior.Compare(dataTriggerBehavior.Binding, dataTriggerBehavior.ComparisonCondition, dataTriggerBehavior.Value))
            {
                Interaction.ExecuteActions(dataTriggerBehavior.AssociatedObject, dataTriggerBehavior.Actions, args);
            }
        }