示例#1
0
        private Thickness CalculateThickness()
        {
            var thickness = (Thickness)_thicknessConverter
                            .ConvertFromInvariantString(_formattedMultiplierString);
            double multiplier = GetFinalLengthMultiplier();

            return(new Thickness(
                       thickness.Left * multiplier,
                       thickness.Top * multiplier,
                       thickness.Right * multiplier,
                       thickness.Bottom * multiplier));
        }
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null)
            {
                return(null);
            }
            string strValue = value as string;

            if (strValue != null)
            {
                try
                {
                    return(_thicknessConverter.ConvertFromInvariantString(strValue));
                }
                catch
                {
                }
            }

            return(Binding.DoNothing);
        }
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            var margin = value as string;

            if (string.IsNullOrEmpty(margin))
            {
                return(DependencyProperty.UnsetValue);
            }
            var thicknessConverter = new ThicknessConverter();
            var convertFromString  = thicknessConverter.ConvertFromInvariantString(margin);

            if (convertFromString == null)
            {
                return(DependencyProperty.UnsetValue);
            }
            var thickness = (Thickness)convertFromString;
            var top       = thickness.Top;
            var bottom    = thickness.Bottom;

            thickness.Top    = bottom;
            thickness.Bottom = top;
            return(thickness);
        }