public static async void SetBackgroundSource(this Grid grid, AdaptiveBackgroundImage adaptiveBackgroundImage, AdaptiveRenderContext context)
        {
            // Try to resolve the image URI
            Uri finalUri = context.Config.ResolveFinalAbsoluteUri(adaptiveBackgroundImage?.Url);

            if (finalUri == null)
            {
                return;
            }

            BitmapImage bi = await context.ResolveImageSource(finalUri);

            if (bi != null)
            {
                // bi.Pixel{Width, Height}: dimensions of image
                // grid.Actual{Width, Height}: dimensions of grid containing background image
                switch (adaptiveBackgroundImage.Mode)
                {
                case AdaptiveBackgroundImageMode.Repeat:
                    grid.Background = new ImageBrush(bi)
                    {
                        TileMode      = TileMode.Tile,
                        Viewport      = new Rect(0, 0, bi.PixelWidth, bi.PixelHeight),
                        ViewportUnits = BrushMappingMode.Absolute
                    };
                    break;

                case AdaptiveBackgroundImageMode.RepeatHorizontally:
                    grid.Background = new ImageBrush(bi)
                    {
                        TileMode      = TileMode.FlipY,
                        Stretch       = Stretch.Uniform,
                        AlignmentY    = (AlignmentY)adaptiveBackgroundImage.VerticalAlignment,
                        Viewport      = new Rect(0, 0, bi.PixelWidth, grid.ActualHeight + 1),
                        ViewportUnits = BrushMappingMode.Absolute
                    };
                    break;

                case AdaptiveBackgroundImageMode.RepeatVertically:
                    grid.Background = new ImageBrush(bi)
                    {
                        TileMode      = TileMode.FlipX,
                        Stretch       = Stretch.Uniform,
                        AlignmentX    = (AlignmentX)adaptiveBackgroundImage.HorizontalAlignment,
                        Viewport      = new Rect(0, 0, grid.ActualWidth + 1, bi.PixelWidth),
                        ViewportUnits = BrushMappingMode.Absolute
                    };
                    break;

                case AdaptiveBackgroundImageMode.Stretch:
                default:
                    grid.Background = new ImageBrush(bi)
                    {
                        Stretch    = Stretch.UniformToFill,
                        AlignmentY = AlignmentY.Top
                    };
                    break;
                }
            }
        }
Exemplo n.º 2
0
 public static void SetSource(this Image image, Uri url, AdaptiveRenderContext context)
 {
     if (url == null)
     {
         return;
     }
     image.Source = context.ResolveImageSource(url);
 }
Exemplo n.º 3
0
 public static void SetBackgroundSource(this Grid grid, Uri url, AdaptiveRenderContext context)
 {
     if (url == null)
     {
         return;
     }
     grid.Background = new ImageBrush(context.ResolveImageSource(url))
     {
         Stretch    = Stretch.UniformToFill,
         AlignmentX = AlignmentX.Left,
         AlignmentY = AlignmentY.Top
     };
 }
Exemplo n.º 4
0
        public static async void SetSource(this Image image, Uri url, AdaptiveRenderContext context)
        {
            if (url == null)
            {
                return;
            }

            image.Source = await context.ResolveImageSource(url);

            var binding = new Binding
            {
                RelativeSource     = RelativeSource.Self,
                Path               = new PropertyPath("Parent.ActualWidth"),
                Mode               = BindingMode.OneWay,
                Converter          = new StretchConverter(),
                ConverterParameter = image
            };

            image.SetBinding(Image.StretchProperty, binding);
        }
Exemplo n.º 5
0
        public static async void SetBackgroundSource(this Grid grid, Uri uri, AdaptiveRenderContext context)
        {
            // Try to resolve the image URI
            Uri finalUri = context.Config.ResolveFinalAbsoluteUri(uri);

            if (finalUri == null)
            {
                return;
            }

            BitmapImage bi = await context.ResolveImageSource(finalUri);

            if (bi != null)
            {
                grid.Background = new ImageBrush(bi)
                {
                    Stretch    = Stretch.UniformToFill,
                    AlignmentX = AlignmentX.Left,
                    AlignmentY = AlignmentY.Top
                };
            }
        }
 /** Helper function to call async function from context */
 private static async void SetImageSource(this Image image, string urlString, AdaptiveRenderContext context)
 {
     image.Source = await context.ResolveImageSource(context.Config.ResolveFinalAbsoluteUri(urlString));
 }