Ejemplo n.º 1
0
 public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
 {
     if (value is string s)
     {
         if (targetType == typeof(UniColor))
         {
             return(UniColor.Parse(s));
         }
         else if (targetType == typeof(System.Windows.Media.Color))
         {
             return(UniColor.Parse(s).GetWPFColor());
         }
         else
         {
             throw new NotSupportedException();
         }
     }
     else
     {
         throw new NotSupportedException();
     }
 }
Ejemplo n.º 2
0
        public override ValidationResult Validate(object value, CultureInfo cultureInfo)
        {
            if (ValidateSatVal || ValidateHue)
            {
                if (!double.TryParse(value.ToString(), NumberStyles.Any, cultureInfo, out double result))
                {
                    return(new ValidationResult(false, "Does Not Parse As Double"));
                }
                else if (ValidateSatVal && (result < 0d || result > 1))
                {
                    return(new ValidationResult(false, "Is Not Within Range 0 to 1"));
                }
                else if (ValidateHue && (result < 0d || result > 360d))
                {
                    return(new ValidationResult(false, "Is Not Within Range 0 to 360"));
                }
            }
            else if (ValidateWebHex)
            {
                try
                {
                    UniColor.Parse(value.ToString());
                }
                catch
                {
                    return(new ValidationResult(false, "Is Not Parseable Color"));
                }
            }
            else
            {
                if (!byte.TryParse(value.ToString(), NumberStyles.Any, cultureInfo, out _))
                {
                    return(new ValidationResult(false, "Does Not Parse As Byte"));
                }
            }

            return(ValidationResult.ValidResult);
        }