none
How to change grid background image in codebehind? RRS feed

  • Question

  • I used:


                StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///d:/Pictures/background1.png"));
                BitmapImage image = new BitmapImage();
                IRandomAccessStream ram = await file.OpenAsync(FileAccessMode.Read);
                await image.SetSourceAsync(ram);
                grid.Background = new ImageBrush() { ImageSource = image };

    and:

     ImageBrush brush = new ImageBrush();
              BitmapImage bitmapImage = new BitmapImage(new Uri("ms-appx:/d:/pictures/background2.jpg"));
               brush.ImageSource = bitmapImage;
               
                Grid.Background = brush;
                Source = new BitmapImage(new Uri("ms-appx:/d:/pictures/background2.jpg"));

    Both methods do not work. What's wrong?

    Tuesday, December 10, 2019 6:21 PM