I am developing an WP8
app and would like to change the background image
with several images ; setting time as a variable and showing images in C#,
Asked
Active
Viewed 72 times
1

Uthistran Selvaraj
- 1,371
- 1
- 12
- 31

gnyangolo
- 29
- 9
1 Answers
0
You can use DispatcherTimer class in order to change the images with respect to time.
Let me suggest you the easiest way. Name your images as numbers like 1.jpg,2.jpg,3.jpg etc and put them inside a folder.
Now you can use either random number class to pick the images in random order or can use the following method to get the sequentially:
DispatcherTimer picture_timer = new DispatcherTimer();
Random rnd = new Random();
picture_timer .Interval = new TimeSpan(0, 0, 3);
picture_timer .Tick += timer_Tick;
picture_timer .Start();
void timer_Tick(object sender, object e)
{
int num = rnd.Next(1, 13); // creates a number between 1 and 12
string image_source = "/Assets/"+num+".jpg";
}

Bilal Amjad
- 232
- 2
- 13
-
Where exactly do i add this code on the MainPage.xaml or on the app.xaml – gnyangolo Apr 27 '16 at 11:59
-
You can declare first two lines of code as global above InitializeComponent(); and then its upto you you can add these lines in onnavigated to method: picture_timer .Interval = new TimeSpan(0, 0, 3); picture_timer .Tick += timer_Tick; picture_timer .Start(); and timer_tick itself is a function. – Bilal Amjad Apr 27 '16 at 12:01
-
I am a little bit confused can; you create a project of such an example and share it with me. I will highly appreciate it . – gnyangolo Apr 27 '16 at 12:15
-
Mail your attempt to me at mail@bilalamjad.net. – Bilal Amjad Apr 27 '16 at 12:18