Exemplo n.º 1
0
        /// <summary>
        /// Converts a string to an animation value.
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public virtual object ConvertToAnimationStepFromString(string value)
        {
            if (value == null)
            {
                return(null);
            }

            Type valueType = AnimationValueCalculatorFactory.GetRegisteredStepForType(this.AssociatedType);

            if (valueType == null)
            {
                valueType = this.AssociatedType;
            }

            object res = null;

            TypeConverter converter = TypeDescriptor.GetConverter(valueType);

            if (converter != null)
            {
                if (converter.CanConvertFrom(typeof(string)))
                {
                    try
                    {
                        res = converter.ConvertFrom(value);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Error setting animation value: " + ex.Message);
                    }
                }
                else
                {
                    //throw new InvalidOperationException(string.Format(
                    //    "The TypeConverter - {0} cannot convert from string, animation step of type {1}",
                    //    converter.ToString(), valueType.FullName));
                    MessageBox.Show(string.Format("The TypeConverter - {0} cannot convert from string, animation step of type {1}", converter.ToString(), valueType.FullName));
                }
            }
            else
            {
                MessageBox.Show("Can't find any TypeConverter for animation step of type " + valueType.FullName);
            }

            return(res);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Retrieves the animation step as a string value.
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public virtual string ConvertAnimationStepToString(object value)
        {
            if (value == null)
            {
                return(null);
            }

            string res = value.ToString();

            Type valueType = AnimationValueCalculatorFactory.GetRegisteredStepForType(this.AssociatedType);

            if (valueType == null)
            {
                valueType = this.AssociatedType;
            }

            TypeConverter converter = TypeDescriptor.GetConverter(valueType);

            if (converter != null)
            {
                if (converter.CanConvertTo(typeof(string)))
                {
                    try
                    {
                        res = (string)converter.ConvertTo(value, typeof(string));
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Error converting animation value: " + ex.Message);
                    }
                }
                else
                {
                    MessageBox.Show("Can't find TypeConverter to string for animation step " + value.ToString());
                }
            }
            else
            {
                MessageBox.Show("Can't find any TypeConverter for animation property " + value.ToString());
            }

            return(res);
        }