Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ImageBrush for Grid programmatically

Tags:

c#

wpf

So I try to apply an image but cannot see any changes...

What do I am missing? Thanks!!

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;
like image 312
Friend Avatar asked May 16 '12 19:05

Friend


1 Answers

Try this instead:

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

RootGrid.Background = ib;

Also, this is obvious, but make sure the image is actually at the right path and set to be Content in the Project.

like image 184
justin.m.chase Avatar answered Oct 22 '22 15:10

justin.m.chase