Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Image inside stackpanel is not getting displayed

I am creating stackpanel inside the gridview cell dynamically and placing a image control inside stackpanel but on the window only blank space coming, not the image
here is what i am doing

StackPanel Stkpnl = new StackPanel();

Image BgImg = new Image();
BitmapImage Img = new BitmapImage(new Uri(
    "Images/cellbg.png", UriKind.Relative));
BgImg.Source = Img ;

Stkpnl.Children.Add(BgImg );
like image 780
user1544004 Avatar asked Nov 03 '22 18:11

user1544004


1 Answers

You need to use a Pack URI. See https://stackoverflow.com/a/1651397/486660

If you have a question as to what your Pack URI should look like, then temporarily add an Image control to your WPF page then goto the Source property and click the "..." button and navigate to your image. The property's text box will have the Pack URI in it.

like image 160
Jim Avatar answered Nov 09 '22 10:11

Jim