コード例 #1
0
        public override ValidationResult Validate(object value, System.Globalization.CultureInfo cultureInfo)
        {
            CurrencyAlertData alertData = (value as BindingExpression).DataItem as CurrencyAlertData;

            if ((value as BindingExpression).ResolvedSourcePropertyName == "LowerBound")
            {
                if (alertData.LowerBound >= alertData.Price)
                {
                    return(new ValidationResult(false, "Lower bound should be less than current price."));
                }
            }

            if ((value as BindingExpression).ResolvedSourcePropertyName == "UpperBound")
            {
                if (alertData.UpperBound <= alertData.Price || alertData.UpperBound == 0)
                {
                    return(new ValidationResult(false, "Upper bound should be greater than current price."));
                }
            }

            return(ValidationResult.ValidResult);
        }
コード例 #2
0
        public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (values[3] == null)
            {
                return(false);
            }

            CurrencyAlertData alertData = values[3] as CurrencyAlertData;

            if (values[0] != null && values[1] != null && values[2] != null)
            {
                double lowerBound = (double)values[0];
                double upperBound = (double)values[2];
                if (lowerBound == 0 && upperBound == 0)
                {
                    alertData.IsAlerted = false;
                    return(false);
                }

                double price = (double)values[1];
                if (lowerBound > 0 && price <= lowerBound)
                {
                    alertData.IsAlerted = true;
                    return(true);
                }

                if (upperBound > 0 && price >= upperBound)
                {
                    alertData.IsAlerted = true;
                    return(true);
                }
            }

            alertData.IsAlerted = false;
            return(false);
        }