コード例 #1
0
        private static void WrappedValueChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            if (object.Equals(e.OldValue, e.NewValue))
            {
                return;
            }
            TextChoiceEditorWrapper choiceEditorWrapper = d as TextChoiceEditorWrapper;

            if (choiceEditorWrapper == null || choiceEditorWrapper.isUpdatingValue)
            {
                return;
            }
            choiceEditorWrapper.isUpdatingValue = true;
            try
            {
                object newValue = e.NewValue;
                if (newValue != null && newValue != MixedProperty.Mixed && newValue is double)
                {
                    choiceEditorWrapper.TextChoiceEditor.Value = (object)UnitTypedSize.CreateFromPixels((double)newValue, choiceEditorWrapper.UnitType);
                }
                else
                {
                    choiceEditorWrapper.TextChoiceEditor.Value = null;
                }
            }
            finally
            {
                choiceEditorWrapper.isUpdatingValue = false;
            }
        }
コード例 #2
0
        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
        {
            string str = value as string;

            if (string.IsNullOrEmpty(str))
            {
                return(null);
            }
            FontSizeConverter fontSizeConverter = new FontSizeConverter();
            double            result;

            if (double.TryParse(str, NumberStyles.Float | NumberStyles.AllowThousands, (IFormatProvider)culture, out result))
            {
                return((object)UnitTypedSize.CreateFromUnits(result, this.unitType));
            }
            return((object)UnitTypedSize.CreateFromPixels((double)fontSizeConverter.ConvertFromString(context, culture, str), this.unitType));
        }