Ejemplo n.º 1
0
 public CustomSize()
 {
     InitializeComponent();
     ProductSize = new CustomSizeModel()
     {
         Height = 100,
         Width  = 148
     };
     customHeight.DataBindings.Add("EditValue", ProductSize, "Height");
     customWidth.DataBindings.Add("EditValue", ProductSize, "Width");
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Generates image width attributes as html by given image view model for object that is image.
        /// </summary>
        /// <param name="helper">The helper.</param>
        /// <param name="model">The image view model.</param>
        /// <returns>The generated image width attribute as html content.</returns>
        public static string GetWidthAttributeForImage(this HtmlHelper helper, ImageViewModel model)
        {
            CustomSizeModel customSize      = model.CustomSize;
            IDataItem       dataItem        = model.Item.DataItem;
            string          thumbnailName   = model.ThumbnailName;
            int?            thumbnailWidth  = model.ThumbnailWidth;
            int?            thumbnailHeight = model.ThumbnailHeight;

            var html  = string.Empty;
            var image = dataItem as Image;

            if (image != null)
            {
                double height         = image.Height;
                double width          = image.Width;
                double originalHeight = height;
                double originalWidth  = width;

                double widthToHeightRatio = originalWidth / originalHeight;

                if (customSize != null && thumbnailName == null)
                {
                    if (customSize.Width.HasValue && customSize.Method.Equals(CropCropArguments, StringComparison.InvariantCultureIgnoreCase))
                    {
                        width = customSize.Width.Value;
                    }
                    else if (customSize.MaxWidth.HasValue && customSize.Method.Equals(ResizeFitToAreaArguments, StringComparison.InvariantCultureIgnoreCase))
                    {
                        if (image.Height > customSize.MaxHeight.Value)
                        {
                            width = Math.Round(widthToHeightRatio * customSize.MaxHeight.Value);
                        }
                        else if (image.Width > customSize.MaxWidth.Value || image.IsVectorGraphics())
                        {
                            width = customSize.MaxWidth.Value;
                        }
                    }
                }
                else if (thumbnailName != null && thumbnailWidth.HasValue)
                {
                    width = thumbnailWidth.Value;
                }

                if (width > 0)
                {
                    html = string.Format(@"width={0}", width);
                }
            }

            return(html);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Generates image width attribute as html by given custom size model for object that is vector graphics.
        /// </summary>
        /// <param name="helper">The helper.</param>
        /// <param name="customSize">The custom size model.</param>
        /// <param name="dataItem">The data item represents an image object.</param>
        /// <returns>The generated image width attribute as html content.</returns>
        public static string GetWidthAttributeForVectorGraphics(this HtmlHelper helper, CustomSizeModel customSize, IDataItem dataItem)
        {
            var html = string.Empty;

            if (customSize != null)
            {
                var image = dataItem as Image;
                if (image != null && image.IsVectorGraphics())
                {
                    if (customSize.Width.HasValue && customSize.Method.Equals(CropCropArguments, StringComparison.InvariantCultureIgnoreCase))
                    {
                        html = string.Format(@"width={0}", customSize.Width.Value);
                    }
                    else if (customSize.MaxWidth.HasValue && customSize.Method.Equals(ResizeFitToAreaArguments, StringComparison.InvariantCultureIgnoreCase))
                    {
                        html = string.Format(@"width={0}", customSize.MaxWidth.Value);
                    }
                }
            }

            return(html);
        }