Ejemplo n.º 1
0
 public static Windows.UI.Color ToColor(object value)
 {
     if (value is string)
     {
         Windows.UI.Color?nullable = FormatterColorHelper.FromStringValue(value.ToString());
         if (nullable.HasValue)
         {
             return(nullable.Value);
         }
     }
     else if (value is Windows.UI.Color)
     {
         return((Windows.UI.Color)value);
     }
     throw new InvalidCastException();
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates a new color format.
        /// </summary>
        /// <param name="token">The string expression for the color format.</param>
        /// <remarks>Use a string expression such as "[red]" or "[blue]" to specify the color format.</remarks>
        public ColorFormatPart(string token) : base(token)
        {
            this.foreColor = Colors.Black;
            this.index     = -1;
            string color = DefaultTokens.TrimSquareBracket(token);

            if ((color == null) || (color == string.Empty))
            {
                throw new ArgumentException(ResourceStrings.FormatterIllegaTokenError);
            }
            try
            {
                Windows.UI.Color?nullable = FormatterColorHelper.FromStringValue(color);
                if (nullable.HasValue)
                {
                    this.foreColor = nullable.Value;
                    this.colorName = color;
                    return;
                }

                if (color.Length > "Color".Length)
                {
                    color = color.Remove(0, "Color".Length);
                    int result = -1;
                    if ((int.TryParse(color, out result) && (result >= 1)) && (result <= 0x38))
                    {
                        this.foreColor = FormatterColorHelper.ColorFromIndex(result);
                        this.index     = result;
                        return;
                    }
                }
            }
            catch
            {
            }
            throw new ArgumentException(ResourceStrings.FormatterIllegaTokenError);
        }