Click here to Skip to main content
15,887,585 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have in a Window in WPF 40 image, for each of this image i need to set an image source at runtime programatically ...

Can i do a For cicle ? How ?

For example i have :
Image1
Image2
Image3
Image4

For Set image with a cycle for how can i do ?

for(int i = 1;i < ???????;i++) {
Image???? .Source = new BitmapImage(new Uri("pack://application:,,,/{AssemblyName};component/Images/MyImage.png”);
}


The Question marks are indicative for explain what i don't know how to :D

Thanks in advancefor any kind of help.
Posted

Use FindName as shown here.

C#
for(int i = 1;i < 40;i++) {
StackPanel sp = dt.FindName("OuterPanel",cp) as StackPanel;
//cp is the ContentPresenter
Image img = sp.FindName("Image" + i) as Image;
img.Source = new BitmapImage(new Uri("pack://application:,,,/{AssemblyName};component/Images/MyImage.png");
}
 
Share this answer
 
v4
Can you do a pratical example , based on my example ? :D

Thanks .
 
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