private static void UnitTypeChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            if (object.Equals(e.OldValue, e.NewValue))
            {
                return;
            }
            TextChoiceEditorWrapper choiceEditorWrapper = d as TextChoiceEditorWrapper;

            if (choiceEditorWrapper == null || !(e.NewValue is UnitType))
            {
                return;
            }
            UnitType unitType = (UnitType)e.NewValue;

            choiceEditorWrapper.textTypeConverter = new Microsoft.Expression.DesignSurface.UserInterface.PropertyInspector.TextSizeConverter(unitType);
            choiceEditorWrapper.OnPropertyChanged("TextSizeConverter");
            if (choiceEditorWrapper.isUpdatingValue)
            {
                return;
            }
            choiceEditorWrapper.isUpdatingValue = true;
            try
            {
                UnitTypedSize unitTypedSize = choiceEditorWrapper.TextChoiceEditor.Value as UnitTypedSize;
                if (unitTypedSize == null)
                {
                    return;
                }
                choiceEditorWrapper.TextChoiceEditor.Value = (object)unitTypedSize.ConvertTo(unitType);
            }
            finally
            {
                choiceEditorWrapper.isUpdatingValue = false;
            }
        }
        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;
            }
        }
Example #3
0
        public override bool Equals(object obj)
        {
            UnitTypedSize unitTypedSize = obj as UnitTypedSize;

            if (unitTypedSize != null && unitTypedSize.size == this.size)
            {
                return(unitTypedSize.units == this.units);
            }
            return(false);
        }
Example #4
0
        public static UnitTypedSize CreateFromPixels(double pixelValue, UnitType type)
        {
            UnitTypedSize unitTypedSize = new UnitTypedSize(pixelValue, UnitType.Pixels);

            if (type != UnitType.Pixels)
            {
                unitTypedSize = unitTypedSize.ConvertTo(type);
            }
            return(unitTypedSize);
        }
Example #5
0
        public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
        {
            UnitTypedSize unitTypedSize = value as UnitTypedSize;

            if (unitTypedSize == null)
            {
                return(base.ConvertTo(context, culture, value, destinationType));
            }
            return((object)unitTypedSize.ConvertTo(this.unitType).ToString());
        }
Example #6
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));
        }
Example #7
0
        public UnitTypedSize ConvertTo(UnitType destinationType)
        {
            double size = this.Size;

            if (this.Units != destinationType)
            {
                switch (destinationType)
                {
                case UnitType.Points:
                    size = UnitTypedSize.ConvertPixelToPoint(this.Size);
                    break;

                case UnitType.Pixels:
                    size = UnitTypedSize.ConvertPointToPixel(this.Size);
                    break;
                }
            }
            return(new UnitTypedSize(size, destinationType));
        }
 private void ChoiceEditorValueChanged(object sender, EventArgs e)
 {
     if (this.isUpdatingValue)
     {
         return;
     }
     this.isUpdatingValue = true;
     try
     {
         object obj = this.TextChoiceEditor.Value;
         if (obj == null)
         {
             this.WrappedValue = MixedProperty.Mixed;
         }
         else
         {
             UnitTypedSize unitTypedSize1 = obj as UnitTypedSize;
             if (unitTypedSize1 == null)
             {
                 return;
             }
             UnitTypedSize unitTypedSize2 = unitTypedSize1.ConvertTo(UnitType.Pixels);
             double        size           = unitTypedSize2.Size;
             unitTypedSize2.Size = this.EnforceHardMaximumAndMinimum(unitTypedSize2.Size);
             if (size != unitTypedSize2.Size)
             {
                 this.TextChoiceEditor.Value = (object)unitTypedSize2.ConvertTo(this.UnitType);
             }
             unitTypedSize2.Size = RoundingHelper.RoundScale(unitTypedSize2.Size);
             this.WrappedValue   = (object)unitTypedSize2.Size;
         }
     }
     finally
     {
         this.isUpdatingValue = false;
     }
 }