public override bool IsValid(ITypeDescriptorContext context, object value)
 {
     try
     {
         return(TextStyleStack.IsValidFormat((string)value));
     }
     catch
     {
         throw new Exception("isvalid failed");
     }
 }
 public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
 {
     try
     {
         return(TextStyleStack.Parse((string)value));
     }
     catch
     {
         throw new Exception("convertfrom failed");
     }
 }
Esempio n. 3
0
        public static TextStyleStack Parse(string stack)
        {
            var value        = new TextStyleStack();
            var stackMembers = stack.Split(' ');

            foreach (var stackMember in stackMembers)
            {
                if (stackMember.ToLower() == "bold")
                {
                    value.FontWeight = FontWeights.Bold;
                }
                if (stackMember.EndsWith("pt"))
                {
                    value.FontSize = (double)fsc.ConvertFromString(stackMember);
                }
            }
            return(value);
        }
        public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
        {
            try
            {
                if (destinationType == null)
                {
                    throw new ArgumentNullException(nameof(destinationType));
                }

                if (value == null)
                {
                    throw new ArgumentNullException(nameof(value));
                }

                var strValue = ConvertToInvariantString(context, value);
                if (destinationType == typeof(string))
                {
                    return(value.ToString());
                }
                if (destinationType == typeof(InstanceDescriptor))
                {
                    var info = TargetType.GetField(strValue);
                    if (info != null)
                    {
                        return(new InstanceDescriptor(info, null));
                    }
                }
                if (destinationType == TargetType)
                {
                    return(TextStyleStack.Parse(strValue));
                }
                throw new Exception("convertto failed");
            }
            catch
            {
                throw new Exception("convertto failed unknown");
            }
        }
Esempio n. 5
0
 public static void SetStyleStack(DependencyObject i, TextStyleStack v) => i.Set(StyleStackProperty, v);