Exemplo n.º 1
0
 protected override Size MeasureOverride(Size availableSize)
 {
     if (double.IsInfinity(availableSize.Width) || double.IsInfinity(availableSize.Height))
     {
         return(_screenSize);
     }
     else
     {
         return(_stretch.CalculateSize(availableSize, _screenSize));
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Measures the control.
        /// </summary>
        /// <param name="availableSize">The available size.</param>
        /// <returns>The desired size of the control.</returns>
        protected override Size MeasureOverride(Size availableSize)
        {
            var source = Source;
            var result = new Size();

            if (source != null)
            {
                result = Stretch.CalculateSize(availableSize, source.Size, StretchDirection);
            }

            return(result);
        }
Exemplo n.º 3
0
        /// <inheritdoc/>
        protected override Size ArrangeOverride(Size finalSize)
        {
            var source = Source;

            if (source != null)
            {
                var sourceSize = source.Size;
                var result     = Stretch.CalculateSize(finalSize, sourceSize);
                return(result);
            }
            else
            {
                return(new Size());
            }
        }
Exemplo n.º 4
0
        public override void Render(DrawingContext context)
        {
            Rect rect = new Rect(0, 0, this.Bounds.Width, this.Bounds.Height);

            context.FillRectangle(BackgroundBrush, rect);
            var bitmap = Bitmap;

            if (bitmap != null &&
                bitmap.Size.Width > 0 && bitmap.Size.Height > 0 &&
                rect.Width > 0 && rect.Height > 0)
            {
                var  bmpSize = bitmap.Size;
                Size size    = Stretch.CalculateSize(rect.Size, bmpSize);

                Rect drawRect = new Rect((rect.Width - size.Width) / 2,
                                         (rect.Height - size.Height) / 2,
                                         size.Width, size.Height);

                context.DrawImage(bitmap, 1, new Rect(0, 0, bmpSize.Width, bmpSize.Height), drawRect);
            }
            base.Render(context);
        }