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; } }
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); }
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()); }
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; } }