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"); } }
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"); } }
public static void SetStyleStack(DependencyObject i, TextStyleStack v) => i.Set(StyleStackProperty, v);