ImageBrush for grid programmatically

Therefore, I am trying to apply the image, but I do not see any changes ...

What am I missing? Thank!!

BitmapImage bi = new BitmapImage();
bi.BeginInit();
bi.UriSource = new Uri(@"pack://application:,,,/Images/bg1.jpg", UriKind.RelativeOrAbsolute);
bi.EndInit();
ImageBrush ib = new ImageBrush();
ib.TileMode = TileMode.Tile;
ib.ImageSource = bi;
ib.Stretch = Stretch.None;
RootGrid.Background = ib;
+5
source share
1 answer

Try this instead:

var ib = new ImageBrush {
  ImageSource =
    new BitmapImage(
      new Uri(@"Images\bg1.jpg", UriKind.Relative)
    )
};

RootGrid.Background = ib;

This is also obvious, but make sure that the image is actually on the right path and set as content in the project.

+9
source

All Articles