public static Unit GetWidth(Unit width, double totalWeight) { if (width.Type == UnitType.None) { if (totalWeight == 0) { return(Unit.Parse("100%")); } else { return(Unit.Parse(string.Format("{0}%", Math.Round(width.Value / totalWeight * 100, 4)))); } } return(width); }
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { if (value == null) { return(Unit.Empty); } if (value.GetType() == typeof(string)) { return(Unit.Parse((string)value)); } else { return(base.ConvertFrom(context, culture, value)); } }