Add and copy different images below eachother depending on value

45 views Asked by At

Im wondering how I can show multiple copies of 5 images below eachother depending on the number value.

The 5 images depends on the value: 50, 100, 200, 500 and 1000.

The number 4750 will make 4 x 1000, 1 x 500, 1 x 200, 0 x 100 and 1 x 50 = the total value.

That part is done with something like

Thousand = value / 1000;
value = value - Thousand * 1000;

FiveHundred = value / 500;
value = value - FiveHundred * 500;

TwoHundred = value / 200;
value = value - TwoHundred * 200;

OneHundred = value / 100;
value = value - OneHundred * 100;

Fifty = value / 50;
value = value - Fifty * 50;

My problem is showing the images from this.

I have made five images and want to copy them n number of times depending on the value. The image thousand is implemented like this (WPF XAML):

<BitmapImage x:Key="Thousand" UriSource="Thousand.jpg" />    

<Image x:Name="Thosand_Copy1" Source="{StaticResource Tusind}" />

But if I do this I have to copy the images many times if the value is 20000 etc. And I think the images will need to load even if you don't need to see them.

What would be a good way of doing this?

Thanks for looking at this.

PS: It should look something like this:

1

There are 1 answers

0
Alfredo Alvarez On BEST ANSWER

I would place on your code behind an observable collection of image location that you want displayed and use a listbox to show them. You can databind the image to each item in the collection

This site explains the concept fairly well

http://wpftutorial.net/ListBoxDataTemplate.html