Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 58056

Problem With Device.StartTimer

$
0
0

Hi Guys,

I am developing a cross platform app using xamarin.Forms and PCL. I want to change the Image of a image control for every 2 seconds,for that i Used Device.StartTimer To change the Image For Every 2 seconds.It worked fine in IPhone and Windows phone but facing problem in Android.
After Continuously navigating to that page having the image control,the app is closing in android.

Is any alternate way is there instead of using Device.StartTimer.

Here is my code snippet

private ImageSource _scrollImageImage;
public ImageSource ScrollImageImage
{
set
{
_scrollImageImage = value;
if (PropertyChanged != null)
{
PropertyChanged(this,
new PropertyChangedEventArgs("ScrollImageImage"));
}
}
get
{
return _scrollImageImage;
}
}

public ObservableCollection ImageSources { get; set; }

ImageSources = new ObservableCollection()
{
ImageSource.FromFile("HomePage1.jpg"),
ImageSource.FromFile("HomePage2.jpg"),
ImageSource.FromFile("HomePage3.jpg"),
ImageSource.FromFile("HomePage4.jpg")
};

Device.StartTimer(new TimeSpan(0, 0, 0, 2), () =>
{
var random = new Random();
var randomImage = random.Next(ImageSources.Count);
ScrollImageImage = ImageSources[randomImage];
return true;
});

Here Is Xaml Binding:


Viewing all articles
Browse latest Browse all 58056

Trending Articles