Based on the following blog post :-
http://blogs.msdn.com/b/ptorr/archive/2010/07/23/how-to-detect-when-a-list-is-scrolling-or-not.aspx
I came up with the following :-
bool alreadyHookedEvents = false;
List<string> _images = new List<string>();
int _index = 0;
void MainPage_Loaded(object sender, RoutedEventArgs e)
{
if (_images.Count == 0)
{
_images.Add(@"\Images\1.jpg");
_images.Add(@"\Images\2.jpg");
_images.Add(@"\Images\3.jpg");
_images.Add(@"\Images\4.jpg");
_images.Add(@"\Images\5.jpg");
_images.Add(@"\Images\6.jpg");
_images.Add(@"\Images\7.jpg");
_images.Add(@"\Images\8.jpg");
_images.Add(@"\Images\9.jpg");
_images.Add(@"\Images\10.jpg");
_images.Add(@"\Images\11.jpg");
_images.Add(@"\Images\12.jpg");
}
if (alreadyHookedEvents)
return;
alreadyHookedEvents = true;
// Visual States are always on the first child of the control template
FrameworkElement element = VisualTreeHelper.GetChild(this.MyHubTile, 0) as FrameworkElement;
if (element != null)
{
VisualStateGroup group = FindVisualState(element, "ImageStates");
if (group != null)
{
group.CurrentStateChanged += (s, args) =>
{
if (group.CurrentState.Name == "Flipped")
{
_index++;
this.MyHubTile.Source = new BitmapImage(new Uri(_images[_index], UriKind.Relative));
}
};
}
}
}
VisualStateGroup FindVisualState(FrameworkElement element, string name)
{
if (element == null)
return null;
IList groups = VisualStateManager.GetVisualStateGroups(element);
foreach (VisualStateGroup group in groups)
if (group.Name == name)
return group;
return null;
}
T FindSimpleVisualChild<T>(DependencyObject element) where T : class
{
while (element != null)
{
if (element is T)
return element as T;
element = VisualTreeHelper.GetChild(element, 0);
}
return null;
}