Ejemplo n.º 1
0
 private static bool IsSideSet(ThicknessSides sides, ThicknessSides sideToTest)
 {
     return((sides & sideToTest) == sideToTest);
 }
Ejemplo n.º 2
0
        public object Convert(
            object value,
            Type targetType,
            object parameter,
            CultureInfo culture)
        {
            if ((!targetType.IsAssignableFrom(typeof(Thickness))) ||
                (value == null) ||
                (value.GetType() != typeof(double)))
            {
                return(DependencyProperty.UnsetValue);
            }

            ThicknessSides sides = ThicknessSides.All; // Defaults to All when no parameter is present;

            if (parameter != null)
            {
                Type parameterType = parameter.GetType();
                if (parameterType == typeof(ThicknessSides))
                {
                    sides = ( ThicknessSides )parameter;
                }
                else if (parameterType == typeof(string))
                {
                    string stringParameter = (string)parameter;
                    if (!string.IsNullOrEmpty(stringParameter))
                    {
                        try
                        {
                            sides = ( ThicknessSides )Enum.Parse(typeof(ThicknessSides), stringParameter);
                        }
                        catch
                        {
                            return(DependencyProperty.UnsetValue);
                        }
                    }
                }
                else
                {
                    return(DependencyProperty.UnsetValue);
                }
            }

            double doubleValue = ( double )value;

            if (this.InverseValue == true)
            {
                doubleValue *= -1;
            }

            Thickness thickness = new Thickness();

            if (IsSideSet(sides, ThicknessSides.Left))
            {
                thickness.Left = doubleValue;
            }

            if (IsSideSet(sides, ThicknessSides.Top))
            {
                thickness.Top = doubleValue;
            }

            if (IsSideSet(sides, ThicknessSides.Right))
            {
                thickness.Right = doubleValue;
            }

            if (IsSideSet(sides, ThicknessSides.Bottom))
            {
                thickness.Bottom = doubleValue;
            }

            return(thickness);
        }
Ejemplo n.º 3
0
 private static bool IsSideSet( ThicknessSides sides, ThicknessSides sideToTest )
 {
   return ( ( sides & sideToTest ) == sideToTest );
 }