public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is Thickness)
            {
                // yes, we can override it with the parameter value
                if (parameter is ThicknessSideType)
                {
                    TakeThicknessSide = (ThicknessSideType)parameter;
                }

                var orgThickness = (Thickness)value;
                switch (TakeThicknessSide)
                {
                case ThicknessSideType.Left:
                    return(orgThickness.Left);

                case ThicknessSideType.Top:
                    return(orgThickness.Top);

                case ThicknessSideType.Right:
                    return(orgThickness.Right);

                case ThicknessSideType.Bottom:
                    return(orgThickness.Bottom);

                default:
                    return(default(double));
                }
            }

            return(default(double));
        }
예제 #2
0
        /// <summary>
        /// returns the thickness by <see cref="IgnoreThicknessSide"/>
        /// </summary>
        /// <param name="value"></param>
        /// <param name="targetType"></param>
        /// <param name="parameter"></param>
        /// <param name="culture"></param>
        /// <returns></returns>
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is Thickness)
            {
                // yes, we can override it with the parameter value
                if (parameter is ThicknessSideType)
                {
                    this.IgnoreThicknessSide = (ThicknessSideType)parameter;
                }
                var orgThickness = (Thickness)value;
                switch (this.IgnoreThicknessSide)
                {
                case ThicknessSideType.Left:
                    return(new Thickness(0, orgThickness.Top, orgThickness.Right, orgThickness.Bottom));

                case ThicknessSideType.Top:
                    return(new Thickness(orgThickness.Left, 0, orgThickness.Right, orgThickness.Bottom));

                case ThicknessSideType.Right:
                    return(new Thickness(orgThickness.Left, orgThickness.Top, 0, orgThickness.Bottom));

                case ThicknessSideType.Bottom:
                    return(new Thickness(orgThickness.Left, orgThickness.Top, orgThickness.Right, 0));

                default:
                    return(orgThickness);
                }
            }
            return(default(Thickness));
        }
예제 #3
0
        /// <summary>
        /// tries to convert by <see cref="TakeThicknessSide"/>
        /// </summary>
        /// <param name="value"></param>
        /// <param name="targetType"></param>
        /// <param name="parameter"></param>
        /// <param name="culture"></param>
        /// <returns></returns>
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            bool isGridTarget = targetType.Name.Contains(nameof(Grid));

            if (value is Thickness)
            {
                // yes, we can override it with the parameter value
                if (parameter is ThicknessSideType)
                {
                    this.TakeThicknessSide = (ThicknessSideType)parameter;
                }
                var orgThickness = (Thickness)value;
                switch (this.TakeThicknessSide)
                {
                case ThicknessSideType.Left:
                    if (isGridTarget)
                    {
                        return(new GridLength(orgThickness.Left, GridUnitType.Pixel));
                    }
                    else
                    {
                        return(orgThickness.Left);
                    }

                case ThicknessSideType.Top:
                    if (isGridTarget)
                    {
                        return(new GridLength(orgThickness.Top, GridUnitType.Pixel));
                    }
                    else
                    {
                        return(orgThickness.Top);
                    }

                case ThicknessSideType.Right:
                    if (isGridTarget)
                    {
                        return(new GridLength(orgThickness.Right, GridUnitType.Pixel));
                    }
                    else
                    {
                        return(orgThickness.Right);
                    }

                case ThicknessSideType.Bottom:
                    if (isGridTarget)
                    {
                        return(new GridLength(orgThickness.Bottom, GridUnitType.Pixel));
                    }
                    else
                    {
                        return(orgThickness.Bottom);
                    }

                default:
                    if (isGridTarget)
                    {
                        return(new GridLength(0, GridUnitType.Pixel));
                    }
                    else
                    {
                        return(0);
                    }
                }
            }

            if (isGridTarget)
            {
                return(new GridLength(0, GridUnitType.Pixel));
            }
            else
            {
                return(0);
            }
        }