Click here to Skip to main content
15,888,521 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Experts,

I want to set image to grid.I am working with C# n WPF.

I am using following code but not working.

ImageBrush myBrush = new ImageBrush();
  Image image = new Image();
  image.Source = new BitmapImage(new Uri("pack://application:,,,MyClassLibrary;component/Images/myImage.jpg"));
  myBrush.ImageSource = image.Source;
  Grid grid = new Grid();
  grid.Background = myBrush; 


Thanks
Posted
Updated 7-Nov-11 19:54pm
v2

ImageBrush myBrush = new ImageBrush();
myBrush.ImageSource = new BitmapImage
(new Uri(@"pack://application:,,,/Resources;component/Images/x.jpg"));            
grid.Background = myBrush; 


you create a new grid and put the image on it, But you cannot see that grid cuz he is noot a part of the UI objects
 
Share this answer
 
v2
It works.
Thanks Mohamed_Ahmed
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900